File fix-restart-paravirt-xen.dif of Package cobbler

Index: cobbler-2.8.2/koan/app.py
===================================================================
--- cobbler-2.8.2.orig/koan/app.py
+++ cobbler-2.8.2/koan/app.py
@@ -62,6 +62,10 @@ import socket
 import utils
 import time
 import configurator
+try:
+    import xml.etree.ElementTree as etree
+except ImportError:
+    etree = None
 
 COBBLER_REQUIRED = 1.300
 
@@ -1596,7 +1600,9 @@ class Koan:
                    return "failed"
                elif state == "shutdown":
                    print "- shutdown VM detected, is the install done?  Restarting!"
-                   utils.find_vm(conn, virtname).create()    
+                   dom = utils.find_vm(conn, virtname)
+                   self.fix_restart_config(conn, dom)
+                   dom.create()
                    return results
                else:
                    raise InfoException("internal error, bad virt state")
@@ -1616,6 +1622,48 @@ class Koan:
 
     #---------------------------------------------------
 
+    def fix_restart_config(self, conn, dom):
+        if self.virt_type not in [ "xenpv", "xenfv" ]:
+            return
+        if not etree:
+            return
+        # we need to fix XEN only
+        xml = dom.XMLDesc(0)
+        root = etree.fromstring(xml)
+        on = root.findall('on_poweroff')
+        if on and len(on) == 1:
+            #print "set on_oweroff to destroy"
+            on[0].text = "destroy"
+        on = root.findall('on_reboot')
+        if on and len(on) == 1:
+            #print "set on_reboot to restart"
+            on[0].text = "restart"
+        on = root.findall('on_crash')
+        if on and len(on) == 1:
+            #print "set on_crash to restart"
+            on[0].text = "restart"
+
+        if self.virt_type == "xenpv":
+            bootloader = root.findall('bootloader')
+            if bootloader and len(bootloader) == 1:
+                #print "set bootloader to pygrub"
+                bootloader[0].text = '/usr/bin/pygrub'
+            ose = root.findall('os')
+            if ose and len(ose) == 1:
+                #print "remove os"
+                root.remove(ose[0])
+        elif self.virt_type == "xenfv":
+            oses = root.findall("./os")
+            for os in oses:
+                for item in os:
+                    if item.tag == 'boot' and item.get('dev', '') == 'network':
+                        #print "remove network boot"
+                        os.remove(item)
+
+        conn.defineXML(etree.tostring(root))
+
+    #---------------------------------------------------
+
     def load_virt_modules(self):
         try:
             import xencreate
openSUSE Build Service is sponsored by