博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
access remote libvirtd
阅读量:4947 次
发布时间:2019-06-11

本文共 2767 字,大约阅读时间需要 9 分钟。

访问远程libvirtd服务

因为是在一个可信环境中运行,所以可以忽略安全方面的操作,步骤如下:
(1)更改libvirtd配置
    1.1 更改/ect/sysconfig/libvirtd文件,打开LIBVIRTD_ARGS="--listen"设置
    1.2 更改/etc/libvirt/libvirtd.conf
        listen_tls = 0 #关闭tls
        listen_tcp = 1 # 打开tcp
        tcp_port = "16509" # 侦听关口
        listen_addr="0.0.0.0" # 侦听地址
        auth_tcp = "none" # 允许匿名访问
(2) 可以通过 virsh -c qemu+tcp://10.2.3.123:16509/system来访问10.2.3.123上面的libvirtd服务
(3) python代码示例如下:
  

import libvirtimport sysimport logging'''enum virDomainState {VIR_DOMAIN_NOSTATE    =     0    no stateVIR_DOMAIN_RUNNING    =     1    the domain is runningVIR_DOMAIN_BLOCKED    =     2    the domain is blocked on resourceVIR_DOMAIN_PAUSED    =     3    the domain is paused by userVIR_DOMAIN_SHUTDOWN    =     4    the domain is being shut downVIR_DOMAIN_SHUTOFF    =     5    the domain is shut offVIR_DOMAIN_CRASHED    =     6    the domain is crashedVIR_DOMAIN_PMSUSPENDED    =     7    the domain is suspended by guest power managementVIR_DOMAIN_LAST    =     8    NB: this enum value will increase over time as new events are added to the libvirt API. It reflects the last state supported by this version of the libvirt API.}struct virDomainInfo {unsigned char    state    the running state, one of virDomainStateunsigned long    maxMem    the maximum memory in KBytes allowedunsigned long    memory    the memory in KBytes used by the domainunsigned short    nrVirtCpu    the number of virtual CPUs for the domainunsigned long long    cpuTime    the CPU time used in nanoseconds}'''def get_VM_infos(host, port=16509):    '''    list domains of the specified host    '''    infos = []    try:        pass            uri = 'qemu+tcp://%s:%s/system' % (host, port)        conn = libvirt.openReadOnly(uri)        # list the defined but inactive domains        domains = [conn.lookupByName(name) for name in conn.listDefinedDomains()]        # list active domains        domains.extend([conn.lookupByID(i) for i in conn.listDomainsID()])        # for dom in domains:        #     print 'ID = %d' % dom.ID()        #     print 'Name = %s' % dom.name()        #     infos = dom.info()        #     print 'State = %d' % infos[0]        #     # print 'State = %s' %s dom.state(0)        #     print 'Max Memory = %s' % infos[1]        #     print 'Memory = %s' % info[2]        #     # print 'Max Memory = %d' % dom.maxMemory        #     print 'Number of virt CPUs = %d' % infos[3]        #     # print 'Number of virt CPUs = %s' % dom.maxVcpus()        #     print 'CPU Time (in ns) = %d' % infos[4]        #     print ' '        for dom in domains:            infos.append(dom.info())    except Exception, e:        print e    return infosif __name__ == '__main__':    infos = get_VM_infos('10.2.3.250', 16509)    print infos

 

转载于:https://www.cnblogs.com/Jerryshome/p/3484204.html

你可能感兴趣的文章
Adobe Scout 入门
查看>>
51nod 1247可能的路径
查看>>
js05-DOM对象二
查看>>
mariadb BINLOG_FORMAT = STATEMENT 异常
查看>>
jq工具函数(九)使用$.extend()扩展Object对象
查看>>
如何监视性能和分析等待事件
查看>>
常见错误: 创建 WCF RIA Services 类库后, 访问数据库出错
查看>>
C3P0 WARN: Establishing SSL connection without server's identity verification is not recommended
查看>>
CSUOJ 1541 There is No Alternative
查看>>
iPhone在日本最牛,在中国输得最慘
查看>>
2014百度之星资格赛的第二个问题
查看>>
动态方法决议 和 消息转发
查看>>
关于UI资源获取资源的好的网站
查看>>
Nginx代理访问提示ERR_CONTENT_LENGTH_MISMATCH异常的解决方案
查看>>
WPF自定义搜索框代码分享
查看>>
js 基础拓展
查看>>
Windows下常用测试命令
查看>>
SpringBoot访问html访问不了的问题
查看>>
{width=200px;height=300px;overflow:hidden}
查看>>
SDK提交到CocoaPods
查看>>