介绍完libvirt Java API的部署工作:
《Windows下Libvirt Java API使用教程(一)- 开发环境部署》
接下来我们就介绍一下接口的使用和代码样例。
libvirt的管理单位是单个主机,所以探测和监控接口所能获取的信息的最大范围也是主机。所以先从主机入手,验证libvirt接口。主机(libvirt所在管理节点)探测相关接口验证代码如下:
分别在KVM和XEN环境下测试了libvirt接口,测试结果如下:
Host name: s5410
Type: QEMU
9001
the number of active CPUs: 64
number of core per socket: 8
memory size in kilobytes: 49444896
expected CPU frequency: 2131
string indicating the CPU model: x86_64
the number of NUMA cell, 1 for uniform: 1
number of CPU socket per node: 4
number of threads per core: 2
the total number of CPUs supported but not necessarily active in the host.: 64
Network name: hello
Network name: default
Network filter name: no-other-l2-traffic
Network filter name: allow-dhcp
…
<capabilities>
<host>
<uuid>30b940dd-f79a-21a2-82d5-ddc1b1b4a7e4</uuid>
<cpu>
<arch>x86_64</arch>
<model>core2duo</model>
<topology sockets=’4′ cores=’8′ threads=’2’/>
<feature/>
<feature/>
…
</cpu>
<migration_features>
<live/>
<uri_transports>
<uri_transport>tcp</uri_transport>
</uri_transports>
</migration_features>
</host>
<guest>
<os_type>hvm</os_type>
<arch>
<wordsize>32</wordsize>
<emulator>/usr/libexec/qemu-kvm</emulator>
<machine>rhel5.4.0</machine>
<machine canonical=’rhel5.4.0′>pc</machine>
<machine>rhel5.4.4</machine>
<machine>rhel5.5.0</machine>
<machine>rhel5.6.0</machine>
<domain type=’qemu’>
</domain>
<domain type=’kvm’>
<emulator>/usr/libexec/qemu-kvm</emulator>
</domain>
</arch>
<features>
<cpuselection/>
<pae/>
<nonpae/>
<acpi default=’on’ toggle=’yes’/>
<apic default=’on’ toggle=’no’/>
</features>
</guest>
…
</capabilities>
Host name: s55203
Type: Xen
3001000
the number of active CPUs: 32
number of core per socket: 8
memory size in kilobytes: 50276352
expected CPU frequency: 1995
string indicating the CPU model: x86_64
the number of NUMA cell, 1 for uniform: 1
number of CPU socket per node: 2
number of threads per core: 2
the total number of CPUs supported but not necessarily active in the host.: 32
Network name: default
Network filter name: allow-dhcp-server
Network filter name: qemu-announce-self-rarp
…
<capabilities>
<host>
<cpu>
<arch>x86_64</arch>
<features>
<vmx/>
</features>
</cpu>
<migration_features>
<live/>
<uri_transports>
<uri_transport>xenmigr</uri_transport>
</uri_transports>
</migration_features>
</host>
<guest>
<os_type>xen</os_type>
<arch>
<wordsize>64</wordsize>
<emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
<machine>xenpv</machine>
<domain type=’xen’>
</domain>
</arch>
</guest>
…
</capabilities>
说明:
注1:标注不支持的,是在当前环境当前libvirt版本下,运行会报错的接口。
unsupported in sys interface
注2:名词解释
hvm:gives similar information but when running a 32 bit OS fully virtualized with Xen using the hvm support。
天不负;卧薪尝胆,三千越甲可吞吴。