首页 > 其他分享 >(记录) libvirt事件使用方法

(记录) libvirt事件使用方法

时间:2022-11-01 09:56:49浏览次数:59  
标签:DOMAIN 记录 domain libvirt VIR SHUTOFF 事件 https

参考文档如下:

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
  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) }

标签:DOMAIN,记录,domain,libvirt,VIR,SHUTOFF,事件,https
From: https://www.cnblogs.com/qinghuan190319/p/16846710.html

相关文章

  • Pictionary 方法记录
    [COCI2017-2018#5]Pictionary题面翻译题目描述在宇宙一个不为人知的地方,有一个星球,上面有一个国家,只有数学家居住。在这个国家有\(n\)个数学家,有趣的是,每个数学家都住......
  • LeetCode刷题记录.Day2
    移除元素题目链接 27.移除元素-力扣(LeetCode)classSolution{public:intremoveElement(vector<int>&nums,intval){intslotIndex=0;......
  • SpringCloudAlibaba 主要组件与nacos 填坑记录
    SpringCloudAlibaba主要功能与实现组件(1)SpringCloudAlibaba主要功能与实现组件【功能与实现组件:】服务限流降级:基本说明:默认支持WebServlet、WebF......
  • Programiranje 方法记录
    [COCI2017-2018#3]Programiranje题面翻译题目描述LittleLeticija正在准备编程考试。虽然她已经解决了很多任务,但还有一个任务尚未解决,所以她正在向你寻求帮助。您将获......
  • [Pyhton] SimPy 离散事件模拟框架详解 —— 以一个简单的汽车充电排队模拟为例
    目录一、背景知识二、SimPy讲解2.1SimPy概述2.2基本概念2.3一个汽车开开停停的例子2.4在走走停停过程中增加充电过程(过程交互)2.5共享资源三、后续参考链接附录二......
  • 记录一个注意点:SimpleDateFormat转化问题
    SimpleDateFormatsimpleDateFormat=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");Stringformatdate=simpleDateFormat.format(newDate());//formatdate就是当前......
  • Power Automate获取sharepoint list记录中的附件,并将附件填写到审批中
    1、定义一个数组变量,用于存储附件数组  2、 获取sharepointList中的附件  3、循环获取附件中的每一个文件的内容,并追加到变量数组  {"Name":@{item......
  • Spring的事件机制
    Spring的事件包含三部分事件(ApplicationEvent):继承自jdk的EventObject,所有的事件都需要继承ApplicationEvent,并且通过构造器参数source得到事件源.应用事件监听器(A......
  • IDEA中的Cherry-Pick的使用及分支提交记录的合并
    什么是 cherry-pickhttps://blog.csdn.net/GBS20200720/article/details/123840359前言这里的cherry-pick指的是git的命令,cherry-pick这个命令的作用就是把指定的commi......
  • 使用int128记录大整数
    部分编译器支持128bit的整数表示,但是需要手写输入输出。注意:__int128等价于__int128_t,不存在int128和int128_t。输出函数:voidPrint128(__int128num){if(num<0......