Add pvsDomainDefineXML functions, it works only for existing
domains for the present.

It's too hard to convert libvirt's XML domain configuration into
PVS'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 <dgurya...@parallels.com>
---
 src/pvs/pvs_driver.c |   89 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/src/pvs/pvs_driver.c b/src/pvs/pvs_driver.c
index 839cf06..9052740 100644
--- a/src/pvs/pvs_driver.c
+++ b/src/pvs/pvs_driver.c
@@ -1069,6 +1069,94 @@ pvsShutdownDomain(virDomainPtr domain)
                                 VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
 }
 
+static int
+pvsSetDescription(virDomainObjPtr dom, const char *description)
+{
+    pvsDomObjPtr pvsdom;
+
+    pvsdom = dom->privateData;
+    if (pvsCmdRun(PRLCTL, "set", pvsdom->uuid,
+                  "--description", description, NULL))
+        return -1;
+
+    return 0;
+}
+
+static int
+pvsApplyChanges(virDomainObjPtr dom, virDomainDefPtr newdef)
+{
+    virDomainDefPtr olddef = dom->def;
+
+    if (newdef->description && !STREQ(olddef->description, 
newdef->description)) {
+        if (pvsSetDescription(dom, newdef->description))
+            return -1;
+    }
+
+    /* TODO: compare all other parameters */
+
+    return 0;
+}
+
+static virDomainPtr
+pvsDomainDefineXML(virConnectPtr conn, const char *xml)
+{
+    pvsConnPtr privconn = conn->privateData;
+    virDomainPtr ret = NULL;
+    virDomainDefPtr def;
+    virDomainObjPtr dom = NULL, olddom = NULL;
+    virDomainEventPtr event = NULL;
+    int dupVM;
+
+    pvsDriverLock(privconn);
+    if ((def = virDomainDefParseString(privconn->caps, xml,
+                                       1 << VIR_DOMAIN_VIRT_PVS,
+                                       VIR_DOMAIN_XML_INACTIVE)) == NULL) {
+        pvsError(VIR_ERR_INVALID_ARG, _("Can't parse XML desc"));
+        goto cleanup;
+    }
+
+    if ((dupVM = virDomainObjIsDuplicate(&privconn->domains, def, 0)) < 0) {
+        pvsError(VIR_ERR_INVALID_ARG, _("Already exists"));
+        goto cleanup;
+    }
+
+    if (dupVM == 1) {
+        olddom = virDomainFindByUUID(&privconn->domains, def->uuid);
+        pvsApplyChanges(olddom, def);
+        virDomainObjUnlock(olddom);
+
+        if (!(dom = virDomainAssignDef(privconn->caps,
+                                       &privconn->domains, def, false))) {
+            pvsError(VIR_ERR_INTERNAL_ERROR, _("Can't allocate domobj"));
+            goto cleanup;
+        }
+
+        def = NULL;
+    } else {
+        pvsError(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)
+        pvsDomainEventQueue(privconn, event);
+    pvsDriverUnlock(privconn);
+    return ret;
+}
+
 static virDriver pvsDriver = {
     .no = VIR_DRV_PVS,
     .name = "PVS",
@@ -1096,6 +1184,7 @@ static virDriver pvsDriver = {
     .domainDestroy = pvsDestroyDomain,  /* 0.9.12 */
     .domainShutdown = pvsShutdownDomain, /* 0.9.12 */
     .domainCreate = pvsDomainCreate,    /* 0.9.12 */
+    .domainDefineXML = pvsDomainDefineXML,      /* 0.9.12 */
 };
 
 /**
-- 
1.7.1

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

Reply via email to