[Kimchi-devel] [PATCH][Kimchi 1/5] Create method to change bootorder of a guest

Ramon Medeiros ramonn at linux.vnet.ibm.com
Mon Jun 6 21:13:33 UTC 2016


Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
 model/vms.py | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/model/vms.py b/model/vms.py
index b0b4eb2..854cd04 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -81,7 +81,7 @@ VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users']
 
 # update parameters which are updatable when the VM is offline
 VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory',
-                            'name', 'users']
+                            'name', 'users', 'boot']
 
 XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file"
 XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']"
@@ -736,6 +736,34 @@ class VMModel(object):
         else:
             remove_metadata_node(dom, 'name')
 
+    def _update_bootorder(self, xml, params):
+        # get element tree from xml
+        et = ET.fromstring(xml)
+
+        # get machine type
+        os = et.find("os")
+        mtype = os.find("type")
+
+        # create new element tree with new bootorder
+        new_os = E.os()
+        new_os.append(mtype)
+
+        # iterate over new bootorder and build tag
+        for device in params["order"]:
+
+            # skip devices not in list
+            if device not in ["hd", "cdrom", "network", "fd"]:
+                continue
+
+            # add bootdevice
+            new_os.append(E.boot(dev=device))
+
+        # update <os>
+        et.remove(os)
+        et.append(new_os)
+
+        return ET.tostring(et)
+
     def _static_vm_update(self, vm_name, dom, params):
         old_xml = new_xml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE)
         params = copy.deepcopy(params)
@@ -782,6 +810,10 @@ class VMModel(object):
         if ('memory' in params and params['memory'] != {}):
             new_xml = self._update_memory_config(new_xml, params, dom)
 
+        # update bootorder
+        if "boot" in params:
+            new_xml = self._update_bootorder(new_xml, params["boot"])
+
         snapshots_info = []
         conn = self.conn.get()
         try:
-- 
2.5.5




More information about the Kimchi-devel mailing list