ia64/xen-unstable

changeset 14674:a02b39eaba58

Add support for HVM domains to new xm XenAPI create code

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Fri Mar 30 17:28:54 2007 +0100 (2007-03-30)
parents d3b1341d83db
children 5138c48c7138
files tools/python/xen/xm/create.dtd tools/python/xen/xm/xenapi_create.py
line diff
     1.1 --- a/tools/python/xen/xm/create.dtd	Fri Mar 30 17:13:50 2007 +0100
     1.2 +++ b/tools/python/xen/xm/create.dtd	Fri Mar 30 17:28:54 2007 +0100
     1.3 @@ -37,6 +37,8 @@
     1.4                   memory,
     1.5                   vbd*,
     1.6                   vif*,
     1.7 +                 console*,
     1.8 +                 platform*,
     1.9                   vcpu_param*,
    1.10                   other_config*)> 
    1.11  <!ATTLIST vm     is_a_template          CDATA #REQUIRED
    1.12 @@ -46,11 +48,6 @@
    1.13                   actions_after_shutdown %NORMAL_EXIT; #REQUIRED 
    1.14                   actions_after_reboot   %NORMAL_EXIT; #REQUIRED
    1.15                   actions_after_crash    %CRASH_BEHAVIOUR; #REQUIRED
    1.16 -                 platform_std_VGA       CDATA #REQUIRED
    1.17 -                 platform_serial        CDATA #REQUIRED
    1.18 -                 platform_localtime     CDATA #REQUIRED 
    1.19 -                 platform_clock_offet   CDATA #REQUIRED
    1.20 -                 platform_enable_audio  CDATA #REQUIRED
    1.21                   PCI_bus                CDATA #REQUIRED> 
    1.22  
    1.23  <!ELEMENT memory EMPTY> 
    1.24 @@ -76,6 +73,9 @@
    1.25                   qos_algorithm_type CDATA    #REQUIRED
    1.26                   network         CDATA       #IMPLIED> 
    1.27  
    1.28 +<!ELEMENT console (other_config*)>
    1.29 +<!ATTLIST console protocol       (vt100|rfb|rdp) #REQUIRED>
    1.30 +
    1.31  <!ELEMENT pv     EMPTY>
    1.32  <!ATTLIST pv     kernel          CDATA #REQUIRED
    1.33                   bootloader      CDATA #REQUIRED
    1.34 @@ -104,6 +104,10 @@
    1.35  <!ELEMENT label  (#PCDATA)> 
    1.36  <!ELEMENT description (#PCDATA)>
    1.37  
    1.38 +<!ELEMENT platform   EMPTY>
    1.39 +<!ATTLIST platform   key   CDATA #REQUIRED
    1.40 +                     value CDATA #REQUIRED>
    1.41 +
    1.42  <!ELEMENT vcpu_param EMPTY>
    1.43  <!ATTLIST vcpu_param key   CDATA #REQUIRED
    1.44                       value CDATA #REQUIRED>
     2.1 --- a/tools/python/xen/xm/xenapi_create.py	Fri Mar 30 17:13:50 2007 +0100
     2.2 +++ b/tools/python/xen/xm/xenapi_create.py	Fri Mar 30 17:28:54 2007 +0100
     2.3 @@ -262,18 +262,8 @@ class xenapi_create:
     2.4                  vm.attributes["actions_after_reboot"].value,
     2.5              "actions_after_crash":
     2.6                  vm.attributes["actions_after_crash"].value,
     2.7 -            "platform_std_VGA":
     2.8 -                vm.attributes["platform_std_VGA"].value,
     2.9 -            "platform_serial":
    2.10 -                vm.attributes["platform_serial"].value,
    2.11 -            "platform_localtime":
    2.12 -                vm.attributes["platform_localtime"].value,
    2.13 -            "platform_clock_offet":
    2.14 -                vm.attributes["platform_clock_offet"].value,
    2.15 -            "platform_enable_audio":
    2.16 -                vm.attributes["platform_enable_audio"].value,
    2.17 -            "PCI_bus":
    2.18 -                vm.attributes["platform_enable_audio"].value,
    2.19 +            "platform":
    2.20 +                get_child_nodes_as_dict(vm, "platform", "key", "value"),
    2.21              "other_config":
    2.22                  get_child_nodes_as_dict(vm, "other_config", "key", "value")
    2.23              }
    2.24 @@ -297,7 +287,7 @@ class xenapi_create:
    2.25                  "HVM_boot_policy":
    2.26                      get_child_node_attribute(vm, "hvm", "boot_policy"),
    2.27                  "HVM_boot_params":
    2.28 -                    get_child_nodes_as_dict(hvm, "boot_params", "key", "value")
    2.29 +                    get_child_nodes_as_dict(hvm, "boot_param", "key", "value")
    2.30                  })
    2.31          try:
    2.32              vm_ref = server.xenapi.VM.create(vm_record)
    2.33 @@ -318,6 +308,12 @@ class xenapi_create:
    2.34  
    2.35              self.create_vifs(vm_ref, vifs)
    2.36  
    2.37 +            # Now create consoles
    2.38 +
    2.39 +            consoles = vm.getElementsByTagName("console")
    2.40 +
    2.41 +            self.create_consoles(vm_ref, consoles)
    2.42 +
    2.43              return vm_ref
    2.44          except:
    2.45              server.xenapi.VM.destroy(vm_ref)
    2.46 @@ -401,6 +397,26 @@ class xenapi_create:
    2.47              self._network_refs = server.xenapi.network.get_all()
    2.48              return self._network_refs.pop(0)
    2.49  
    2.50 +    def create_consoles(self, vm_ref, consoles):
    2.51 +        log(DEBUG, "create_consoles")
    2.52 +        return map(lambda console: self.create_console(vm_ref, console),
    2.53 +                   consoles)
    2.54 +
    2.55 +    def create_console(self, vm_ref, console):
    2.56 +        log(DEBUG, "create_consoles")
    2.57 +
    2.58 +        console_record = {
    2.59 +            "VM":
    2.60 +                vm_ref,
    2.61 +            "protocol":
    2.62 +                console.attributes["protocol"].value,
    2.63 +            "other_params":
    2.64 +                get_child_nodes_as_dict(console,
    2.65 +                  "other_param", "key", "value")
    2.66 +            }
    2.67 +
    2.68 +        return server.xenapi.console.create(console_record)
    2.69 +
    2.70  def get_child_by_name(exp, childname, default = None):
    2.71      try:
    2.72          return [child for child in sxp.children(exp)
    2.73 @@ -464,11 +480,6 @@ class sxp2xml:
    2.74              = actions_after_reboot
    2.75          vm.attributes["actions_after_crash"] \
    2.76              = actions_after_crash
    2.77 -        vm.attributes["platform_std_VGA"] = "false"
    2.78 -        vm.attributes["platform_serial"] = ""
    2.79 -        vm.attributes["platform_localtime"] = ""
    2.80 -        vm.attributes["platform_clock_offet"] = ""
    2.81 -        vm.attributes["platform_enable_audio"] = ""
    2.82          vm.attributes["PCI_bus"] = ""
    2.83  
    2.84          vm.attributes["vcpus_max"] \
    2.85 @@ -506,7 +517,13 @@ class sxp2xml:
    2.86              vm.appendChild(pv)
    2.87          elif image[0] == "hvm":
    2.88              hvm = document.createElement("hvm")
    2.89 -            hvm.attributes["boot_policy"] = ""
    2.90 +            hvm.attributes["boot_policy"] = "BIOS order"
    2.91 +
    2.92 +            boot_order = document.createElement("boot_param")
    2.93 +            boot_order.attributes["key"] = "order"
    2.94 +            boot_order.attributes["value"] \
    2.95 +                = get_child_by_name(image, "boot", "abcd")
    2.96 +            hvm.appendChild
    2.97  
    2.98              vm.appendChild(hvm)
    2.99  
   2.100 @@ -540,6 +557,18 @@ class sxp2xml:
   2.101  
   2.102          map(vm.appendChild, vifs)
   2.103  
   2.104 +        # Last but not least the consoles...
   2.105 +
   2.106 +        consoles = self.extract_consoles(image, document)
   2.107 +
   2.108 +        map(vm.appendChild, consoles)
   2.109 +
   2.110 +        # Platform variables...
   2.111 +
   2.112 +        platform = self.extract_platform(image, document)
   2.113 +
   2.114 +        map(vm.appendChild, platform)
   2.115 +
   2.116          # transient?
   2.117  
   2.118          if transient:
   2.119 @@ -637,6 +666,62 @@ class sxp2xml:
   2.120  
   2.121      _eths = -1
   2.122  
   2.123 +    def mk_other_config(self, key, value, document):
   2.124 +        other_config = document.createElement("other_config")
   2.125 +        other_config.attributes["key"] = key
   2.126 +        other_config.attributes["value"] = value
   2.127 +        return other_config
   2.128 +
   2.129 +    def extract_consoles(self, image, document):
   2.130 +        consoles = []
   2.131 +
   2.132 +        if int(get_child_by_name(image, "nographic", "1")) == 1:
   2.133 +            return consoles
   2.134 +        
   2.135 +        if int(get_child_by_name(image, "vnc", "0")) == 1:
   2.136 +            console = document.createElement("console")
   2.137 +            console.attributes["protocol"] = "rfb"
   2.138 +            console.appendChild(self.mk_other_config(
   2.139 +                "vncunused", str(get_child_by_name(image, "vncunused", "0")),
   2.140 +                document))
   2.141 +            console.appendChild(self.mk_other_config(
   2.142 +                "vnclisten",
   2.143 +                get_child_by_name(image, "vnclisten", "127.0.0.1"),
   2.144 +                document))
   2.145 +            console.appendChild(self.mk_other_config(
   2.146 +                "vncpasswd", get_child_by_name(image, "vncpasswd", ""),
   2.147 +                document))
   2.148 +            consoles.append(console)          
   2.149 +        if int(get_child_by_name(image, "sdl", "0")) == 1:
   2.150 +            console = document.createElement("console")
   2.151 +            console.attributes["protocol"] = "sdl"
   2.152 +            console.appendChild(self.mk_other_config(
   2.153 +                "display", get_child_by_name(image, "display", ""),
   2.154 +                document))
   2.155 +            console.appendChild(self.mk_other_config(
   2.156 +                "xauthority",
   2.157 +                get_child_by_name(image, "vxauthority", "127.0.0.1"),
   2.158 +                document))
   2.159 +            console.appendChild(self.mk_other_config(
   2.160 +                "vncpasswd", get_child_by_name(image, "vncpasswd", ""),
   2.161 +                document))
   2.162 +            consoles.append(console)
   2.163 +            
   2.164 +        return consoles
   2.165 +
   2.166 +
   2.167 +    def extract_platform(self, image, document):
   2.168 +        platform_keys = ['acpi', 'apic', 'pae']
   2.169 +
   2.170 +        def extract_platform_key(key):
   2.171 +            platform = document.createElement("platform")
   2.172 +            platform.attributes["key"] = key
   2.173 +            platform.attributes["value"] \
   2.174 +                = str(get_child_by_name(image, key, "1"))
   2.175 +            return platform
   2.176 +        
   2.177 +        return map(extract_platform_key, platform_keys)
   2.178 +    
   2.179      def getFreshEthDevice(self):
   2.180          self._eths += 1
   2.181          return "eth%i" % self._eths