[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1217507475 -3600
# Node ID 6fabbba27009d1fab2fe6c061e27d1f2cf3d0bac
# Parent  e446b7c3db5fca2bc1aba3da5deaaefc19d8702f
xm on xenapi: Enable 'xm pci-{att,det}ach' commands to be executed via xen-api.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@xxxxxxxxxxxxx>
---
 tools/python/xen/xm/main.py |   53 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 51 insertions(+), 2 deletions(-)

diff -r e446b7c3db5f -r 6fabbba27009 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Thu Jul 31 13:30:59 2008 +0100
+++ b/tools/python/xen/xm/main.py       Thu Jul 31 13:31:15 2008 +0100
@@ -2418,7 +2418,34 @@ def xm_pci_attach(args):
 def xm_pci_attach(args):
     arg_check(args, 'pci-attach', 2, 3)
     (dom, pci) = parse_pci_configuration(args, 'Initialising')
-    server.xend.domain.device_configure(dom, pci)
+
+    if serverType == SERVER_XEN_API:
+
+        pci_dev = sxp.children(pci, 'dev')[0]
+        domain = int(sxp.child_value(pci_dev, 'domain'), 16)
+        bus = int(sxp.child_value(pci_dev, 'bus'), 16)
+        slot = int(sxp.child_value(pci_dev, 'slot'), 16)
+        func = int(sxp.child_value(pci_dev, 'func'), 16)
+        vslt = int(sxp.child_value(pci_dev, 'vslt'), 16)
+        name = "%04x:%02x:%02x.%01x" % (domain, bus, slot, func)
+
+        target_ref = None
+        for ppci_ref in server.xenapi.PPCI.get_all():
+            if name == server.xenapi.PPCI.get_name(ppci_ref):
+                target_ref = ppci_ref
+                break
+        if target_ref is None:
+            raise OptionError("Device %s not found" % name)
+
+        dpci_record = {
+            "VM":           get_single_vm(dom),
+            "PPCI":         target_ref,
+            "hotplug_slot": vslt
+        }
+        server.xenapi.DPCI.create(dpci_record)
+
+    else:
+        server.xend.domain.device_configure(dom, pci)
 
 def xm_scsi_attach(args):
     xenapi_unsupported()
@@ -2518,7 +2545,29 @@ def xm_pci_detach(args):
 def xm_pci_detach(args):
     arg_check(args, 'pci-detach', 2)
     (dom, pci) = parse_pci_configuration(args, 'Closing')
-    server.xend.domain.device_configure(dom, pci)
+
+    if serverType == SERVER_XEN_API:
+
+        pci_dev = sxp.children(pci, 'dev')[0]
+        domain = int(sxp.child_value(pci_dev, 'domain'), 16)
+        bus = int(sxp.child_value(pci_dev, 'bus'), 16)
+        slot = int(sxp.child_value(pci_dev, 'slot'), 16)
+        func = int(sxp.child_value(pci_dev, 'func'), 16)
+        vslt = int(sxp.child_value(pci_dev, 'vslt'), 16)
+        name = "%04x:%02x:%02x.%01x" % (domain, bus, slot, func)
+
+        target_ref = None
+        for dpci_ref in server.xenapi.VM.get_DPCIs(get_single_vm(dom)):
+            ppci_ref = server.xenapi.DPCI.get_PPCI(dpci_ref)
+            if name == server.xenapi.PPCI.get_name(ppci_ref):
+                target_ref = ppci_ref
+                server.xenapi.DPCI.destroy(dpci_ref)
+                break
+        if target_ref is None:
+            raise OptionError("Device %s not assigned" % name)
+
+    else:
+        server.xend.domain.device_configure(dom, pci)
 
 def xm_scsi_detach(args):
     xenapi_unsupported()

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.