use of com.vmware.vim25.mo.ResourcePool in project photon-model by vmware.
the class EnumerationClient method buildFullTraversal.
/**
* @return An array of SelectionSpec covering VM, Host, Resource pool,
* Cluster Compute Resource and Datastore.
*/
public List<SelectionSpec> buildFullTraversal() {
// Terminal traversal specs
// RP -> VM
TraversalSpec rpToVm = new TraversalSpec();
rpToVm.setType(VimNames.TYPE_RESOURCE_POOL);
rpToVm.setName("rpToVm");
rpToVm.setPath("vm");
rpToVm.setSkip(Boolean.FALSE);
// vApp -> VM
TraversalSpec vAppToVM = new TraversalSpec();
vAppToVM.setType(VimNames.TYPE_VAPP);
vAppToVM.setName("vAppToVM");
vAppToVM.setPath("vm");
// HostSystem -> VM
TraversalSpec hToVm = new TraversalSpec();
hToVm.setType(VimNames.TYPE_HOST);
hToVm.setPath("vm");
hToVm.setName("hToVm");
hToVm.getSelectSet().add(getSelectionSpec("VisitFolders"));
hToVm.setSkip(Boolean.FALSE);
// DC -> DS
TraversalSpec dcToDs = new TraversalSpec();
dcToDs.setType(VimNames.TYPE_DATACENTER);
dcToDs.setPath("datastore");
dcToDs.setName("dcToDs");
dcToDs.setSkip(Boolean.FALSE);
// Recurse through all ResourcePools
TraversalSpec rpToRp = new TraversalSpec();
rpToRp.setType(VimNames.TYPE_RESOURCE_POOL);
rpToRp.setPath("resourcePool");
rpToRp.setSkip(Boolean.FALSE);
rpToRp.setName("rpToRp");
rpToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec crToRp = new TraversalSpec();
crToRp.setType(VimNames.TYPE_COMPUTE_RESOURCE);
crToRp.setPath("resourcePool");
crToRp.setSkip(Boolean.FALSE);
crToRp.setName("crToRp");
crToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec crToH = new TraversalSpec();
crToH.setType(VimNames.TYPE_COMPUTE_RESOURCE);
crToH.setSkip(Boolean.FALSE);
crToH.setPath("host");
crToH.setName("crToH");
TraversalSpec dcToHf = new TraversalSpec();
dcToHf.setType(VimNames.TYPE_DATACENTER);
dcToHf.setSkip(Boolean.FALSE);
dcToHf.setPath("hostFolder");
dcToHf.setName("dcToHf");
dcToHf.getSelectSet().add(getSelectionSpec("VisitFolders"));
TraversalSpec vAppToRp = new TraversalSpec();
vAppToRp.setType(VimNames.TYPE_VAPP);
vAppToRp.setName("vAppToRp");
vAppToRp.setPath("resourcePool");
vAppToRp.getSelectSet().add(getSelectionSpec("rpToRp"));
TraversalSpec dcToVmf = new TraversalSpec();
dcToVmf.setType(VimNames.TYPE_DATACENTER);
dcToVmf.setSkip(Boolean.FALSE);
dcToVmf.setPath("vmFolder");
dcToVmf.setName("dcToVmf");
dcToVmf.getSelectSet().add(getSelectionSpec("VisitFolders"));
TraversalSpec dcToNetf = new TraversalSpec();
dcToNetf.setType(VimNames.TYPE_DATACENTER);
dcToNetf.setSkip(Boolean.FALSE);
dcToNetf.setPath("networkFolder");
dcToNetf.setName("dcToNetf");
dcToNetf.getSelectSet().add(getSelectionSpec("VisitFolders"));
TraversalSpec dcToNet = new TraversalSpec();
dcToNet.setType(VimNames.TYPE_DATACENTER);
dcToNet.setSkip(Boolean.FALSE);
dcToNet.setPath("network");
dcToNet.setName("dcToNet");
// For Folder -> Folder recursion
TraversalSpec visitFolders = new TraversalSpec();
visitFolders.setType(VimNames.TYPE_FOLDER);
visitFolders.setPath("childEntity");
visitFolders.setSkip(Boolean.FALSE);
visitFolders.setName("VisitFolders");
List<SelectionSpec> sspecarrvf = new ArrayList<>();
sspecarrvf.add(getSelectionSpec("crToRp"));
sspecarrvf.add(getSelectionSpec("crToH"));
sspecarrvf.add(getSelectionSpec("dcToVmf"));
sspecarrvf.add(getSelectionSpec("dcToHf"));
sspecarrvf.add(getSelectionSpec("vAppToRp"));
sspecarrvf.add(getSelectionSpec("vAppToVM"));
sspecarrvf.add(getSelectionSpec("dcToDs"));
sspecarrvf.add(getSelectionSpec("hToVm"));
sspecarrvf.add(getSelectionSpec("rpToVm"));
sspecarrvf.add(getSelectionSpec("dcToNet"));
sspecarrvf.add(getSelectionSpec("dcToNetf"));
sspecarrvf.add(getSelectionSpec("VisitFolders"));
visitFolders.getSelectSet().addAll(sspecarrvf);
List<SelectionSpec> resultspec = new ArrayList<>();
resultspec.add(visitFolders);
resultspec.add(crToRp);
resultspec.add(crToH);
resultspec.add(dcToVmf);
resultspec.add(dcToHf);
resultspec.add(vAppToRp);
resultspec.add(vAppToVM);
resultspec.add(dcToDs);
resultspec.add(hToVm);
resultspec.add(rpToVm);
resultspec.add(rpToRp);
resultspec.add(dcToNet);
resultspec.add(dcToNetf);
return resultspec;
}
use of com.vmware.vim25.mo.ResourcePool in project photon-model by vmware.
the class OvfDeployer method deployOvf.
public ManagedObjectReference deployOvf(URI ovfUri, ManagedObjectReference host, ManagedObjectReference vmFolder, String vmName, List<OvfNetworkMapping> networks, ManagedObjectReference datastore, Collection<KeyValue> ovfProps, String deploymentConfig, ManagedObjectReference resourcePool) throws Exception {
String ovfDescriptor = getRetriever().retrieveAsString(ovfUri);
OvfCreateImportSpecParams params = new OvfCreateImportSpecParams();
params.setHostSystem(host);
params.setLocale("US");
params.setEntityName(vmName);
if (deploymentConfig == null) {
deploymentConfig = "";
}
params.setDeploymentOption(deploymentConfig);
params.getNetworkMapping().addAll(networks);
params.setDiskProvisioning(OvfCreateImportSpecParamsDiskProvisioningType.THIN.name());
if (ovfProps != null) {
params.getPropertyMapping().addAll(ovfProps);
}
ManagedObjectReference ovfManager = this.connection.getServiceContent().getOvfManager();
OvfCreateImportSpecResult importSpecResult = getVimPort().createImportSpec(ovfManager, ovfDescriptor, resourcePool, datastore, params);
if (!importSpecResult.getError().isEmpty()) {
return VimUtils.rethrow(importSpecResult.getError().get(0));
}
long totalBytes = getImportSizeBytes(importSpecResult);
ManagedObjectReference lease = getVimPort().importVApp(resourcePool, importSpecResult.getImportSpec(), vmFolder, host);
LeaseProgressUpdater leaseUpdater = new LeaseProgressUpdater(this.connection, lease, totalBytes);
GetMoRef get = new GetMoRef(this.connection);
HttpNfcLeaseInfo httpNfcLeaseInfo;
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
try {
leaseUpdater.awaitReady();
logger.info("Lease ready");
// start updating the lease
leaseUpdater.start(executorService);
httpNfcLeaseInfo = get.entityProp(lease, PROP_INFO);
List<HttpNfcLeaseDeviceUrl> deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
String ip = this.connection.getURI().getHost();
String basePath = extractBasePath(ovfUri);
for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrls) {
String deviceKey = deviceUrl.getImportKey();
for (OvfFileItem ovfFileItem : importSpecResult.getFileItem()) {
if (deviceKey.equals(ovfFileItem.getDeviceId())) {
logger.debug("Importing device id: {}", deviceKey);
String sourceUri = computeDiskSourceUri(basePath, ovfFileItem);
String uploadUri = makUploadUri(ip, deviceUrl);
uploadVmdkFile(ovfFileItem, sourceUri, uploadUri, leaseUpdater, this.ovfRetriever.getClient());
logger.info("Completed uploading VMDK file {}", sourceUri);
}
}
}
// complete lease
leaseUpdater.complete();
} catch (Exception e) {
leaseUpdater.abort(VimUtils.convertExceptionToFault(e));
logger.info("Error importing ovf", e);
throw e;
} finally {
executorService.shutdown();
}
httpNfcLeaseInfo = get.entityProp(lease, PROP_INFO);
ManagedObjectReference entity = httpNfcLeaseInfo.getEntity();
// as this is an OVF it makes sense to enable the OVF transport
// only the guestInfo is enabled by default
VmConfigSpec spec = new VmConfigSpec();
spec.getOvfEnvironmentTransport().add(TRANSPORT_GUESTINFO);
spec.getOvfEnvironmentTransport().add(TRANSPORT_ISO);
VirtualMachineConfigSpec reconfig = new VirtualMachineConfigSpec();
reconfig.setVAppConfig(spec);
ManagedObjectReference reconfigTask = getVimPort().reconfigVMTask(entity, reconfig);
VimUtils.waitTaskEnd(this.connection, reconfigTask);
return entity;
}
use of com.vmware.vim25.mo.ResourcePool in project photon-model by vmware.
the class GetMoRef method getVMTraversalSpec.
/**
* @return TraversalSpec specification to get to the VirtualMachine managed
* object.
*/
public TraversalSpec getVMTraversalSpec() {
// Create a traversal spec that starts from the 'root' objects
// and traverses the inventory tree to get to the VirtualMachines.
// Build the traversal specs bottoms up
// Traversal to get to the VM in a VApp
TraversalSpec vAppToVM = new TraversalSpecBuilder().name("vAppToVM").type("VirtualApp").path("vm");
// Traversal spec for VApp to VApp
TraversalSpec vAppToVApp = new TraversalSpecBuilder().name("vAppToVApp").type("VirtualApp").path("resourcePool").selectSet(// SelectionSpec for both VApp to VApp and VApp to VM
new SelectionSpecBuilder().name("vAppToVApp"), new SelectionSpecBuilder().name("vAppToVM"));
// This SelectionSpec is used for recursion for Folder recursion
SelectionSpec visitFolders = new SelectionSpecBuilder().name("VisitFolders");
// Traversal to get to the vmFolder from DataCenter
TraversalSpec dataCenterToVMFolder = new TraversalSpecBuilder().name("DataCenterToVMFolder").type("Datacenter").path("vmFolder").skip(false).selectSet(visitFolders);
// TraversalSpec to get to the DataCenter from rootFolder
return new TraversalSpecBuilder().name("VisitFolders").type("Folder").path("childEntity").skip(false).selectSet(visitFolders, dataCenterToVMFolder, vAppToVM, vAppToVApp);
}
use of com.vmware.vim25.mo.ResourcePool in project photon-model by vmware.
the class Lister method listFolder.
private List<Element> listFolder() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FinderException {
PropertyFilterSpec spec = new PropertyFilterSpec();
ObjectSpec objSpec = new ObjectSpec();
objSpec.setObj(this.start);
TraversalSpec selectionSpec = new TraversalSpec();
selectionSpec.setPath("childEntity");
selectionSpec.setType("Folder");
selectionSpec.setSkip(false);
objSpec.getSelectSet().add(selectionSpec);
spec.getObjectSet().add(objSpec);
// Retrieve all objects that we can deal with
String[] childTypes = { "Folder", "Datacenter", "VirtualMachine", "Network", "ComputeResource", "ClusterComputeResource", "Datastore" };
for (String t : childTypes) {
PropertySpec pspec = new PropertySpec();
pspec.setType(t);
pspec.getPathSet().add("name");
// Additional basic properties.
if (t.equals("ComputeResource") || t.equals("ClusterComputeResource")) {
// The ComputeResource and ClusterComputeResource are dereferenced in
// the ResourcePoolFlag. Make sure they always have their resourcePool
// field populated.
pspec.getPathSet().add("resourcePool");
}
spec.getPropSet().add(pspec);
}
return callPropertyCollectorAndConvert(spec);
}
use of com.vmware.vim25.mo.ResourcePool in project photon-model by vmware.
the class Lister method listComputeResource.
private List<Element> listComputeResource() throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ObjectSpec ospec = new ObjectSpec();
ospec.setSkip(true);
ospec.setObj(this.start);
for (String f : new String[] { "host", "resourcePool" }) {
TraversalSpec tspec = new TraversalSpec();
tspec.setPath(f);
tspec.setType("ComputeResource");
tspec.setSkip(false);
ospec.getSelectSet().add(tspec);
}
PropertyFilterSpec filter = new PropertyFilterSpec();
filter.getObjectSet().add(ospec);
for (String t : new String[] { "HostSystem", "ResourcePool" }) {
PropertySpec pspec = new PropertySpec();
pspec.setType(t);
pspec.getPathSet().add("name");
filter.getPropSet().add(pspec);
}
return callPropertyCollectorAndConvert(filter);
}
Aggregations