xen toolstack - xen api

user space的接口为 xapi.py

xapi.py的成员API函数的流程都follow如下流程:

1. 调用connect, 通过ServerProxy rpc登陆到xend

2. 调用execute, 执行func(*args), 其中func, args都是传入的参数, *args表示变长参数


xapi.py支持的API commands如下

COMMANDS = {
    'host-info': ('', 'Get Xen Host Info'),
    'host-set-name': ('', 'Set host name'),
    'pif-list': ('', 'List all PIFs'),
    'sr-list':   ('', 'List all SRs'),
    'vbd-list':  ('', 'List all VBDs'),
    'vbd-create': ('<domname> <pycfg> [opts]',
                   'Create VBD attached to domname'),
    'vdi-create': ('<pycfg> [opts]', 'Create a VDI'),
    'vdi-list'  : ('', 'List all VDI'),
    'vdi-rename': ('<vdi_uuid> <new_name>', 'Rename VDI'),
    'vdi-destroy': ('<vdi_uuid>', 'Delete VDI'),
    'vif-create': ('<domname> <pycfg>', 'Create VIF attached to domname'),
    'vtpm-create' : ('<domname> <pycfg>', 'Create VTPM attached to domname'),


    'vm-create': ('<pycfg>', 'Create VM with python config'),
    'vm-destroy': ('<domname>', 'Delete VM'),
    
    'vm-list':   ('[--long]', 'List all domains.'),
    'vm-name':   ('<uuid>', 'Name of UUID.'),
    'vm-shutdown': ('<name> [opts]', 'Shutdown VM with name'),
    'vm-start':  ('<name>', 'Start VM with name'),
    'vm-uuid':   ('<name>', 'UUID of a domain by name.'),
    'async-vm-start': ('<name>', 'Start VM asynchronously'),
}


看一个例子

def xapi_vm_start(args, async = False):
    if len(args) < 1:
        raise OptionError("No Domain name specified.")
    

    # connect to xend
    server, session = connect()

    # convert vm name to vm uuid
    vm_uuid = resolve_vm(server, session, args[0])
    print 'Starting VM %s (%s)' % (args[0], vm_uuid)

    # call VM.start function
    success = execute(server, 'VM.start', (session, vm_uuid, False), async = async)
    if async:
        print 'Task started: %s' % success
    else:
        print 'Done.'


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值