[Libvirt-cim] [PATCH] Set default VM autostart value

Sharad Mishra snmishra at us.ibm.com
Fri Jul 23 00:00:55 UTC 2010


# HG changeset patch
# User Sharad Mishra <snmishra at us.ibm.com>
# Date 1279843221 25200
# Node ID d054bf0cab617f6ea47604d6bca11261961a1e73
# Parent  10160de3a1384c2c3dd9ac95d4aec3e3bece3050
Set default VM autostart value.

This patch fixes the issue of no default showing up for VMs that were created without autostart flag.

Signed-off-by: Sharad Mishra <snmishra at us.ibm.com>

diff -r 10160de3a138 -r d054bf0cab61 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h	Thu Jul 15 15:37:05 2010 -0700
+++ b/libxkutil/device_parsing.h	Thu Jul 22 17:00:21 2010 -0700
@@ -135,6 +135,7 @@
         char *name;
         char *typestr; /*xen, kvm, etc */
         char *uuid;
+        int autostart;
         char *bootloader;
         char *bootloader_args;
         char *clock;
diff -r 10160de3a138 -r d054bf0cab61 schema/ComputerSystem.mof
--- a/schema/ComputerSystem.mof	Thu Jul 15 15:37:05 2010 -0700
+++ b/schema/ComputerSystem.mof	Thu Jul 22 17:00:21 2010 -0700
@@ -11,7 +11,7 @@
    string UUID;
 
    [Description("Flag to set VM autostart.")]
-   boolean autoStart;
+   string autoStart;
 
 };
 
@@ -27,7 +27,7 @@
    string UUID;
 
    [Description("Flag to set VM autostart.")]
-   boolean autoStart;
+   string autoStart;
 
 };
 
@@ -43,7 +43,7 @@
    string UUID;
 
    [Description("Flag to set VM autostart.")]
-   boolean autoStart;
+   string autoStart;
 
 };
 
diff -r 10160de3a138 -r d054bf0cab61 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c	Thu Jul 15 15:37:05 2010 -0700
+++ b/src/Virt_ComputerSystem.c	Thu Jul 22 17:00:21 2010 -0700
@@ -65,6 +65,33 @@
         return 1;
 }
 
+/* Set the "autoStart" property of an instance from a domain */
+static int set_autostart_from_dom(virDomainPtr dom, 
+                                  CMPIInstance *instance, 
+                                  struct domain *dominfo)
+{
+        int autoFlag = 0;
+        char autovalue[16];
+
+        if((virDomainGetAutostart(dom, &autoFlag)) == -1) {
+                CU_DEBUG("Could not read autostart value from xml");
+        } else {
+                CU_DEBUG("Autostart for current domain is set to %d", 
+                         autoFlag);
+                dominfo->autostart = autoFlag;
+        }
+
+        if(autoFlag)
+                strcpy(autovalue, "enable");
+        else
+                strcpy(autovalue, "disable");
+
+        CMSetProperty(instance, "autoStart",
+                      (CMPIValue *)autovalue, CMPI_chars);
+
+        return 1;
+}
+
 /* Set the "UUID" property of an instance from a domain */
 static int set_uuid_from_dom(virDomainPtr dom, 
                              CMPIInstance *instance, 
@@ -499,6 +526,15 @@
                 goto out;
         }
 
+        if (!set_autostart_from_dom(dom, instance, domain)) {
+                virt_set_status(broker, &s,
+                                CMPI_RC_ERR_FAILED,
+                                virDomainGetConnect(dom),
+                                "Unable to get domain autostart flag");
+
+                goto out;
+        }
+
         if (!set_uuid_from_dom(dom, instance, &uuid)) {
                 virt_set_status(broker, &s,
                                 CMPI_RC_ERR_FAILED,
diff -r 10160de3a138 -r d054bf0cab61 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Thu Jul 15 15:37:05 2010 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Thu Jul 22 17:00:21 2010 -0700
@@ -1356,7 +1356,8 @@
         virDomainPtr dom;
         const char *name;
         CMPIInstance *inst = NULL;
-        bool autoStartFlag = false;
+        const char *autoStartFlag = NULL;
+        int autoflag;
 
         conn = connect_by_classname(_BROKER, CLASSNAME(ref), s);
         if (conn == NULL) {
@@ -1374,9 +1375,14 @@
                 goto out;
         }
 
-        if (cu_get_bool_prop(inst, "autoStart", &autoStartFlag) != CMPI_RC_OK)
-                autoStartFlag = false;
-        if(virDomainSetAutostart(dom, (autoStartFlag) ? 1 : 0) == -1)
+        if (cu_get_str_prop(inst, "autoStart", &autoStartFlag) != CMPI_RC_OK)
+                autoStartFlag = strdup("disable");
+        
+        if (STREQ(autoStartFlag, "enable"))
+                autoflag = 1;
+        else
+                autoflag = 0;	
+        if((virDomainSetAutostart(dom, autoflag)) == -1)
                 CU_DEBUG("Failed to set autostart flag.");
 
         name = virDomainGetName(dom);




More information about the Libvirt-cim mailing list