ia64/xen-unstable

changeset 18219:6fabbba27009

xm on xenapi: Enable 'xm pci-{att,det}ach' commands to be executed via xen-api.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jul 31 13:31:15 2008 +0100 (2008-07-31)
parents e446b7c3db5f
children d922ce861337
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Thu Jul 31 13:30:59 2008 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Thu Jul 31 13:31:15 2008 +0100
     1.3 @@ -2418,7 +2418,34 @@ def parse_pci_configuration(args, state)
     1.4  def xm_pci_attach(args):
     1.5      arg_check(args, 'pci-attach', 2, 3)
     1.6      (dom, pci) = parse_pci_configuration(args, 'Initialising')
     1.7 -    server.xend.domain.device_configure(dom, pci)
     1.8 +
     1.9 +    if serverType == SERVER_XEN_API:
    1.10 +
    1.11 +        pci_dev = sxp.children(pci, 'dev')[0]
    1.12 +        domain = int(sxp.child_value(pci_dev, 'domain'), 16)
    1.13 +        bus = int(sxp.child_value(pci_dev, 'bus'), 16)
    1.14 +        slot = int(sxp.child_value(pci_dev, 'slot'), 16)
    1.15 +        func = int(sxp.child_value(pci_dev, 'func'), 16)
    1.16 +        vslt = int(sxp.child_value(pci_dev, 'vslt'), 16)
    1.17 +        name = "%04x:%02x:%02x.%01x" % (domain, bus, slot, func)
    1.18 +
    1.19 +        target_ref = None
    1.20 +        for ppci_ref in server.xenapi.PPCI.get_all():
    1.21 +            if name == server.xenapi.PPCI.get_name(ppci_ref):
    1.22 +                target_ref = ppci_ref
    1.23 +                break
    1.24 +        if target_ref is None:
    1.25 +            raise OptionError("Device %s not found" % name)
    1.26 +
    1.27 +        dpci_record = {
    1.28 +            "VM":           get_single_vm(dom),
    1.29 +            "PPCI":         target_ref,
    1.30 +            "hotplug_slot": vslt
    1.31 +        }
    1.32 +        server.xenapi.DPCI.create(dpci_record)
    1.33 +
    1.34 +    else:
    1.35 +        server.xend.domain.device_configure(dom, pci)
    1.36  
    1.37  def xm_scsi_attach(args):
    1.38      xenapi_unsupported()
    1.39 @@ -2518,7 +2545,29 @@ def xm_network_detach(args):
    1.40  def xm_pci_detach(args):
    1.41      arg_check(args, 'pci-detach', 2)
    1.42      (dom, pci) = parse_pci_configuration(args, 'Closing')
    1.43 -    server.xend.domain.device_configure(dom, pci)
    1.44 +
    1.45 +    if serverType == SERVER_XEN_API:
    1.46 +
    1.47 +        pci_dev = sxp.children(pci, 'dev')[0]
    1.48 +        domain = int(sxp.child_value(pci_dev, 'domain'), 16)
    1.49 +        bus = int(sxp.child_value(pci_dev, 'bus'), 16)
    1.50 +        slot = int(sxp.child_value(pci_dev, 'slot'), 16)
    1.51 +        func = int(sxp.child_value(pci_dev, 'func'), 16)
    1.52 +        vslt = int(sxp.child_value(pci_dev, 'vslt'), 16)
    1.53 +        name = "%04x:%02x:%02x.%01x" % (domain, bus, slot, func)
    1.54 +
    1.55 +        target_ref = None
    1.56 +        for dpci_ref in server.xenapi.VM.get_DPCIs(get_single_vm(dom)):
    1.57 +            ppci_ref = server.xenapi.DPCI.get_PPCI(dpci_ref)
    1.58 +            if name == server.xenapi.PPCI.get_name(ppci_ref):
    1.59 +                target_ref = ppci_ref
    1.60 +                server.xenapi.DPCI.destroy(dpci_ref)
    1.61 +                break
    1.62 +        if target_ref is None:
    1.63 +            raise OptionError("Device %s not assigned" % name)
    1.64 +
    1.65 +    else:
    1.66 +        server.xend.domain.device_configure(dom, pci)
    1.67  
    1.68  def xm_scsi_detach(args):
    1.69      xenapi_unsupported()