迁移之前的libvirt事件

时间:2018-11-21 02:52:08

标签: virtualization qemu kvm libvirt

我正在尝试删除无法在迁移之前迁移的pci设备“ ivshmem”。

我使用了libvirt挂钩脚本,该脚本在挂钩时无法连接libvirtd,因此无法删除pci设备。

然后,我找到了libvirt api“ libvirt-event”并注册了“ VIR_DOMAIN_EVENT_ID_LIFECYCLE”,但这是“迁移之前”的事件

这是我的代码:

libvirt.virEventRegisterDefaultImpl()

def event_lifecycle_cb(conn, dom, event, detail, opaque):
    print ""
    print "=-" * 25
    print "%s event: %s detail %s" % (dom.name(), str(event), str(detail))
    #print "%s: event: %s (%s)" % (dom.name(), VIR_DOMAIN_EVENT_MAPPING.get(event, "?"), event)
    #print "%s: state: %s (%s)" % (dom.name(), VIR_DOMAIN_STATE_MAPPING.get(dom.state()[0], "?"), dom.state()[0])
    if event == 2:
        #
    if event == 3 and detail == 1:
        # delete the pci device 
    print "=-" * 25


def conn_register_event_id_lifecycle(conn):
    conn.domainEventRegisterAny(
        None,
        libvirt.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
        event_lifecycle_cb,
        conn)

# setup connection
#conn=libvirt.open("xen:///")
conn=libvirt.open("qemu:///system")
if conn == None:
    print 'Failed to open connection to the hypervisor'
    sys.exit(1)

# register events
conn_register_event_id_lifecycle(conn)

# event loop
while True:
    libvirt.virEventRunDefaultImpl()

提前感谢任何指针

0 个答案:

没有答案