Windows下Libvirt Java API使用教程(二)- 接口使用说明

@Beforepublicvoidinit(){System.setProperty("jna.library.path","D:/Git-Repo/git/libvirt-java/libvirt-java/src/test/java/kubi/coder/");try{xenConn=newConnect("xen+tcp://10.4.55.203/");// system代表拥有系统权限/session是用户权限kvmConn=newConnect("qemu+tcp://10.4.54.10/system");}catch(LibvirtExceptione){e.printStackTrace();}}/**
* 主机信息探测接口验证，验证可以获取的主机属性和监控指标，分别考虑Xen环境和KVM环境
*
*
* @author lihzh
* @date 2012-5-15 下午1:28:00
*/@TestpublicvoidtestDetectHost(){// KVMdoDetectHost(kvmConn);// XENdoDetectHost(xenConn);}/**
* 执行探测主机测试函数
*
* @param conn
* @author lihzh
* @date 2012-5-15 下午1:37:37
*/privatevoiddoDetectHost(Connectconn){try{// Returns the free memory for the connection// System.out.println("FreeMemory: " + conn.getFreeMemory());// 不支持// Returns the system hostname on which the hypervisor is running.// (the result of the gethostname(2) system call)// If we are connected to a remote system,// then this returns the hostname of the remote systemSystem.out.println("Host name: "+conn.getHostName());// Gets the name of the Hypervisor software used.System.out.println("Type: "+conn.getType());// Gets the version level of the Hypervisor running. This may work// only with hypervisor call, i.e. with priviledged access to the// hypervisor, not with a Read-Only connection. If the version can't// be extracted by lack of capacities returns 0.// Returns:// major * 1,000,000 + minor * 1,000 + releaseSystem.out.println(conn.getVersion());NodeInfonodeInfo=conn.nodeInfo();System.out.println("the number of active CPUs: "+nodeInfo.cpus);System.out.println("number of core per socket: "+nodeInfo.cores);System.out.println("memory size in kilobytes: "+nodeInfo.memory);System.out.println("expected CPU frequency: "+nodeInfo.mhz);System.out.println("string indicating the CPU model: "+nodeInfo.model);System.out.println("the number of NUMA cell, 1 for uniform: "+nodeInfo.nodes);System.out.println("number of CPU socket per node: "+nodeInfo.sockets);System.out.println("number of threads per core: "+nodeInfo.threads);System.out.println("the total number of CPUs supported but not necessarily active in the host.: "+nodeInfo.maxCpus());// for (String interName : conn.listInterfaces()) {// System.out.println(interName);// } 不支持// Provides the list of names of defined interfaces on this host// for (String interName : conn.listDefinedInterfaces()) {// System.out.println(interName);// } // 不支持// Lists the active networks.for(StringnetworkName:conn.listNetworks()){System.out.println("Network name: "+networkName);}// Lists the names of the network filtersfor(StringnetworkFilterName:conn.listNetworkFilters()){System.out.println("Network filter name: "+networkFilterName);}System.out.println(conn.getCapabilities());}catch(LibvirtExceptione){e.printStackTrace();}}