[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 8/8] parallels: implement VM creation



To create a new VM in Parallels Clud Server we should issue
"prlctl create" command, and give path to the directory,
where VM should be created. VM's storage will be in that
directory later. So in this first version find out location
of first VM's hard disk and create VM there.

Signed-off-by: Dmitry Guryanov <dguryanov parallels com>
---
 src/parallels/parallels_driver.c  |   81 ++++++++++++++++++++++++++++++++++++-
 src/parallels/parallels_storage.c |    5 +--
 src/parallels/parallels_utils.h   |    2 +
 3 files changed, 83 insertions(+), 5 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 80ff709..c12470b 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1511,6 +1511,77 @@ parallelsApplyChanges(virDomainObjPtr dom, virDomainDefPtr new)
     return 0;
 }
 
+static int
+parallelsCreateVm(virConnectPtr conn, virDomainDefPtr def)
+{
+    parallelsConnPtr privconn = conn->privateData;
+    int i;
+    virStorageVolDefPtr privvol = NULL;
+    virStoragePoolObjPtr pool = NULL;
+    virStorageVolPtr vol = NULL;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    for (i = 0; i < def->ndisks; i++) {
+        if (def->disks[i]->device != VIR_DOMAIN_DISK_DEVICE_DISK)
+            continue;
+
+        vol = parallelsStorageVolumeLookupByPathLocked(conn, def->disks[i]->src);
+        if (!vol) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Can't find volume with path '%s'"),
+                           def->disks[i]->src);
+            return -1;
+        }
+        break;
+    }
+
+    if (!vol) {
+        /* We determine path to VM directory from volume, so
+         * let's report error if no disk until better solution
+         * will be found */
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("Can't create VM without hard disks"));
+        return -1;
+    }
+
+    pool = virStoragePoolObjFindByName(&privconn->pools, vol->pool);
+    if (!pool) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("Can't find storage pool with name '%s'"),
+                       vol->pool);
+        goto error;
+    }
+
+    privvol = virStorageVolDefFindByPath(pool, def->disks[i]->src);
+    if (!privvol) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("Can't find storage volume definition for path '%s'"),
+                       def->disks[i]->src);
+        goto error2;
+    }
+
+    virUUIDFormat(def->uuid, uuidstr);
+
+    if (parallelsCmdRun(PRLCTL, "create", def->name, "--dst",
+                        pool->def->target.path, "--no-hdd",
+                        "--uuid", uuidstr, NULL) < 0)
+        goto error2;
+
+    if (parallelsCmdRun(PRLCTL, "set", def->name, "--vnc-mode", "auto", NULL) < 0)
+        goto error2;
+
+    virStoragePoolObjUnlock(pool);
+    virUnrefStorageVol(vol);
+
+    return 0;
+
+  error2:
+    virStoragePoolObjUnlock(pool);
+  error:
+    virUnrefStorageVol(vol);
+    return -1;
+}
+
 static virDomainPtr
 parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
 {
@@ -1550,8 +1621,16 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
 
         def = NULL;
     } else {
-        virReportError(VIR_ERR_NO_SUPPORT, _("Not implemented yet"));
+        if (parallelsCreateVm(conn, def))
             goto cleanup;
+        if (parallelsLoadDomains(privconn, def->name))
+            goto cleanup;
+        dom = virDomainFindByName(&privconn->domains, def->name);
+        if (!dom) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Domain is not defined after creation"));
+            goto cleanup;
+        }
     }
 
     event = virDomainEventNewFromObj(dom,
diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c
index a7fdaed..4b56588 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -44,9 +44,6 @@ static virStorageVolDefPtr
 parallelsStorageVolumeDefine(virStoragePoolObjPtr pool, const char *xmldesc,
                              const char *xmlfile, bool is_new);
 static virStorageVolPtr
-parallelsStorageVolumeLookupByPathLocked(virConnectPtr conn, const char *path);
-
-static virStorageVolPtr
 parallelsStorageVolumeLookupByPath(virConnectPtr conn, const char *path);
 
 static int
@@ -868,7 +865,7 @@ parallelsStorageVolumeLookupByKey(virConnectPtr conn, const char *key)
     return ret;
 }
 
-static virStorageVolPtr
+virStorageVolPtr
 parallelsStorageVolumeLookupByPathLocked(virConnectPtr conn, const char *path)
 {
     parallelsConnPtr privconn = conn->privateData;
diff --git a/src/parallels/parallels_utils.h b/src/parallels/parallels_utils.h
index f6948c4..93bfb8e 100644
--- a/src/parallels/parallels_utils.h
+++ b/src/parallels/parallels_utils.h
@@ -58,5 +58,7 @@ int parallelsCmdRun(const char *binary, ...)
 char * parallelsAddFileExt(const char *path, const char *ext);
 void parallelsDriverLock(parallelsConnPtr driver);
 void parallelsDriverUnlock(parallelsConnPtr driver);
+virStorageVolPtr parallelsStorageVolumeLookupByPathLocked(virConnectPtr conn,
+                                                          const char *path);
 
 #endif
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]