1. 程式人生 > >Vijava 學習筆記之 虛擬機器連線

Vijava 學習筆記之 虛擬機器連線

    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();
            }
     
     
        }
    }