Search in sources :

Example 6 with ResourcePool

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;
}
Also used : TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) ArrayList(java.util.ArrayList)

Example 7 with ResourcePool

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;
}
Also used : OvfFileItem(com.vmware.vim25.OvfFileItem) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OvfCreateImportSpecResult(com.vmware.vim25.OvfCreateImportSpecResult) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) IOException(java.io.IOException) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) OvfCreateImportSpecParams(com.vmware.vim25.OvfCreateImportSpecParams) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) HttpNfcLeaseInfo(com.vmware.vim25.HttpNfcLeaseInfo) VmConfigSpec(com.vmware.vim25.VmConfigSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) HttpNfcLeaseDeviceUrl(com.vmware.vim25.HttpNfcLeaseDeviceUrl)

Example 8 with ResourcePool

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);
}
Also used : TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) TraversalSpecBuilder(com.vmware.photon.controller.model.adapters.vsphere.util.builders.TraversalSpecBuilder) SelectionSpecBuilder(com.vmware.photon.controller.model.adapters.vsphere.util.builders.SelectionSpecBuilder)

Example 9 with ResourcePool

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);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Example 10 with ResourcePool

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);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)8 TraversalSpec (com.vmware.vim25.TraversalSpec)6 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)5 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)5 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)4 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)4 MethodFault (com.vmware.vim25.MethodFault)4 TaskInfo (com.vmware.vim25.TaskInfo)4 VirtualMachineDefinedProfileSpec (com.vmware.vim25.VirtualMachineDefinedProfileSpec)4 VirtualMachineRelocateSpec (com.vmware.vim25.VirtualMachineRelocateSpec)4 ArrayList (java.util.ArrayList)4 Lock (java.util.concurrent.locks.Lock)4 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 ClientUtils.findMatchingVirtualDevice (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice)3 OvfDeployer (com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfDeployer)3 OvfParser (com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser)3 OvfRetriever (com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever)3 ArrayOfVirtualDevice (com.vmware.vim25.ArrayOfVirtualDevice)3 DuplicateName (com.vmware.vim25.DuplicateName)3 FileAlreadyExists (com.vmware.vim25.FileAlreadyExists)3