Search in sources :

Example 11 with GetMoRef

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef 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 12 with GetMoRef

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.

the class CreatePortgroupFlow method createPortgroupInVsphere.

private ConnectionCallback createPortgroupInVsphere(DeferredResult<Void> result) {
    return (connection, error) -> {
        if (error != null) {
            result.fail(error);
            return;
        }
        // extract moref of the parent DVS switch
        ManagedObjectReference dvsRef = CustomProperties.of(this.networkState).getMoRef(CustomProperties.MOREF);
        DVPortgroupConfigSpec pgSpec = createDefaultPortgroupSpec();
        ManagedObjectReference task;
        try {
            task = connection.getVimPort().createDVPortgroupTask(dvsRef, pgSpec);
        } catch (Exception e) {
            result.fail(e);
            return;
        }
        TaskInfo taskInfo;
        try {
            taskInfo = VimUtils.waitTaskEnd(connection, task);
        } catch (Exception e) {
            result.fail(e);
            return;
        }
        if (taskInfo.getState() != TaskInfoState.SUCCESS) {
            IllegalStateException e = new IllegalStateException(taskInfo.getError().getLocalizedMessage());
            result.fail(e);
            return;
        }
        ManagedObjectReference pg = (ManagedObjectReference) taskInfo.getResult();
        AssertUtil.assertNotNull(pg, "MoRef of dvPortGroup");
        String pgKey = null;
        String dvsUuid = null;
        try {
            GetMoRef get = new GetMoRef(connection);
            Map<String, Object> propValues = get.entityProps(pg, VimPath.pg_config_key, VimPath.pg_config_distributedVirtualSwitch);
            pgKey = (String) propValues.get(VimPath.pg_config_key);
            ManagedObjectReference parentDvSwitch = (ManagedObjectReference) propValues.get(VimPath.pg_config_distributedVirtualSwitch);
            if (parentDvSwitch != null) {
                dvsUuid = get.entityProp(parentDvSwitch, VimPath.dvs_uuid);
            }
        } catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg ignore) {
            getService().logWarning("Cannot retrieve dvPortGroup properties of [%s]: %s", VimUtils.convertMoRefToString(pg), ignore.getLocalizedMessage());
        }
        // store the moref as custom property
        CustomProperties.of(this.subnetState).put(CustomProperties.MOREF, pg).put(DvsProperties.PORT_GROUP_KEY, pgKey).put(DvsProperties.DVS_UUID, dvsUuid);
        OperationContext.setFrom(getOperationContext());
        Operation.createPatch(PhotonModelUriUtils.createInventoryUri(getService().getHost(), this.subnetState.documentSelfLink)).setBody(this.subnetState).setCompletion((o, e) -> {
            if (e != null) {
                result.fail(e);
                return;
            }
            result.complete(null);
            getTaskManager().patchTask(TaskStage.FINISHED);
        }).sendWith(getService());
    };
}
Also used : VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) SessionUtil(com.vmware.photon.controller.model.resources.SessionUtil) OperationContext(com.vmware.xenon.common.OperationContext) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) DistributedVirtualPortgroupPortgroupType(com.vmware.vim25.DistributedVirtualPortgroupPortgroupType) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) AssertUtil(com.vmware.photon.controller.model.util.AssertUtil) TaskInfo(com.vmware.vim25.TaskInfo) VimUtils(com.vmware.photon.controller.model.adapters.vsphere.VimUtils) ConnectionCallback(com.vmware.photon.controller.model.adapters.vsphere.VSphereIOThreadPool.ConnectionCallback) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) CustomProperties(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) SubnetInstanceRequest(com.vmware.photon.controller.model.adapterapi.SubnetInstanceRequest) DeferredResult(com.vmware.xenon.common.DeferredResult) DVPortgroupConfigSpec(com.vmware.vim25.DVPortgroupConfigSpec) IAAS_API_ENABLED(com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) TaskInfoState(com.vmware.vim25.TaskInfoState) TaskInfo(com.vmware.vim25.TaskInfo) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) Map(java.util.Map) DVPortgroupConfigSpec(com.vmware.vim25.DVPortgroupConfigSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 13 with GetMoRef

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.

the class BaseVSphereAdapterTest method fetchVirtualDisk.

/**
 * Get the reference to Virtual Disk from VM.
 */
protected VirtualDisk fetchVirtualDisk(ComputeState vm, GetMoRef get) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference vmMoRef = CustomProperties.of(vm).getMoRef(MOREF);
    ArrayOfVirtualDevice devices = get.entityProp(vmMoRef, VimPath.vm_config_hardware_device);
    VirtualDisk vd = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).findFirst().orElse(null);
    return vd;
}
Also used : Arrays(java.util.Arrays) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState) VerificationHost(com.vmware.xenon.common.test.VerificationHost) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) StringUtils(org.apache.commons.lang3.StringUtils) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) Utils(com.vmware.xenon.common.Utils) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Builder(com.vmware.xenon.services.common.QueryTask.Builder) EnumSet(java.util.EnumSet) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) LIMIT_IOPS(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.LIMIT_IOPS) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) StatelessService(com.vmware.xenon.common.StatelessService) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) ServerX509TrustManager(com.vmware.photon.controller.model.security.ssl.ServerX509TrustManager) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) INSERT_CDROM(com.vmware.photon.controller.model.constants.PhotonModelConstants.INSERT_CDROM) LocalDateTime(java.time.LocalDateTime) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) COMPUTE_CPU_COUNT(com.vmware.photon.controller.model.adapters.vsphere.VSphereAdapterResizeComputeService.COMPUTE_CPU_COUNT) ArrayList(java.util.ArrayList) Query(com.vmware.xenon.services.common.QueryTask.Query) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) TestName(org.junit.rules.TestName) StatefulService(com.vmware.xenon.common.StatefulService) Before(org.junit.Before) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) File(java.io.File) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ExecutionException(java.util.concurrent.ExecutionException) ContentService(com.vmware.photon.controller.model.resources.ContentService) VirtualDisk(com.vmware.vim25.VirtualDisk) TestContext(com.vmware.xenon.common.test.TestContext) SHARES_LEVEL(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.SHARES_LEVEL) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) VirtualDiskType(com.vmware.vim25.VirtualDiskType) Service(com.vmware.xenon.common.Service) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ExampleService(com.vmware.xenon.services.common.ExampleService) SslTrustCertificateService(com.vmware.photon.controller.model.security.service.SslTrustCertificateService) QueryTask(com.vmware.xenon.services.common.QueryTask) TaskServiceState(com.vmware.xenon.services.common.TaskService.TaskServiceState) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) ServiceDocument(com.vmware.xenon.common.ServiceDocument) LifecycleState(com.vmware.photon.controller.model.support.LifecycleState) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) After(org.junit.After) MOREF(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.MOREF) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) X509TrustManagerResolver(com.vmware.photon.controller.model.security.ssl.X509TrustManagerResolver) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) PROVISION_TYPE(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVISION_TYPE) VSphereConstants(com.vmware.photon.controller.model.adapters.vsphere.constants.VSphereConstants) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) REBOOT_VM_FLAG(com.vmware.photon.controller.model.adapters.vsphere.VSphereAdapterResizeComputeService.REBOOT_VM_FLAG) DiskService(com.vmware.photon.controller.model.resources.DiskService) VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) HOST_NAME_KEY(com.vmware.photon.controller.model.adapters.vsphere.VSphereEndpointAdapterService.HOST_NAME_KEY) ResourceRemovalTaskService(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService) TestProperty(com.vmware.xenon.common.test.TestProperty) HashMap(java.util.HashMap) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) Function(java.util.function.Function) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) DISK_MODE_PERSISTENT(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_MODE_PERSISTENT) HashSet(java.util.HashSet) PhotonModelSecurityServices(com.vmware.photon.controller.model.security.PhotonModelSecurityServices) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) SharesLevel(com.vmware.vim25.SharesLevel) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Assert.assertNotNull(org.junit.Assert.assertNotNull) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) FileWriter(java.io.FileWriter) TestUtils.doPost(com.vmware.photon.controller.model.tasks.TestUtils.doPost) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) CertificateUtil(com.vmware.photon.controller.model.security.util.CertificateUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) Collections(java.util.Collections) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 14 with GetMoRef

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.

the class BaseVSphereAdapterTest method fetchAllVirtualDisks.

/**
 * Get the reference to Virtual Disk from VM.
 */
protected List<VirtualDisk> fetchAllVirtualDisks(ComputeState vm, GetMoRef get) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ManagedObjectReference vmMoRef = CustomProperties.of(vm).getMoRef(MOREF);
    ArrayOfVirtualDevice devices = get.entityProp(vmMoRef, VimPath.vm_config_hardware_device);
    return devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) SslTrustCertificateState(com.vmware.photon.controller.model.security.service.SslTrustCertificateService.SslTrustCertificateState) VerificationHost(com.vmware.xenon.common.test.VerificationHost) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) StringUtils(org.apache.commons.lang3.StringUtils) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) Utils(com.vmware.xenon.common.Utils) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Builder(com.vmware.xenon.services.common.QueryTask.Builder) EnumSet(java.util.EnumSet) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) LIMIT_IOPS(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.LIMIT_IOPS) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) StatelessService(com.vmware.xenon.common.StatelessService) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) ServerX509TrustManager(com.vmware.photon.controller.model.security.ssl.ServerX509TrustManager) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) INSERT_CDROM(com.vmware.photon.controller.model.constants.PhotonModelConstants.INSERT_CDROM) LocalDateTime(java.time.LocalDateTime) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) COMPUTE_CPU_COUNT(com.vmware.photon.controller.model.adapters.vsphere.VSphereAdapterResizeComputeService.COMPUTE_CPU_COUNT) ArrayList(java.util.ArrayList) Query(com.vmware.xenon.services.common.QueryTask.Query) ResourceRemovalTaskState(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService.ResourceRemovalTaskState) TestName(org.junit.rules.TestName) StatefulService(com.vmware.xenon.common.StatefulService) Before(org.junit.Before) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) File(java.io.File) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ExecutionException(java.util.concurrent.ExecutionException) ContentService(com.vmware.photon.controller.model.resources.ContentService) VirtualDisk(com.vmware.vim25.VirtualDisk) TestContext(com.vmware.xenon.common.test.TestContext) SHARES_LEVEL(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.SHARES_LEVEL) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) VirtualDiskType(com.vmware.vim25.VirtualDiskType) Service(com.vmware.xenon.common.Service) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ExampleService(com.vmware.xenon.services.common.ExampleService) SslTrustCertificateService(com.vmware.photon.controller.model.security.service.SslTrustCertificateService) QueryTask(com.vmware.xenon.services.common.QueryTask) TaskServiceState(com.vmware.xenon.services.common.TaskService.TaskServiceState) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) ServiceDocument(com.vmware.xenon.common.ServiceDocument) LifecycleState(com.vmware.photon.controller.model.support.LifecycleState) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) After(org.junit.After) MOREF(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.MOREF) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) X509TrustManagerResolver(com.vmware.photon.controller.model.security.ssl.X509TrustManagerResolver) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) PROVISION_TYPE(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVISION_TYPE) VSphereConstants(com.vmware.photon.controller.model.adapters.vsphere.constants.VSphereConstants) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) REBOOT_VM_FLAG(com.vmware.photon.controller.model.adapters.vsphere.VSphereAdapterResizeComputeService.REBOOT_VM_FLAG) DiskService(com.vmware.photon.controller.model.resources.DiskService) VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) HOST_NAME_KEY(com.vmware.photon.controller.model.adapters.vsphere.VSphereEndpointAdapterService.HOST_NAME_KEY) ResourceRemovalTaskService(com.vmware.photon.controller.model.tasks.ResourceRemovalTaskService) TestProperty(com.vmware.xenon.common.test.TestProperty) HashMap(java.util.HashMap) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) Function(java.util.function.Function) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) DISK_MODE_PERSISTENT(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_MODE_PERSISTENT) HashSet(java.util.HashSet) PhotonModelSecurityServices(com.vmware.photon.controller.model.security.PhotonModelSecurityServices) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) SharesLevel(com.vmware.vim25.SharesLevel) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Assert.assertNotNull(org.junit.Assert.assertNotNull) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) FileWriter(java.io.FileWriter) TestUtils.doPost(com.vmware.photon.controller.model.tasks.TestUtils.doPost) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) CertificateUtil(com.vmware.photon.controller.model.security.util.CertificateUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) Collections(java.util.Collections) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 15 with GetMoRef

use of com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef in project photon-model by vmware.

the class TestVSphereLibraryProvisionTaskWithStorage method deployFromLibraryWithAdditionalDisks.

@Test
public void deployFromLibraryWithAdditionalDisks() throws Throwable {
    ComputeService.ComputeState vm = provisionVMAndGetState(true, true);
    try {
        if (vm == null) {
            return;
        }
        // Verify that the disk is resized
        BasicConnection connection = createConnection();
        GetMoRef get = new GetMoRef(connection);
        List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
        assertEquals(3, virtualDisks.size());
        assertEquals(3, vm.diskLinks.size());
        List<DeferredResult<DiskService.DiskState>> disks = vm.diskLinks.stream().map(link -> {
            Operation getOp = Operation.createGet(this.host, link).setReferer(this.host.getReferer());
            return this.host.sendWithDeferredResult(getOp, DiskService.DiskState.class);
        }).collect(Collectors.toList());
        DeferredResult.allOf(disks).thenAccept(diskStates -> diskStates.stream().forEach(ds -> {
            assertNotNull(ds.customProperties);
            assertNotNull(ds.sourceImageReference);
            assertNotNull(ds.customProperties.get(PROVIDER_DISK_UNIQUE_ID));
        }));
    } finally {
        if (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) Collectors(java.util.stream.Collectors) List(java.util.List) VirtualDisk(com.vmware.vim25.VirtualDisk) DeferredResult(com.vmware.xenon.common.DeferredResult) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) DiskService(com.vmware.photon.controller.model.resources.DiskService) Assert.assertEquals(org.junit.Assert.assertEquals) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) Operation(com.vmware.xenon.common.Operation) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) DiskService(com.vmware.photon.controller.model.resources.DiskService) DeferredResult(com.vmware.xenon.common.DeferredResult) Test(org.junit.Test)

Aggregations

GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)20 BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)13 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)13 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)12 Test (org.junit.Test)8 VirtualDisk (com.vmware.vim25.VirtualDisk)7 Operation (com.vmware.xenon.common.Operation)7 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)6 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)6 VimPath (com.vmware.photon.controller.model.adapters.vsphere.util.VimPath)5 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)4 DiskService (com.vmware.photon.controller.model.resources.DiskService)4 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)4 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)4 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)3 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)3 ArrayOfVirtualDevice (com.vmware.vim25.ArrayOfVirtualDevice)3 TaskInfo (com.vmware.vim25.TaskInfo)3 TaskInfoState (com.vmware.vim25.TaskInfoState)3 DeferredResult (com.vmware.xenon.common.DeferredResult)3