private String getNetworkName(ConfigTarget configTarget) { if (configTarget.getNetwork() != null) { for (VirtualMachineNetworkInfo network : configTarget.getNetwork()) { NetworkSummary netSummary = network.getNetwork(); if (netSummary.isAccessible()) { return netSummary.getName(); } } } return null; }
/** * Create an instance of {@link ConfigTarget } * */ public ConfigTarget createConfigTarget() { return new ConfigTarget(); }
if(configTarget.getDatastore() != null) for (int i = 0; i < configTarget.getDatastore().length; i++) VirtualMachineDatastoreInfo vdsInfo = configTarget.getDatastore()[i]; DatastoreSummary dsSummary = vdsInfo.getDatastore(); if (dsSummary.isAccessible())
private VirtualMachineConfigSpec createVmConfigSpec(ConnectionResources connectionResources, VmInputs vmInputs) throws Exception { ConfigTarget configTarget = new VmUtils().getHostConfigTarget(connectionResources, connectionResources.getHostMor()); List<VirtualMachineDatastoreInfo> dataStoresList = configTarget.getDatastore(); String dataStoreName = vmInputs.getDataStore(); if (configTarget.getNetwork() != null) { nicSpec = vmUtils.getNicSpecs(networkName, null, VirtualDeviceConfigSpecOperation.ADD, GENERATED, DEFAULT_NIC_KEY, Operation.ADD.toString(), vmInputs);
private static DistributedVirtualPortgroupInfo getDvPortGroupInfo(VirtualMachine vm, String dvPort) throws Exception{ HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost()); ComputeResource cr = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser(); ConfigTarget configTarget = envBrowser.queryConfigTarget(host); DistributedVirtualPortgroupInfo dvPortgroupInfo = null; DistributedVirtualPortgroupInfo[] availableDvPortGroupInfo = configTarget.getDistributedVirtualPortgroup(); int j = 0; while (j < availableDvPortGroupInfo.length && dvPortgroupInfo == null) { dvPortgroupInfo = (availableDvPortGroupInfo[j].portgroupName.equalsIgnoreCase(dvPort)) ? availableDvPortGroupInfo[j] : null; j++; } if (dvPortgroupInfo == null) { throw new Exception("Impossible to find dvPortGroupInfo with name : " + dvPort); } return dvPortgroupInfo; }
if(configTarget.getDatastore() != null) for (int i = 0; i < configTarget.getDatastore().length; i++) VirtualMachineDatastoreInfo vdsInfo = configTarget.getDatastore()[i]; DatastoreSummary dsSummary = vdsInfo.getDatastore(); if (dsSummary.isAccessible())
if(configTarget.getNetwork() != null) for (int i = 0; i < configTarget.getNetwork().length; i++) VirtualMachineNetworkInfo netInfo = configTarget.getNetwork()[i]; NetworkSummary netSummary = netInfo.getNetwork(); if (netSummary.isAccessible())
static DatastoreSummary findDatastoreSummary(VirtualMachine vm, String dsName) throws Exception { DatastoreSummary dsSum = null; VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); if(hmor == null) { System.out.println("No Datastore found"); return null; } ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); VirtualMachineDatastoreInfo[] dis = configTarget.getDatastore(); for (int i=0; dis!=null && i<dis.length; i++) { dsSum = dis[i].getDatastore(); if (dsSum.isAccessible() && dsName.equals(dsSum.getName())) { break; } } return dsSum; }
if(configTarget.getNetwork() != null) for (int i = 0; i < configTarget.getNetwork().length; i++) VirtualMachineNetworkInfo netInfo = configTarget.getNetwork()[i]; NetworkSummary netSummary = netInfo.getNetwork(); if (netSummary.isAccessible())
static DatastoreSummary findDatastoreSummary(VirtualMachine vm, String dsName) throws Exception { DatastoreSummary dsSum = null; VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); if(hmor == null) { System.out.println("No Datastore found"); return null; } ConfigTarget configTarget = envBrowser.queryConfigTarget(new HostSystem(vm.getServerConnection(), hmor)); VirtualMachineDatastoreInfo[] dis = configTarget.getDatastore(); for (int i=0; dis!=null && i<dis.length; i++) { dsSum = dis[i].getDatastore(); if (dsSum.isAccessible() && dsName.equals(dsSum.getName())) { break; } } return dsSum; }
static boolean doesNetworkNameExist(VirtualMachine vm, String netName) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); HostSystem host = new HostSystem( vm.getServerConnection(), hmor); ConfigTarget cfg = envBrowser.queryConfigTarget(host); VirtualMachineNetworkInfo[] nets = cfg.getNetwork(); for (int i = 0; nets!=null && i < nets.length; i++) { NetworkSummary netSummary = nets[i].getNetwork(); if (netSummary.isAccessible() && netSummary.getName().equalsIgnoreCase(netName)) { return true; } } return false; } }
ManagedObjectReference cloneHostMor = getMorHost(vmInputs.getCloneHost(), connectionResources, vmMor); ConfigTarget configTarget = getHostConfigTarget(connectionResources, cloneHostMor); List<VirtualMachineDatastoreInfo> dataStoreInfoList = configTarget.getDatastore(); for (VirtualMachineDatastoreInfo dataStoreInfo : dataStoreInfoList) { if (vmInputs.getCloneDataStore().equals(dataStoreInfo.getDatastore().getName())) {
static boolean doesNetworkNameExist(VirtualMachine vm, String netName) throws Exception { VirtualMachineRuntimeInfo vmRuntimeInfo = vm.getRuntime(); EnvironmentBrowser envBrowser = vm.getEnvironmentBrowser(); ManagedObjectReference hmor = vmRuntimeInfo.getHost(); HostSystem host = new HostSystem( vm.getServerConnection(), hmor); ConfigTarget cfg = envBrowser.queryConfigTarget(host); VirtualMachineNetworkInfo[] nets = cfg.getNetwork(); for (int i = 0; nets!=null && i < nets.length; i++) { NetworkSummary netSummary = nets[i].getNetwork(); if (netSummary.isAccessible() && netSummary.getName().equalsIgnoreCase(netName)) { return true; } } return false; } }