libvirt_utils.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:daisy 作者: opnfv 项目源码 文件源码
def create_vm(template, name=None, disks=None, physical_bridge=None):
    LI('Begin to create VM %s' % template)

    if name or disks or physical_bridge:
        tree = ET.ElementTree(file=template)
        root = tree.getroot()
        if name:
            modify_vm_name(root, name)
        if disks:
            modify_vm_disk_file(root, disks)
        if physical_bridge:
            modify_vm_bridge(root, physical_bridge)

        temp_file = path_join(WORKSPACE, 'tmp.xml')
        tree.write(temp_file)
        output = commands.getoutput('cat %s' % temp_file)
        os.remove(temp_file)
    else:
        output = commands.getoutput('cat %s' % template)

    conn = libvirt.open('qemu:///system')
    domain = conn.defineXML(output)
    if domain is None:
        err_exit('Failed to define VM %s' % template)
    if domain.create() < 0:
        err_exit('Failed to start VM %s' % template)
    domain.setAutostart(1)
    conn.close()

    LI('VM %s is started' % domain.name())
    return domain
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号