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

[Xen-devel] [PATCH][3/3] XenAPI: Example Scripts for PCI Assignment



These attachments are examples for pci assignment via xen-api.

ppci_get_record.py: demonstrates physical pci information acquisition.
dpci_create.py: adds a pci device to a domain.
dpci_destroy.py: removes a pci device from a domain.

Regards,
-----------------------
Yosuke Iwamatsu
        NEC Corporation
#!/usr/bin/python
"""Test program for Xen-API direct PCI device attachment"""

SERVER_URL='http://localhost:9363'
USER='me'
PASSWORD='mypassword'

VM_NAME='mydomain'
PCI_NAME='0000:0c:00.1'

import sys
sys.path.append("/usr/lib/python")

from xen.xm.XenAPI import Session

def main(argv = sys.argv):
    server = Session(SERVER_URL)
    server.login_with_password(USER, PASSWORD)

    # get VM
    vm_refs = server.xenapi.host.get_resident_VMs(
            server.xenapi.session.get_this_host(server.getSession()))
    for vm_ref in vm_refs:
        vm_record = server.xenapi.VM.get_record(vm_ref)
        if vm_record['name_label'] == VM_NAME:
            break

    # get PPCI
    ppci_refs = server.xenapi.host.get_PPCIs(
            server.xenapi.session.get_this_host(server.getSession()))
    for ppci_ref in ppci_refs:
        ppci_record = server.xenapi.PPCI.get_record(ppci_ref)
        if ppci_record['name'] == PCI_NAME:
            break

    # create DPCI
    dpci_record = {
        'VM': vm_ref,
        'PPCI': ppci_ref,
        'hotplug_slot': 0,
        }
    dpci_ref = server.xenapi.DPCI.create(dpci_record)

    server.logout()

if __name__ == "__main__":
    main()
#!/usr/bin/python
"""Test program for Xen-API direct PCI device detachment"""

SERVER_URL='http://localhost:9363'
USER='me'
PASSWORD='mypassword'

VM_NAME='mydomain'
PCI_NAME='0000:0c:00.1'

import sys
sys.path.append("/usr/lib/python")

from xen.xm.XenAPI import Session

def main(argv = sys.argv):
    server = Session(SERVER_URL)
    server.login_with_password(USER, PASSWORD)

    # get VM
    vm_refs = server.xenapi.host.get_resident_VMs(
            server.xenapi.session.get_this_host(server.getSession()))
    for vm_ref in vm_refs:
        vm_record = server.xenapi.VM.get_record(vm_ref)
        if vm_record['name_label'] == VM_NAME:
            break

    # get DPCI
    dpci_refs = server.xenapi.DPCI.get_all()
    for dpci_ref in dpci_refs:
        dpci_record = server.xenapi.DPCI.get_record(dpci_ref)
        ppci_record = server.xenapi.PPCI.get_record(dpci_record['PPCI'])
        if ppci_record['name'] == PCI_NAME:
            break

    # destroy
    server.xenapi.DPCI.destroy(dpci_ref)

    server.logout()

if __name__ == "__main__":
    main()
#!/usr/bin/python
"""Test program for Xen-API PPCI class"""

SERVER_URL='http://localhost:9363'
USER='me'
PASSWORD='mypassword'

import sys
sys.path.append("/usr/lib/python")

from xen.xm.XenAPI import Session

def main(argv = sys.argv):
    server = Session(SERVER_URL)
    server.login_with_password(USER, PASSWORD)

    print "=== PPCI INFORMATION ==="
    ppci_refs = server.xenapi.host.get_PPCIs(
            server.xenapi.session.get_this_host(server.getSession()))
    print "ppci_refs = %s" % ppci_refs
    for ppci_ref in ppci_refs:
        ppci_record = server.xenapi.PPCI.get_record(ppci_ref)
        print "ppci_record = %s" % ppci_record
    print

    server.logout()

if __name__ == "__main__":
    main()
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

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