Vijava 学习笔记之 虚拟机连接解析

访客 阅读:225 2021-03-31 22:38:37 评论:0
package com.vmware.client; 
 
import com.vmware.util.ClientSesion; 
import com.vmware.vim25.VirtualMachineAffinityInfo; 
import com.vmware.vim25.VirtualMachineCapability; 
import com.vmware.vim25.VirtualMachineConfigInfo; 
import com.vmware.vim25.mo.*; 
import java.net.URL; 
 
/** 
 * Created by vixuan-008 on 2015/4/8. 
 * 测试类 
 */ 
public class Client { 
    public static void main(String[] args){ 
 
        try{ 
            ClientSesion session=new ClientSesion("172.16.1.20","root","vmware"); 
            URL url = new URL("https", session.getHost(), "/sdk"); 
            ServiceInstance si = new ServiceInstance(url, session.getUsername(), session.getPassword(), true); 
 
            Folder rootFolder = si.getRootFolder(); 
 
            ManagedEntity[] mes =new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); 
            if(mes==null || mes.length==0){ 
                si.getServerConnection().logout(); 
            } 
            System.out.println("VirtualMachine numbers:" + mes.length); 
 
            VirtualMachine virtualMachine=(VirtualMachine)mes[0]; 
            VirtualMachineConfigInfo config=virtualMachine.getConfig();//虚拟机配置信息 
            VirtualMachineCapability capability=virtualMachine.getCapability();//虚拟机容量信息 
 
            //虚拟机名称 
            System.out.println("virtualMachine Name:" + virtualMachine.getName()); 
           //虚拟机名称 
            System.out.println("virtualMachine Name:"+config.getName()); 
            //虚拟机描述 
            System.out.println("virtualMachind desciption:" + config.getAnnotation()); 
            //虚拟机关联CPU(关联Process 或者) 
            VirtualMachineAffinityInfo affinity=config.getCpuAffinity(); 
           //虚拟机版本信息 
            System.out.println("virtualMachine version" + config.getVersion()); 
            //虚拟机CPU 计数器是否启用 
            System.out.println("cpu counters enable:"+config.vPMCEnabled); 
 
 
 
 
 
 
 
        }catch(Exception e){ 
            e.printStackTrace(); 
        } 
 
 
    } 
} 

相关截图:


声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
排行榜
KIKK导航

KIKK导航

关注我们