参考文档如下:
https://www.cnblogs.com/dingyunfeng/p/12735512.html https://developer.aliyun.com/article/378327 C接口文档:https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventAgentLifecycleState C与python对应关系简介:https://libvirt.org/bindings.html python源码仓库:https://gitlab.com/libvirt/libvirt-python/-/tree/master/ python函数中文释义:https://my.oschina.net/guol/blog/131776 libvirt事件调用:https://www.javaroad.cn/questions/304518
事件回调中包含一级事件(event)和二级事件(details)
二级事件是产生一级事件的原因,eg:event is Stopped, details is Shutdown or Destroyed and so on, 即虚拟机停止,可能是由于内部正常关机或者外部关闭等等
事件回调函数中,event、detail的含义
def myDomainEventCallback(conn, dom, event, detail, opaque): print("myDomainEventCallback%s EVENT: Domain %s(%s) %s %s" % ( opaque, dom.name(), dom.ID(), DOM_EVENTS[event], DOM_EVENTS[event][detail])) DOM_EVENTS = Description( ("Defined", ("Added", "Updated", "Renamed", "Snapshot")), ("Undefined", ("Removed", "Renamed")), ("Started", ("Booted", "Migrated", "Restored", "Snapshot", "Wakeup")), ("Suspended", ("Paused", "Migrated", "IOError", "Watchdog", "Restored", "Snapshot", "API error", "Postcopy", "Postcopy failed")), ("Resumed", ("Unpaused", "Migrated", "Snapshot", "Postcopy")), ("Stopped", ("Shutdown", "Destroyed", "Crashed", "Migrated", "Saved", "Failed", "Snapshot", "Daemon")), ("Shutdown", ("Finished", "On guest request", "On host request")), ("PMSuspended", ("Memory", "Disk")), ("Crashed", ("Panicked",)),
libvirt state函数的返回值含义,返回一个列表,列表中有两个元素:state和Reason
enum virDomainState { VIR_DOMAIN_NOSTATE = 0 (0x0) no state VIR_DOMAIN_RUNNING = 1 (0x1) the domain is running VIR_DOMAIN_BLOCKED = 2 (0x2) the domain is blocked on resource VIR_DOMAIN_PAUSED = 3 (0x3) the domain is paused by user VIR_DOMAIN_SHUTDOWN = 4 (0x4) the domain is being shut down VIR_DOMAIN_SHUTOFF = 5 (0x5) the domain is shut off VIR_DOMAIN_CRASHED = 6 (0x6) the domain is crashed VIR_DOMAIN_PMSUSPENDED = 7 (0x7) the domain is suspended by guest power management VIR_DOMAIN_LAST = 8 (0x8) NB: this enum value will increase over time as new states are added to the libvirt API. It reflects the last state supported by this version of the libvirt API. }
根据state名字定位reason的enum结构,eg: ret = [5, 2]
state[5] = VIR_DOMAIN_SHUTOFF
定位virDomainShutoffReason结构体的2号:VIR_DOMAIN_SHUTOFF_DESTROYED
enum virDomainShutoffReason { VIR_DOMAIN_SHUTOFF_UNKNOWN = 0 (0x0) the reason is unknown标签:DOMAIN,记录,domain,libvirt,VIR,SHUTOFF,事件,https From: https://www.cnblogs.com/qinghuan190319/p/16846710.html
VIR_DOMAIN_SHUTOFF_SHUTDOWN = 1 (0x1) normal shutdown VIR_DOMAIN_SHUTOFF_DESTROYED = 2 (0x2) forced poweroff VIR_DOMAIN_SHUTOFF_CRASHED = 3 (0x3) domain crashed VIR_DOMAIN_SHUTOFF_MIGRATED = 4 (0x4) migrated to another host VIR_DOMAIN_SHUTOFF_SAVED = 5 (0x5) saved to a file VIR_DOMAIN_SHUTOFF_FAILED = 6 (0x6) domain failed to start VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT = 7 (0x7) restored from a snapshot which was taken while domain was shutoff VIR_DOMAIN_SHUTOFF_DAEMON = 8 (0x8) daemon decides to kill domain during reconnection processing VIR_DOMAIN_SHUTOFF_LAST = 9 (0x9) }