ia64/xen-unstable

changeset 19720:8f64f43624e8

xend: xen-api, pass-through: Add create_dpci_from_sxp()

Move some duplicated code into create_dpci_from_sxp()

Signed-off-by: Simon Horman <horms@verge.net.au>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:41:13 2009 +0100 (2009-06-04)
parents 728eb34bbfcc
children 2c172f9db417
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Jun 04 10:40:24 2009 +0100
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Jun 04 10:41:13 2009 +0100
     1.3 @@ -1221,7 +1221,29 @@ class XendConfig(dict):
     1.4                          raise XendConfigError('The mac "%s" is already defined' %
     1.5                                                dev_mac)
     1.6          return None
     1.7 -    
     1.8 +
     1.9 +    def create_dpci_from_sxp(self, pci_devs):
    1.10 +        for pci_dev in pci_devs:
    1.11 +            dpci_uuid = pci_dev.get('uuid')
    1.12 +            log.debug("create_dpci_from_sxp: %s" % pci_dev)
    1.13 +            ppci_uuid = XendPPCI.get_by_sbdf(pci_dev['domain'],
    1.14 +                                             pci_dev['bus'],
    1.15 +                                             pci_dev['slot'],
    1.16 +                                             pci_dev['func'])
    1.17 +            if ppci_uuid is None:
    1.18 +                continue
    1.19 +            dpci_record = {
    1.20 +                'VM': self['uuid'],
    1.21 +                'PPCI': ppci_uuid,
    1.22 +                'hotplug_slot': pci_dev.get('vslot', 0)
    1.23 +            }
    1.24 +
    1.25 +            dpci_opts = pci_dev.get('opts')
    1.26 +            if dpci_opts and len(dpci_opts) > 0:
    1.27 +                dpci_record['options'] = dpci_opts
    1.28 +
    1.29 +            XendDPCI(dpci_uuid, dpci_record)
    1.30 +
    1.31      def device_add(self, dev_type, cfg_sxp = None, cfg_xenapi = None,
    1.32                     target = None):
    1.33          """Add a device configuration in SXP format or XenAPI struct format.
    1.34 @@ -1276,25 +1298,7 @@ class XendConfig(dict):
    1.35                  pci_devs = pci_dict['devs']
    1.36  
    1.37                  # create XenAPI DPCI objects.
    1.38 -                for pci_dev in pci_devs:
    1.39 -                    dpci_uuid = pci_dev.get('uuid')
    1.40 -                    ppci_uuid = XendPPCI.get_by_sbdf(pci_dev['domain'],
    1.41 -                                                     pci_dev['bus'],
    1.42 -                                                     pci_dev['slot'],
    1.43 -                                                     pci_dev['func'])
    1.44 -                    if ppci_uuid is None:
    1.45 -                        continue
    1.46 -                    dpci_record = {
    1.47 -                        'VM': self['uuid'],
    1.48 -                        'PPCI': ppci_uuid,
    1.49 -                        'hotplug_slot': pci_dev.get('vslot', 0)
    1.50 -                    }
    1.51 -
    1.52 -                    dpci_opts = pci_dev.get('opts')
    1.53 -                    if dpci_opts and len(dpci_opts) > 0:
    1.54 -                        dpci_record['options'] = dpci_opts
    1.55 -
    1.56 -                    XendDPCI(dpci_uuid, dpci_record)
    1.57 +                self.create_dpci_from_sxp(pci_devs)
    1.58  
    1.59                  target['devices'][pci_devs_uuid] = (dev_type,
    1.60                                                      {'devs': pci_devs,
    1.61 @@ -1846,25 +1850,7 @@ class XendConfig(dict):
    1.62                      XendAPIStore.deregister(dpci_uuid, "DPCI")
    1.63  
    1.64                  # create XenAPI DPCI objects.
    1.65 -                for pci_dev in pci_devs:
    1.66 -                    dpci_uuid = pci_dev.get('uuid')
    1.67 -                    ppci_uuid = XendPPCI.get_by_sbdf(pci_dev['domain'],
    1.68 -                                                     pci_dev['bus'],
    1.69 -                                                     pci_dev['slot'],
    1.70 -                                                     pci_dev['func'])
    1.71 -                    if ppci_uuid is None:
    1.72 -                        continue
    1.73 -                    dpci_record = {
    1.74 -                        'VM': self['uuid'],
    1.75 -                        'PPCI': ppci_uuid,
    1.76 -                        'hotplug_slot': pci_dev.get('vslot', 0)
    1.77 -                    }
    1.78 -
    1.79 -                    dpci_opts = pci_dev.get('opts')
    1.80 -                    if dpci_opts and len(dpci_opts) > 0:
    1.81 -                        dpci_record['options'] = dpci_opts
    1.82 -
    1.83 -                    XendDPCI(dpci_uuid, dpci_record)
    1.84 +                self.create_dpci_from_sxp(pci_devs)
    1.85  
    1.86                  self['devices'][dev_uuid] = (dev_type,
    1.87                                               {'devs': pci_devs,