[PATCH 7/8] lxc, qemu: Add support for virDomainGetDescription

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

 



This patch adds support for the newly added api for the LXC and qemu
drivers.
---
 src/lxc/lxc_driver.c   |   69 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_driver.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 138 insertions(+), 0 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index d26bfe9..1df7b45 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3870,6 +3870,74 @@ no_memory:
     goto cleanup;
 }

+static char *
+lxcDomainGetDescription(virDomainPtr dom, unsigned int flags)
+{
+    lxc_driver_t *driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    virDomainDefPtr persistentDef;
+    char *ret = NULL;
+    char *field;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG |
+                  VIR_DOMAIN_DESCRIPTION_TITLE, NULL);
+
+    bool title = (flags & VIR_DOMAIN_DESCRIPTION_TITLE) > 0;
+
+    lxcDriverLock(driver);
+    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+    lxcDriverUnlock(driver);
+
+    if (!vm) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+        virUUIDFormat(dom->uuid, uuidstr);
+        lxcError(VIR_ERR_NO_DOMAIN,
+                 _("no domain with matching uuid '%s'"), uuidstr);
+        goto cleanup;
+    }
+
+    if (flags & VIR_DOMAIN_AFFECT_LIVE &&
+        flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        lxcError(VIR_ERR_INVALID_ARG,
+                        _("Can't specify both LIVE and CONFIG flags"));
+        goto cleanup;
+    }
+
+    if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
+                                        &persistentDef) < 0)
+        goto cleanup;
+
+    if (title) {
+        if (flags & VIR_DOMAIN_AFFECT_LIVE)
+            field = vm->def->title;
+        else
+            field = persistentDef->title;
+    } else {
+        /* description */
+        if (flags & VIR_DOMAIN_AFFECT_LIVE)
+            field = vm->def->description;
+        else
+            field = persistentDef->description;
+    }
+
+    if (!field) {
+        lxcError(VIR_ERR_OPERATION_FAILED,
+                 _("No title or description found"));
+        goto cleanup;
+    }
+
+    if (!(ret = strdup(field))) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+cleanup:
+    if (vm)
+        virDomainObjUnlock(vm);
+    return ret;
+}
+
 static int
 lxcVMFilterRebuild(virConnectPtr conn ATTRIBUTE_UNUSED,
                    virHashIterator iter, void *data)
@@ -3961,6 +4029,7 @@ static virDriver lxcDriver = {
     .isAlive = lxcIsAlive, /* 0.9.8 */
     .nodeSuspendForDuration = nodeSuspendForDuration, /* 0.9.8 */
     .domainSetDescription = lxcDomainSetDescription, /* 0.9.10 */
+    .domainGetDescription = lxcDomainGetDescription, /* 0.9.10 */
 };

 static virStateDriver lxcStateDriver = {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 10dd98d..e4082df 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11926,6 +11926,74 @@ no_memory:
     goto cleanup;
 }

+static char *
+qemuDomainGetDescription(virDomainPtr dom, unsigned int flags)
+{
+    struct qemud_driver *driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    virDomainDefPtr persistentDef;
+    char *ret = NULL;
+    char *field=NULL;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG |
+                  VIR_DOMAIN_DESCRIPTION_TITLE, NULL);
+
+    bool title = (flags & VIR_DOMAIN_DESCRIPTION_TITLE) > 0;
+
+    qemuDriverLock(driver);
+    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+    qemuDriverUnlock(driver);
+
+    if (!vm) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+        virUUIDFormat(dom->uuid, uuidstr);
+        qemuReportError(VIR_ERR_NO_DOMAIN,
+                        _("no domain with matching uuid '%s'"), uuidstr);
+        goto cleanup;
+    }
+
+    if (flags & VIR_DOMAIN_AFFECT_LIVE &&
+        flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        qemuReportError(VIR_ERR_INVALID_ARG,
+                        _("Can't specify both LIVE and CONFIG flags"));
+        goto cleanup;
+    }
+
+    if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
+                                        &persistentDef) < 0)
+        goto cleanup;
+
+    if (title) {
+        if (flags & VIR_DOMAIN_AFFECT_LIVE)
+            field = vm->def->title;
+        else
+            field = persistentDef->title;
+    } else {
+        /* description */
+        if (flags & VIR_DOMAIN_AFFECT_LIVE)
+            field = vm->def->description;
+        else
+            field = persistentDef->description;
+    }
+
+    if (!field) {
+        qemuReportError(VIR_ERR_OPERATION_FAILED,
+                        _("No title or description found"));
+        goto cleanup;
+    }
+
+    if (!(ret = strdup(field))) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+cleanup:
+    if (vm)
+        virDomainObjUnlock(vm);
+    return ret;
+}
+
 static virDriver qemuDriver = {
     .no = VIR_DRV_QEMU,
     .name = "QEMU",
@@ -12079,6 +12147,7 @@ static virDriver qemuDriver = {
     .domainGetInterfaceParameters = qemuDomainGetInterfaceParameters, /* 0.9.9 */
     .domainSetInterfaceParameters = qemuDomainSetInterfaceParameters, /* 0.9.9 */
     .domainSetDescription = qemuDomainSetDescription, /* 0.9.10 */
+    .domainGetDescription = qemuDomainGetDescription, /* 0.9.10 */
 };


-- 
1.7.3.4

--
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]