libvirt_utils.py 文件源码

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

项目:daisy 作者: opnfv 项目源码 文件源码
def delete_vm_and_disk(vm_name):
    LI('Begin to delete VM %s', vm_name)
    conn = libvirt.open('qemu:///system')
    vm = None
    for item in conn.listAllDomains():
        if vm_name == item.name():
            vm = item
            break
    if vm is None:
        conn.close()
        LI('VM %s is not found' % vm_name)
        return

    output = vm.XMLDesc()
    root = ET.fromstring(output)

    if vm.isActive():
        vm.destroy()
        LI('Destroy VM %s' % vm.name())
    vm.undefine()

    for disk_file in get_disk_file(root):
        if os.path.isfile(disk_file):
            status, output = commands.getstatusoutput('rm -f %s' % disk_file)
            if status:
                LW('Failed to delete the VM disk file %s' % disk_file)

    conn.close()
    LI('VM %s is removed' % vm_name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号