[PATCH v7 6/8] parallels: implement virDomainDefineXML operation for existing domains

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

 



Add parallelsDomainDefineXML function, it works only for existing
domains for the present.

It's too hard to convert libvirt's XML domain configuration into
parallels's one, so I've decided to compare virDomainDef structures:
current domain definition and the one created from XML, given to
the function. And change only different parameters.

Only description change implemetented, changing other parameters
will be implemented later.

Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx>
---
 src/parallels/parallels_driver.c |   89 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 46cb85c..1e6027c 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1089,6 +1089,94 @@ parallelsShutdownDomain(virDomainPtr domain)
                                 VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
 }
 
+static int
+parallelsSetDescription(virDomainObjPtr dom, const char *description)
+{
+    parallelsDomObjPtr parallelsdom;
+
+    parallelsdom = dom->privateData;
+    if (parallelsCmdRun(PRLCTL, "set", parallelsdom->uuid,
+                  "--description", description, NULL))
+        return -1;
+
+    return 0;
+}
+
+static int
+parallelsApplyChanges(virDomainObjPtr dom, virDomainDefPtr newdef)
+{
+    virDomainDefPtr olddef = dom->def;
+
+    if (newdef->description && !STREQ(olddef->description, newdef->description)) {
+        if (parallelsSetDescription(dom, newdef->description))
+            return -1;
+    }
+
+    /* TODO: compare all other parameters */
+
+    return 0;
+}
+
+static virDomainPtr
+parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
+{
+    parallelsConnPtr privconn = conn->privateData;
+    virDomainPtr ret = NULL;
+    virDomainDefPtr def;
+    virDomainObjPtr dom = NULL, olddom = NULL;
+    virDomainEventPtr event = NULL;
+    int dupVM;
+
+    parallelsDriverLock(privconn);
+    if ((def = virDomainDefParseString(privconn->caps, xml,
+                                       1 << VIR_DOMAIN_VIRT_PARALLELS,
+                                       VIR_DOMAIN_XML_INACTIVE)) == NULL) {
+        parallelsError(VIR_ERR_INVALID_ARG, _("Can't parse XML desc"));
+        goto cleanup;
+    }
+
+    if ((dupVM = virDomainObjIsDuplicate(&privconn->domains, def, 0)) < 0) {
+        parallelsError(VIR_ERR_INVALID_ARG, _("Already exists"));
+        goto cleanup;
+    }
+
+    if (dupVM == 1) {
+        olddom = virDomainFindByUUID(&privconn->domains, def->uuid);
+        parallelsApplyChanges(olddom, def);
+        virDomainObjUnlock(olddom);
+
+        if (!(dom = virDomainAssignDef(privconn->caps,
+                                       &privconn->domains, def, false))) {
+            parallelsError(VIR_ERR_INTERNAL_ERROR, _("Can't allocate domobj"));
+            goto cleanup;
+        }
+
+        def = NULL;
+    } else {
+        parallelsError(VIR_ERR_NO_SUPPORT, _("Not implemented yet"));
+            goto cleanup;
+    }
+
+    event = virDomainEventNewFromObj(dom,
+                                     VIR_DOMAIN_EVENT_DEFINED,
+                                     !dupVM ?
+                                     VIR_DOMAIN_EVENT_DEFINED_ADDED :
+                                     VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+
+    ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
+    if (ret)
+        ret->id = dom->def->id;
+
+  cleanup:
+    virDomainDefFree(def);
+    if (dom)
+        virDomainObjUnlock(dom);
+    if (event)
+        parallelsDomainEventQueue(privconn, event);
+    parallelsDriverUnlock(privconn);
+    return ret;
+}
+
 static virDriver parallelsDriver = {
     .no = VIR_DRV_PARALLELS,
     .name = "PARALLELS",
@@ -1116,6 +1204,7 @@ static virDriver parallelsDriver = {
     .domainDestroy = parallelsDestroyDomain,  /* 0.9.12 */
     .domainShutdown = parallelsShutdownDomain, /* 0.9.12 */
     .domainCreate = parallelsDomainCreate,    /* 0.9.12 */
+    .domainDefineXML = parallelsDomainDefineXML,      /* 0.9.12 */
 };
 
 /**
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]