Windows下Libvirt Java API使用教程(二)- 接口使用说明
2012-05-16 19:39:43 来源:WEB开发网核心提示:循环较多,摘取部分结果如下: Active vm id: 53Domain id: 53Domain name: i-546A099EDomain os type: hvmDomain uuid: e608560a-2c03-8e48-2e60-d0d01693f530Domain max memory: 147456
循环较多,摘取部分结果如下:
Active vm id: 53
Domain id: 53
Domain name: i-546A099E
Domain os type: hvm
Domain uuid: e608560a-2c03-8e48-2e60-d0d01693f530
Domain max memory: 147456
Domain max vcpu: 1
Domain xml description: <domain type='xen' id='53'>
<name>i-546A099E</name>
<uuid>e608560a-2c03-8e48-2e60-d0d01693f530</uuid>
<memory>131072</memory>
<currentMemory>131072</currentMemory>
<vcpu>1</vcpu>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/opt/awcloud/instance/admin/i-546A099E/disk'/>
<target dev='hda' bus='ide'/>
</disk>
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/opt/awcloud/instance/admin/i-546A099E/disk2'/>
<target dev='hdb' bus='ide'/>
</disk>
<interface type='bridge'>
<mac address='d0:0d:54:6a:09:9e'/>
<source bridge='xenbr0'/>
<script path='vif-bridge'/>
<target dev='vif53.0'/>
</interface>
<serial type='file'>
<source path='/opt/awcloud/instance/admin/i-546A099E/console.log'/>
<target port='0'/>
</serial>
<console type='file'>
<source path='/opt/awcloud/instance/admin/i-546A099E/console.log'/>
<target port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='17237' autoport='no'/>
</devices>
</domain>
Domain maxMen allowed: 147456
Domain memory: 139140
Domain state: VIR_DOMAIN_BLOCKED
Domain network autostart: false
cpu: 31
cpu time: 2225977676675
cpu number: 0
cpu state: VIR_VCPU_BLOCKED
Domain network autostart: false
Inactive domain name: i-46A70811
Inactive domain name: i-38C20705
Inactive domain name: i-498E09B2
Inactive domain name: null
Inactive domain name: null
Inactive domain name: null
Inactive domain name: null
Inactive domain name: null
结果分析:
结果中基本包含了一个虚拟机组成的全部元素信息。如果你想做一个监控系统,你可以发现这里有:
虚拟机的名字
虚拟机的Id
虚拟机的内存大小
虚拟CPU个数
虚拟机磁盘文件信息,磁盘文件的大小。甚至包括log等信息。
虚拟磁盘读写速率。
虚拟机网络设备信息。Mac地址,设备类型等。
虚拟机网卡读写速率。
基本可以满足一个监控系统的需求。
说明一下上面的测试代码。libvirt Java API的入口基本都是通过Connect这个类,也就是首先建立与被管理主机之间的连接:
Connect kvmConn = new Connect("qemu+tcp://10.4.54.10/system");
然后通过该连接获取信息:
conn.listDomains()
一个接口的如果需要接受参数:
conn.domainLookupByID(activeDomId)
肯定可以从其他的接口返回中找到答案:
for (int activeDomId : conn.listDomains())
只是有的获取的直接,有可能需要解析xml格式的返回值来获取需要参数值。比如:disk的paht和interface的path。
最后再简单介绍一下管控接口:
更多精彩
赞助商链接
