ia64/xen-unstable

changeset 14650:2ac29d446366

Finish off network in xm via XenAPI

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Thu Mar 29 16:29:31 2007 +0100 (2007-03-29)
parents 2e05921d4f78
children 2317e0cdd07d
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	Thu Mar 29 15:59:53 2007 +0100
     1.2 +++ b/tools/python/xen/xm/create.dtd	Thu Mar 29 16:29:31 2007 +0100
     1.3 @@ -74,7 +74,6 @@
     1.4                   mtu             CDATA       #REQUIRED
     1.5                   device          CDATA       #REQUIRED
     1.6                   qos_algorithm_type CDATA    #REQUIRED
     1.7 -                 bridge          CDATA       #IMPLIED
     1.8                   network         CDATA       #IMPLIED> 
     1.9  
    1.10  <!ELEMENT pv     EMPTY>
     2.1 --- a/tools/python/xen/xm/xenapi_create.py	Thu Mar 29 15:59:53 2007 +0100
     2.2 +++ b/tools/python/xen/xm/xenapi_create.py	Thu Mar 29 16:29:31 2007 +0100
     2.3 @@ -25,7 +25,7 @@ from xml.parsers.xmlproc import xmlproc,
     2.4  from xen.xend import sxp
     2.5  from xen.xend.XendAPIConstants import XEN_API_ON_NORMAL_EXIT, \
     2.6       XEN_API_ON_CRASH_BEHAVIOUR
     2.7 -
     2.8 +from xen.xm.opts import OptionError
     2.9  
    2.10  import sys
    2.11  import os
    2.12 @@ -184,15 +184,7 @@ class xenapi_create:
    2.13          map(self.check_vif, vifs)
    2.14  
    2.15      def check_vif(self, vif):
    2.16 -        """
    2.17 -        Check that the vif has
    2.18 -        either a bridge or network
    2.19 -        name but not both
    2.20 -        """
    2.21 -        if "bridge" in vif.attributes.keys() \
    2.22 -               and "network" in vif.attributes.keys():
    2.23 -            raise "You cannot specify both a bridge and\
    2.24 -                   a network name."
    2.25 +        pass
    2.26  
    2.27      # Cleanup methods here
    2.28      def cleanup_vdis(self, vdi_refs_dict):
    2.29 @@ -313,19 +305,23 @@ class xenapi_create:
    2.30              traceback.print_exc()
    2.31              sys.exit(-1)
    2.32  
    2.33 -        # Now create vbds
    2.34 +        try:
    2.35 +            # Now create vbds
    2.36  
    2.37 -        vbds = vm.getElementsByTagName("vbd")
    2.38 +            vbds = vm.getElementsByTagName("vbd")
    2.39  
    2.40 -        self.create_vbds(vm_ref, vbds, vdis)
    2.41 +            self.create_vbds(vm_ref, vbds, vdis)
    2.42 +
    2.43 +            # Now create vifs
    2.44  
    2.45 -        # Now create vifs
    2.46 +            vifs = vm.getElementsByTagName("vif")
    2.47  
    2.48 -        vifs = vm.getElementsByTagName("vif")
    2.49 +            self.create_vifs(vm_ref, vifs)
    2.50  
    2.51 -        self.create_vifs(vm_ref, vifs)
    2.52 -
    2.53 -        return vm_ref
    2.54 +            return vm_ref
    2.55 +        except:
    2.56 +            server.xenapi.VM.destroy(vm_ref)
    2.57 +            raise
    2.58          
    2.59      def create_vbds(self, vm_ref, vbds, vdis):
    2.60          log(DEBUG, "create_vbds")
    2.61 @@ -363,13 +359,16 @@ class xenapi_create:
    2.62      def create_vif(self, vm_ref, vif):
    2.63          log(DEBUG, "create_vif")
    2.64  
    2.65 -        if "bridge" in vif.attributes.keys():
    2.66 -            raise "Not allowed to add by bridge just yet"
    2.67 -        elif "network" in vif.attributes.keys():
    2.68 -            network = [network_ref
    2.69 +        if "network" in vif.attributes.keys():
    2.70 +            networks = [network_ref
    2.71                  for network_ref in server.xenapi.network.get_all()
    2.72                  if server.xenapi.network.get_name_label(network_ref)
    2.73 -                       == vif.attributes["network"].value][0]
    2.74 +                       == vif.attributes["network"].value]
    2.75 +            if len(networks) > 0:
    2.76 +                network = networks[0]
    2.77 +            else:
    2.78 +                raise OptionError("Network %s doesn't exist"
    2.79 +                                  % vif.attributes["network"].value)
    2.80          else:
    2.81              network = self._get_network_ref()
    2.82  
    2.83 @@ -631,7 +630,7 @@ class sxp2xml:
    2.84          vif.attributes["qos_algorithm_type"] = ""
    2.85  
    2.86          if get_child_by_name(vif_sxp, "bridge") is not None:
    2.87 -            vif.attributes["bridge"] \
    2.88 +            vif.attributes["network"] \
    2.89                  = get_child_by_name(vif_sxp, "bridge")
    2.90          
    2.91          return vif