Vijava 学习笔记之ResourcePool(基础配置信息)分析

无情 阅读:263 2021-03-31 22:37:08 评论:0

Vijava 代码

实体类:

package  com.vmware.pojo; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.Date; 
/** 
 * 虚拟机信息 
 * @author zhb 
 * 
 */ 
 
public class VirtualMachineInfo extends Entity{ 
    private String changeVersion; //更改后版本号 
    private Calendar modified;  //修改时间 
    private String name;  //名称 
    private String guestFullName; //操作系统全名 
    private String guestState;//操作系统运行状态 
    private String vmPowerState; //电源状态 
    private String version; //虚拟机版本号 
    private String uuid;  //特定id 
    private String instanceUuid;  //虚拟机实例id 
    private boolean template; //是否为模板 
    private String guestId;  //操作系统名称 
    private String alternateGuestName; //操作系统名称 
    private String annotation;//虚拟机的描述。 
    private String locationId; //本地目录 
 
    private int numCPU; //cpu数 
    private Integer numCoresPerSocket; //插槽cpu数 
    private int memoryMB; //内存大小,单位为MB 
    private String hostName;//主机全名 
    private String ipAddress; //IP地址 
    private ArrayList<VirtualMachineDiskInfo> disks = new ArrayList<VirtualMachineDiskInfo>(); //虚拟磁盘 
    private ArrayList<VirtualMachineNicInfo> nics = new ArrayList<VirtualMachineNicInfo>();//虚拟网卡 
    private ArrayList<String> datastores = new  ArrayList<String>(); //存储数据源 
    private ArrayList<String> networks = new ArrayList<String>();//网络信息,存储网络名称 
    private ArrayList<ControllerInfo> conts = new  ArrayList<ControllerInfo>();//控制器集 
    private ArrayList<GuestNicObject> guestNics = new ArrayList<GuestNicObject>();//客户机网卡地址配置信息 
 
    //下面一些关联关系,辅助查询 
    private String hostProdId; //主机程序内部id 
    private String resPoolProdId;//资源池程序内部id 
 
    private ResourceAllocationInfo cpuAllocation = new ResourceAllocationInfo(); //cpu分配信息 
    private ResourceAllocationInfo memoryAllocation = new ResourceAllocationInfo(); //内存分配信息 
    private VirtualMachineLogicDiskInfo[] logicDisks; //虚拟机逻辑磁盘信息 
    private ArrayList<VmSnapshot> snapshots = new ArrayList<VmSnapshot>();  //快照信息列表 
 
    private String parentFolderProgId;//父目录 
    private Date timePeriod;   //时间期限 
    private String applicant;  //资源申请人 
 
    private String currentSnapProgId;  //当前快照名称 
    private String vmPath; //存储位置 
 
 
 
    public String getChangeVersion() { 
        return changeVersion; 
    } 
    public void setChangeVersion(String changeVersion) { 
        this.changeVersion = changeVersion; 
    } 
    public Calendar getModified() { 
        return modified; 
    } 
    public void setModified(Calendar modified) { 
        this.modified = modified; 
    } 
    public String getName() { 
        return name; 
    } 
    public void setName(String name) { 
        this.name = name; 
    } 
    public String getGuestFullName() { 
        return guestFullName; 
    } 
    public void setGuestFullName(String guestFullName) { 
        this.guestFullName = guestFullName; 
    } 
    public String getVersion() { 
        return version; 
    } 
    public void setVersion(String version) { 
        this.version = version; 
    } 
    public String getUuid() { 
        return uuid; 
    } 
    public void setUuid(String uuid) { 
        this.uuid = uuid; 
    } 
    public String getInstanceUuid() { 
        return instanceUuid; 
    } 
    public void setInstanceUuid(String instanceUuid) { 
        this.instanceUuid = instanceUuid; 
    } 
    public boolean isTemplate() { 
        return template; 
    } 
    public void setTemplate(boolean template) { 
        this.template = template; 
    } 
    public String getGuestId() { 
        return guestId; 
    } 
    public void setGuestId(String guestId) { 
        this.guestId = guestId; 
    } 
    public String getAlternateGuestName() { 
        return alternateGuestName; 
    } 
    public void setAlternateGuestName(String alternateGuestName) { 
        this.alternateGuestName = alternateGuestName; 
    } 
    public String getAnnotation() { 
        return annotation; 
    } 
    public void setAnnotation(String annotation) { 
        this.annotation = annotation; 
    } 
    public String getLocationId() { 
        return locationId; 
    } 
    public void setLocationId(String locationId) { 
        this.locationId = locationId; 
    } 
    public int getNumCPU() { 
        return numCPU; 
    } 
    public void setNumCPU(int numCPU) { 
        this.numCPU = numCPU; 
    } 
    public Integer getNumCoresPerSocket() { 
        return numCoresPerSocket; 
    } 
    public void setNumCoresPerSocket(Integer numCoresPerSocket) { 
        this.numCoresPerSocket = numCoresPerSocket; 
    } 
    public int getMemoryMB() { 
        return memoryMB; 
    } 
    public void setMemoryMB(int memoryMB) { 
        this.memoryMB = memoryMB; 
    } 
    public String getHostName() { 
        return hostName; 
    } 
    public void setHostName(String hostName) { 
        this.hostName = hostName; 
    } 
    public String getIpAddress() { 
        return ipAddress; 
    } 
    public void setIpAddress(String ipAddress) { 
        this.ipAddress = ipAddress; 
    } 
    public ArrayList<VirtualMachineDiskInfo> getDisks() { 
        return disks; 
    } 
    public void setDisk(VirtualMachineDiskInfo disk){ 
        this.disks.add(disk); 
    } 
    public void setDisks(ArrayList<VirtualMachineDiskInfo> disks) { 
        this.disks = disks; 
    } 
    public ArrayList<VirtualMachineNicInfo> getNics() { 
        return nics; 
    } 
    public void setNic(VirtualMachineNicInfo nic){ 
        this.nics.add(nic); 
    } 
    public void setNics(ArrayList<VirtualMachineNicInfo> nics) { 
        this.nics = nics; 
    } 
    public ArrayList<String> getDatastores() { 
        return datastores; 
    } 
    public void setDatastore(String datastore){ 
        this.datastores.add(datastore); 
    } 
    public void setDatastores(ArrayList<String> datastores) { 
        this.datastores = datastores; 
    } 
    public ArrayList<String> getNetworks() { 
        return networks; 
    } 
    public void setNetwork(String network){ 
        this.networks.add(network); 
    } 
    public void setNetworks(ArrayList<String> networks) { 
        this.networks = networks; 
    } 
    public ArrayList<ControllerInfo> getConts() { 
        return conts; 
    } 
    public void setCont(ControllerInfo cont){ 
        this.conts.add(cont); 
    } 
    public void setConts(ArrayList<ControllerInfo> conts) { 
        this.conts = conts; 
    } 
    public String getGuestState() { 
        return guestState; 
    } 
    public void setGuestState(String guestState) { 
        this.guestState = guestState; 
    } 
    public String getVmPowerState() { 
        return vmPowerState; 
    } 
    public void setVmPowerState(String vmPowerState) { 
        this.vmPowerState = vmPowerState; 
    } 
    public String getHostProdId() { 
        return hostProdId; 
    } 
    public void setHostProdId(String hostProdId) { 
        this.hostProdId = hostProdId; 
    } 
    public String getResPoolProdId() { 
        return resPoolProdId; 
    } 
    public void setResPoolProdId(String resPoolProdId) { 
        this.resPoolProdId = resPoolProdId; 
    } 
    public ResourceAllocationInfo getCpuAllocation() { 
        return cpuAllocation; 
    } 
    public void setCpuAllocation(ResourceAllocationInfo cpuAllocation) { 
        this.cpuAllocation = cpuAllocation; 
    } 
    public ResourceAllocationInfo getMemoryAllocation() { 
        return memoryAllocation; 
    } 
    public void setMemoryAllocation(ResourceAllocationInfo memoryAllocation) { 
        this.memoryAllocation = memoryAllocation; 
    } 
    public VirtualMachineLogicDiskInfo[] getLogicDisks() { 
        return logicDisks; 
    } 
    public void setLogicDisks(VirtualMachineLogicDiskInfo[] logicDisks) { 
        this.logicDisks = logicDisks; 
    } 
    public ArrayList<GuestNicObject> getGuestNics() { 
        return guestNics; 
    } 
    public void setGuestNics(ArrayList<GuestNicObject> guestNics) { 
        this.guestNics = guestNics; 
    } 
    public ArrayList<VmSnapshot> getSnapshots() { 
        return snapshots; 
    } 
    public void addSnapshot(VmSnapshot vmSnapshot){ 
        snapshots.add(vmSnapshot); 
    } 
    public void setSnapshots(ArrayList<VmSnapshot> snapshots) { 
        this.snapshots = snapshots; 
    } 
    public String getParentFolderProgId() { 
        return parentFolderProgId; 
    } 
    public void setParentFolderProgId(String parentFolderProgId) { 
        this.parentFolderProgId = parentFolderProgId; 
    } 
    public String getApplicant() { 
        return applicant; 
    } 
    public void setApplicant(String applicant) { 
        this.applicant = applicant; 
    } 
    public Date getTimePeriod() { 
        return timePeriod; 
    } 
    public void setTimePeriod(Date timePeriod) { 
        this.timePeriod = timePeriod; 
    } 
    public String getCurrentSnapProgId() { 
        return currentSnapProgId; 
    } 
    public void setCurrentSnapProgId(String currentSnapProgId) { 
        this.currentSnapProgId = currentSnapProgId; 
    } 
    public String getVmPath() { 
        return vmPath; 
    } 
    public void setVmPath(String vmPath) { 
        this.vmPath = vmPath; 
    } 
}
package com.vmware.pojo; 
 
/** 
 * 虚拟机磁盘信息 
 * @author zhb 
 * 
 */ 
 
public class VirtualMachineDiskInfo { 
    private String diskType;//参数列表 
    /** 
     * 1:Sparse disk format, version 1 VirtualDiskSparseVer1BackingInfo 
     * 2:Sparse disk format, version 2 VirtualDiskSparseVer2BackingInfo 
     * 3:Flat disk format, version 1 VirtualDiskFlatVer1BackingInfo 
     * 4:Flat disk format, version 2 VirtualDiskFlatVer2BackingInfo 
     * 5:Raw disk format, version 2 VirtualDiskRawDiskVer2BackingInfo 
     * 6:Partitioned raw disk format, version 2  VirtualDiskPartitionedRawDiskVer2BackingInfo 
     * 7:Raw disk mapping, version 1 VirtualDiskRawDiskMappingVer1BackingInfo 
     */ 
    private String diskMode; 
    private String fileName;  //磁盘路经 
    private Long capacity;    //容量  
    private String uuid;      //特定id   
    private String label;     //名称 
    private String datastoreId; //数据源id 
    private int[] partition; //分区数 
    private String deviceName; //设备名 
    private int contIdKey; //对应相应的控制器 
    private int key;//程序内部用到的key 
    private int unitNumber; //内部序号 
    private String diskFlag; //磁盘标识 
    private String contentId;//容量id 
 
 
 
    public Long getCapacity() { 
        return capacity; 
    } 
    public void setCapacity(Long capacity) { 
        this.capacity = capacity; 
    } 
    public String getDiskType() { 
        return diskType; 
    } 
    public void setDiskType(String diskType) { 
        this.diskType = diskType; 
    } 
    public String getDiskMode() { 
        return diskMode; 
    } 
    public void setDiskMode(String diskMode) { 
        this.diskMode = diskMode; 
    } 
    public String getFileName() { 
        return fileName; 
    } 
    public void setFileName(String fileName) { 
        this.fileName = fileName; 
    } 
    public String getUuid() { 
        return uuid; 
    } 
    public void setUuid(String uuid) { 
        this.uuid = uuid; 
    } 
    public String getLabel() { 
        return label; 
    } 
    public void setLabel(String label) { 
        this.label = label; 
    } 
    public String getDatastoreId() { 
        return datastoreId; 
    } 
    public void setDatastoreId(String datastoreId) { 
        this.datastoreId = datastoreId; 
    } 
    public int[] getPartition() { 
        return partition; 
    } 
    public void setPartition(int[] partition) { 
        this.partition = partition; 
    } 
    public String getDeviceName() { 
        return deviceName; 
    } 
    public void setDeviceName(String deviceName) { 
        this.deviceName = deviceName; 
    } 
    public int getKey() { 
        return key; 
    } 
    public void setKey(int key) { 
        this.key = key; 
    } 
    public int getContIdKey() { 
        return contIdKey; 
    } 
    public void setContIdKey(int contIdKey) { 
        this.contIdKey = contIdKey; 
    } 
    public int getUnitNumber() { 
        return unitNumber; 
    } 
    public void setUnitNumber(int unitNumber) { 
        this.unitNumber = unitNumber; 
    } 
    public String getContentId() { 
        return contentId; 
    } 
    public void setContentId(String contentId) { 
        this.contentId = contentId; 
    } 
    public String getDiskFlag() { 
        return diskFlag; 
    } 
    public void setDiskFlag(String diskFlag) { 
        this.diskFlag = diskFlag; 
    } 
} 
package com.vmware.pojo; 
 
 
/** 
 * 虚拟机网卡配置信息 
 * @author zhb 
 * 
 */ 
 
public class VirtualMachineNicInfo extends Entity{ 
    private int vmId;  //虚拟机id 
    private String nicType;  /*类型  N	参数集: 
	VirtualE1000 
	VirtualPCNet32 
	VirtualVmxnet 
	VirtualVmxnet2 
	VirtualVmxnet3 
	Unknown*/ 
    private String addressType; //地址类型 
    private String macAddress; //mac地址 
    private String switchUuid; //交换机id 
    private String portgroupKey; //端口组id 
    private String portKey;//端口 
    private String deviceName;//设备名称 
    private int key;//内部键 
    private String networkType;//网络类型 
    private String wakeOnLanEnabled;  //局域网是否唤醒  1:唤醒 0: 不唤醒 
    private String startConnected;  //打开电源是否连接   1、	连接 0、	不连接 
    private String connected; //已连接  1、	连接 0、	不连接 
 
    public int getVmId() { 
        return vmId; 
    } 
    public void setVmId(int vmId) { 
        this.vmId = vmId; 
    } 
    public String getNicType() { 
        return nicType; 
    } 
    public void setNicType(String nicType) { 
        this.nicType = nicType; 
    } 
    public String getAddressType() { 
        return addressType; 
    } 
    public void setAddressType(String addressType) { 
        this.addressType = addressType; 
    } 
    public String getMacAddress() { 
        return macAddress; 
    } 
    public void setMacAddress(String macAddress) { 
        this.macAddress = macAddress; 
    } 
    public String getSwitchUuid() { 
        return switchUuid; 
    } 
    public void setSwitchUuid(String switchUuid) { 
        this.switchUuid = switchUuid; 
    } 
    public String getPortgroupKey() { 
        return portgroupKey; 
    } 
    public void setPortgroupKey(String portgroupKey) { 
        this.portgroupKey = portgroupKey; 
    } 
    public String getPortKey() { 
        return portKey; 
    } 
    public void setPortKey(String portKey) { 
        this.portKey = portKey; 
    } 
    public String getDeviceName() { 
        return deviceName; 
    } 
    public void setDeviceName(String deviceName) { 
        this.deviceName = deviceName; 
    } 
    public int getKey() { 
        return key; 
    } 
    public void setKey(int key) { 
        this.key = key; 
    } 
    public String getNetworkType() { 
        return networkType; 
    } 
    public void setNetworkType(String networkType) { 
        this.networkType = networkType; 
    } 
    public String getWakeOnLanEnabled() { 
        return wakeOnLanEnabled; 
    } 
    public void setWakeOnLanEnabled(String wakeOnLanEnabled) { 
        this.wakeOnLanEnabled = wakeOnLanEnabled; 
    } 
    public String getStartConnected() { 
        return startConnected; 
    } 
    public void setStartConnected(String startConnected) { 
        this.startConnected = startConnected; 
    } 
    public String getConnected() { 
        return connected; 
    } 
    public void setConnected(String connected) { 
        this.connected = connected; 
    } 
 
 
 
} 

package com.vmware.pojo; 
 
/** 
 * 控制器信息 
 * @author zhb 
 * 
 */ 
public class ControllerInfo { 
    private int contId; //控制器id 
    private String contType;//控制器类型 1:表示scsi控制器 
    private String contLable;//控制器标签 
    private int unitNumber;//设备节点 
    private int busNumber;//总线 
    private int key; //内部键 
    private int[] deviceKey; //所挂设备 
    private String busShareMode;//总线共享模式 
 
    public int getContId() { 
        return contId; 
    } 
    public void setContId(int contId) { 
        this.contId = contId; 
    } 
    public String getContLable() { 
        return contLable; 
    } 
    public void setContLable(String contLable) { 
        this.contLable = contLable; 
    } 
    public int getUnitNumber() { 
        return unitNumber; 
    } 
    public void setUnitNumber(int unitNumber) { 
        this.unitNumber = unitNumber; 
    } 
    public int getBusNumber() { 
        return busNumber; 
    } 
    public void setBusNumber(int busNumber) { 
        this.busNumber = busNumber; 
    } 
    public int getKey() { 
        return key; 
    } 
    public void setKey(int key) { 
        this.key = key; 
    } 
    public int[] getDeviceKey() { 
        return deviceKey; 
    } 
    public void setDeviceKey(int[] deviceKey) { 
        this.deviceKey = deviceKey; 
    } 
    public String getContType() { 
        return contType; 
    } 
    public void setContType(String contType) { 
        this.contType = contType; 
    } 
    public String getBusShareMode() { 
        return busShareMode; 
    } 
    public void setBusShareMode(String busShareMode) { 
        this.busShareMode = busShareMode; 
    } 
 
 
 
} 
package com.vmware.pojo; 
 
/** 
 * 客户机网卡IP地址配置信息 
 * @author zhb 
 * 
 */ 
public class GuestNicObject { 
    private String network;   //网络名称 
    private String ipAddress;//ip地址列表 
    private String macAddress;  //mac地址 
    private boolean connected;  //是否连接虚拟设备 
    private int deviceConfigId; 
    private GuestNicDnsObject nicDnsObject; //dns配置信息 
 
    public boolean isConnected() { 
        return connected; 
    } 
    public void setConnected(boolean connected) { 
        this.connected = connected; 
    } 
    public int getDeviceConfigId() { 
        return deviceConfigId; 
    } 
    public void setDeviceConfigId(int deviceConfigId) { 
        this.deviceConfigId = deviceConfigId; 
    } 
    public String getIpAddress() { 
        return ipAddress; 
    } 
    public void setIpAddress(String ipAddress) { 
        this.ipAddress = ipAddress; 
    } 
    public String getMacAddress() { 
        return macAddress; 
    } 
    public void setMacAddress(String macAddress) { 
        this.macAddress = macAddress; 
    } 
    public String getNetwork() { 
        return network; 
    } 
    public void setNetwork(String network) { 
        this.network = network; 
    } 
    public GuestNicDnsObject getNicDnsObject() { 
        return nicDnsObject; 
    } 
    public void setNicDnsObject(GuestNicDnsObject nicDnsObject) { 
        this.nicDnsObject = nicDnsObject; 
    } 
} 
package com.vmware.pojo; 
public class GuestNicDnsObject { 
    private boolean dhcp; 
    private String hostName; 
    private String domainName; 
    private String primaryAddress; //主dns地址 
    private String prepAddress;    //预备地址 
    private String[] searchDomain; 
 
    public boolean isDhcp() { 
        return dhcp; 
    } 
    public void setDhcp(boolean dhcp) { 
        this.dhcp = dhcp; 
    } 
    public String getDomainName() { 
        return domainName; 
    } 
    public void setDomainName(String domainName) { 
        this.domainName = domainName; 
    } 
    public String getHostName() { 
        return hostName; 
    } 
    public void setHostName(String hostName) { 
        this.hostName = hostName; 
    } 
    public String getPrepAddress() { 
        return prepAddress; 
    } 
    public void setPrepAddress(String prepAddress) { 
        this.prepAddress = prepAddress; 
    } 
    public String getPrimaryAddress() { 
        return primaryAddress; 
    } 
    public void setPrimaryAddress(String primaryAddress) { 
        this.primaryAddress = primaryAddress; 
    } 
    public String[] getSearchDomain() { 
        return searchDomain; 
    } 
    public void setSearchDomain(String[] searchDomain) { 
        this.searchDomain = searchDomain; 
    } 
} 

逻辑层:

package com.vmware.resourcepool; 
 
import com.vmware.pojo.ResourcePoolInfo; 
import com.vmware.vim25.mo.*; 
 
/** 
 * Created by vixuan-008 on 2015/4/27. 
 */ 
public class ResourcePoolOption { 
    /** 
     * 数据中心发现资源池 
     * @param dcName      数据中心 
     * @param clusterName 集群资源池名称 
     * @return 
     */ 
    public ResourcePoolInfo resourcePoolDiscovery(ServiceInstance serviceInstance,String dcName,String clusterName){ 
      //  ServiceInstance serviceInstance = null; 
        ResourcePoolInfo resPoolInfo = null; 
        try 
        { 
     //       serviceInstance = resourcePoolServiceInstance.getServiceInstance(); 
            Folder rootFolder = serviceInstance.getRootFolder(); 
            Datacenter dc = (Datacenter) new InventoryNavigator(rootFolder).searchManagedEntity("Datacenter", dcName); 
 
            ClusterComputeResource clusterResPool = (ClusterComputeResource) new InventoryNavigator(dc).searchManagedEntity("ClusterComputeResource",clusterName); 
            ResourcePool resPool= clusterResPool.getResourcePool(); 
            resPoolInfo = new ResourcePoolInfo(); 
            resPoolInfo.setName(resPool.getName()); 
            resPoolInfo.setChangeVersion(resPool.getConfig().getChangeVersion()); 
            resPoolInfo.setLastModified(resPool.getConfig().getLastModified()); 
            //cpu配置信息 
            resPoolInfo.setCpuExpandableReservation(resPool.getConfig().getCpuAllocation().getExpandableReservation()); 
            resPoolInfo.setCpuLevel(resPool.getConfig().getCpuAllocation().getShares().getLevel().name()); 
            resPoolInfo.setCpuLimit(resPool.getConfig().getCpuAllocation().getLimit()); 
            resPoolInfo.setCpuReservation(resPool.getConfig().getCpuAllocation().getReservation()); 
            //内存配置信息 
            resPoolInfo.setMemExpandableReservation(resPool.getConfig().getMemoryAllocation().getExpandableReservation()); 
            resPoolInfo.setMemLevel(resPool.getConfig().getMemoryAllocation().getShares().getLevel().name()); 
            resPoolInfo.setMemLimit(resPool.getConfig().getMemoryAllocation().getLimit()); 
            resPoolInfo.setMemReservation(resPool.getConfig().getMemoryAllocation().getReservation()); 
            resPoolInfo.setProgId(resPool.getMOR().val); 
            //主机信息 
            for(int i=0;i<clusterResPool.getHosts().length;i++) 
            { 
                HostSystem host = clusterResPool.getHosts()[i]; 
               // resPoolInfo.setHost(host.getMOR().val); 
                resPoolInfo.setHost(host.getName()); 
            } 
            //存储信息 
            for(int i=0;i<clusterResPool.getDatastores().length;i++) 
            { 
                Datastore datastore = clusterResPool.getDatastores()[i]; 
             //   resPoolInfo.setDatastore(datastore.getMOR().val); 
                resPoolInfo.setDatastore(datastore.getName()); 
            } 
            //网络信息 
            for(int i=0;i<clusterResPool.getNetworks().length;i++) 
            { 
                Network network = clusterResPool.getNetworks()[i]; 
           //     resPoolInfo.setNetwork(network.getMOR().val); 
                resPoolInfo.setNetwork(network.getName()); 
            } 
            setResouceVms(resPoolInfo,resPool); 
            getChildPools(resPoolInfo,resPool); 
        }catch(Exception e) 
        { 
 
        } 
        return resPoolInfo; 
    } 
 
 
    private void getChildPools(ResourcePoolInfo resPoolInfo,ResourcePool resPool) 
    { 
        try 
        { 
            System.out.println(resPool.getName()); 
            if(resPool.getResourcePools()!=null && resPool.getResourcePools().length>0) 
            { 
                for(int i=0;i<resPool.getResourcePools().length;i++) 
                { 
                    ResourcePoolInfo newResPoolInfo = new ResourcePoolInfo(); 
                    ResourcePool newResPool= resPool.getResourcePools()[i]; 
                    newResPoolInfo.setName(newResPool.getName()); 
                    newResPoolInfo.setChangeVersion(newResPool.getConfig().getChangeVersion()); 
                    newResPoolInfo.setLastModified(newResPool.getConfig().getLastModified()); 
                    //cpu配置信息 
                    newResPoolInfo.setCpuExpandableReservation(newResPool.getConfig().getCpuAllocation().getExpandableReservation()); 
                    newResPoolInfo.setCpuLevel(newResPool.getConfig().getCpuAllocation().getShares().getLevel().name()); 
                    newResPoolInfo.setCpuLimit(newResPool.getConfig().getCpuAllocation().getLimit()); 
                    newResPoolInfo.setCpuReservation(newResPool.getConfig().getCpuAllocation().getReservation()); 
                    //内存配置信息 
                    newResPoolInfo.setMemExpandableReservation(newResPool.getConfig().getMemoryAllocation().getExpandableReservation()); 
                    newResPoolInfo.setMemLevel(newResPool.getConfig().getMemoryAllocation().getShares().getLevel().name()); 
                    newResPoolInfo.setMemLimit(newResPool.getConfig().getMemoryAllocation().getLimit()); 
                    newResPoolInfo.setMemReservation(newResPool.getConfig().getMemoryAllocation().getReservation()); 
                    newResPoolInfo.setProgId(newResPool.getMOR().val); 
                    resPoolInfo.setChildResPool(newResPoolInfo); 
                    setResouceVms(newResPoolInfo,newResPool); 
                    getChildPools(newResPoolInfo,newResPool); 
                } 
            } 
        }catch(Exception e) 
        { 
 
        } 
    } 
 
    private void setResouceVms(ResourcePoolInfo resPoolInfo,ResourcePool resPool) 
    { 
        try 
        { 
 
            if(resPool.getVMs()!=null) 
            { 
                for(int i=0;i<resPool.getVMs().length;i++) 
                { 
                    resPoolInfo.setVm(resPool.getVMs()[i].getMOR().val); 
                } 
            } 
        }catch(Exception e) 
        { 
 
        } 
    } 
} 


测试代码:

package com.vmware.main; 
 
 
import com.vmware.pojo.ResourcePoolInfo; 
import com.vmware.resourcepool.ResourcePoolOption; 
import com.vmware.util.Session; 
import com.vmware.vim25.mo.ServiceInstance; 
import java.util.ArrayList; 
/** 
 * Created by vixuan-008 on 2015/4/27. 
 */ 
public class ResourcePoolOptionTest { 
    public static void main(String[] args){ 
        try{ 
            ServiceInstance serviceInstance= Session.getInstance("172.16.1.20", "root", "vmware"); 
            ResourcePoolOption resourcePoolOption=new ResourcePoolOption(); 
            ResourcePoolInfo resourcePoolInfo=resourcePoolOption.resourcePoolDiscovery(serviceInstance,"Datacenter","ehc"); 
            if(resourcePoolInfo!=null){ 
                //资源池名称 
                System.out.println("pool name is:"+resourcePoolInfo.getName()); 
               //虚拟机信息 
                ArrayList<String> vms=resourcePoolInfo.getVms(); 
                if(vms.size()>0){ 
                    for(String vm:vms){ 
                        System.out.println("virtualMachine Name is:" + vm); 
                    } 
                } 
                //物理服务器 
                ArrayList<String> hosts=resourcePoolInfo.getHosts(); 
                if(hosts.size()>0){ 
                    for(String host:hosts){ 
                        System.out.println("HostSystem Name is:" + host); 
                    } 
                } 
 
            } 
            serviceInstance.getServerConnection().logout(); 
 
 
 
        }catch (Exception e){ 
            e.printStackTrace(); 
        } 
    } 
} 

效果展示:




声明

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

发表评论
搜索
KIKK导航

KIKK导航

排行榜
关注我们

一个IT知识分享的公众号