Search in sources :

Example 6 with ArrayOfVirtualDevice

use of com.vmware.vim25.ArrayOfVirtualDevice 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 7 with ArrayOfVirtualDevice

use of com.vmware.vim25.ArrayOfVirtualDevice 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 8 with ArrayOfVirtualDevice

use of com.vmware.vim25.ArrayOfVirtualDevice in project photon-model by vmware.

the class InstanceClient method attachExternalDisks.

/**
 * Attach any externally created disks to the VM if any.
 */
public void attachExternalDisks() throws Exception {
    if (this.externalDisks == null || this.externalDisks.isEmpty()) {
        return;
    }
    if (this.vm == null) {
        throw new IllegalStateException("Cannot attach diskStates if VM is not created");
    }
    for (DiskStateExpanded diskState : this.externalDisks) {
        ArrayOfVirtualDevice devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
        String diskDatastoreName = CustomProperties.of(diskState).getString(DISK_DATASTORE_NAME);
        ClientUtils.attachDiskToVM(devices, this.vm, diskState, this.finder.datastore(diskDatastoreName).object, this.connection, this.getVimPort());
    }
}
Also used : DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice)

Example 9 with ArrayOfVirtualDevice

use of com.vmware.vim25.ArrayOfVirtualDevice in project photon-model by vmware.

the class InstanceClient method cloneOvfBasedTemplate.

private ManagedObjectReference cloneOvfBasedTemplate(ManagedObjectReference vmTempl, ManagedObjectReference datastore, ManagedObjectReference folder, ManagedObjectReference resourcePool, List<VirtualMachineDefinedProfileSpec> pbmSpec) throws Exception {
    String vmName = this.ctx.child.name;
    Map<String, Object> props = this.get.entityProps(vmTempl, VimPath.vm_summary_config_numCpu, VimPath.vm_summary_config_memorySizeMB, VimPath.vm_snapshot, VimPath.vm_config_hardware_device, VimPath.vm_config_vAppConfig_property);
    VirtualMachineSnapshotInfo snapshot = (VirtualMachineSnapshotInfo) props.get(VimPath.vm_snapshot);
    ArrayOfVirtualDevice devices = (ArrayOfVirtualDevice) props.get(VimPath.vm_config_hardware_device);
    VirtualDisk vd = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).findFirst().orElse(null);
    VirtualSCSIController scsiController = getFirstScsiController(devices);
    Integer[] scsiUnit = findFreeScsiUnit(scsiController, devices.getVirtualDevice());
    VirtualMachineRelocateDiskMoveOptions diskMoveOption = computeDiskMoveType();
    boolean customizeImageDisk = false;
    List<VirtualDeviceConfigSpec> newDisks = new ArrayList<>();
    VirtualMachineRelocateSpecDiskLocator bootDiskLocator = null;
    List<VirtualDisk> vDisks = null;
    if (this.bootDisk != null) {
        if (vd == null) {
            String datastoreName = this.get.entityProp(datastore, VimPath.ds_summary_name);
            String path = makePathToVmdkFile("ephemeral_disk", vmName);
            String diskName = String.format(VM_PATH_FORMAT, datastoreName, path);
            VirtualDeviceConfigSpec hdd = createHdd(scsiController.getKey(), scsiUnit[0], this.bootDisk, diskName, datastore, pbmSpec);
            newDisks.add(hdd);
        } else {
            // strategy
            if (this.imageDisks != null && !this.imageDisks.isEmpty()) {
                vDisks = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).filter(d -> {
                    DiskStateExpanded ds = findMatchingImageDiskState(d, this.imageDisks);
                    return toKb(ds.capacityMBytes) > d.getCapacityInKB() || ds.customProperties != null;
                }).collect(Collectors.toList());
                if (vDisks.size() > 0) {
                    diskMoveOption = VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING;
                    logger.warn("Changing clone strategy to MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING, as there is disk resize requested");
                    customizeImageDisk = true;
                    bootDiskLocator = setProvisioningType(vDisks.get(0), datastore, pbmSpec);
                }
            }
        }
    }
    VirtualCdrom vcd = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualCdrom).map(d -> (VirtualCdrom) d).findFirst().orElse(null);
    // add a cdrom so that ovf transport works
    if (vcd == null) {
        VirtualDevice ideController = getFirstIdeController(devices);
        int ideUnit = findFreeUnit(ideController, devices.getVirtualDevice());
        VirtualDeviceConfigSpec cdrom = createCdrom(ideController, ideUnit);
        newDisks.add(cdrom);
    } else {
        VirtualDeviceConfigSpec cdrom = reconfigureCdrom(vcd);
        newDisks.add(cdrom);
    }
    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    // even though this is a clone, hw config from the compute resource
    // is takes precedence
    spec.setNumCPUs((int) this.ctx.child.description.cpuCount);
    spec.setMemoryMB(toMemoryMb(this.ctx.child.description.totalMemoryBytes));
    String gt = CustomProperties.of(this.ctx.child).getString(CustomProperties.GUEST_ID, null);
    if (gt != null) {
        spec.setGuestId(gt);
    }
    // set ovf environment
    ArrayOfVAppPropertyInfo infos = (ArrayOfVAppPropertyInfo) props.get(// this.get.entityProp(vmTempl,
    VimPath.vm_config_vAppConfig_property);
    // VimPath.vm_config_vAppConfig_property);
    populateVAppProperties(spec, infos);
    populateCloudConfig(spec, infos);
    recordTimestamp(spec.getExtraConfig());
    // set the maximum snapshot limit if specified
    final String snapshotLimit = CustomProperties.of(this.ctx.child).getString(CustomProperties.SNAPSHOT_MAXIMUM_LIMIT);
    recordSnapshotLimit(spec.getExtraConfig(), snapshotLimit);
    // add disks one at a time
    for (VirtualDeviceConfigSpec newDisk : newDisks) {
        spec.getDeviceChange().add(newDisk);
    }
    // configure network
    VirtualPCIController pci = getFirstPciController(devices);
    for (NetworkInterfaceStateWithDetails nicWithDetails : this.ctx.nics) {
        VirtualDevice nic = createNic(nicWithDetails, pci.getControllerKey());
        addDeviceToVm(spec, nic);
    }
    // remove any networks from the template
    devices.getVirtualDevice().stream().filter(d -> VirtualEthernetCard.class.isAssignableFrom(d.getClass())).forEach(d -> addRemoveDeviceFromVm(spec, d));
    VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
    if (pbmSpec != null) {
        pbmSpec.stream().forEach(sp -> {
            relocSpec.getProfile().add(sp);
        });
    }
    relocSpec.setDatastore(datastore);
    relocSpec.setFolder(folder);
    relocSpec.setPool(resourcePool);
    relocSpec.setDiskMoveType(diskMoveOption.value());
    VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
    cloneSpec.setLocation(relocSpec);
    cloneSpec.setPowerOn(false);
    cloneSpec.setTemplate(false);
    if (snapshot != null) {
        cloneSpec.setSnapshot(snapshot.getCurrentSnapshot());
    }
    cloneSpec.setConfig(spec);
    if (bootDiskLocator != null) {
        cloneSpec.getLocation().getDisk().add(bootDiskLocator);
    }
    ManagedObjectReference cloneTask = getVimPort().cloneVMTask(vmTempl, folder, vmName, cloneSpec);
    TaskInfo info = waitTaskEnd(cloneTask);
    if (info.getState() == TaskInfoState.ERROR) {
        return VimUtils.rethrow(info.getError());
    }
    ManagedObjectReference vmMoref = (ManagedObjectReference) info.getResult();
    // Apply boot disk customization if any, if done through full clone.
    if (customizeImageDisk) {
        ArrayOfVirtualDevice virtualDevices = this.get.entityProp(vmMoref, VimPath.vm_config_hardware_device);
        reconfigureBootDisk(vmMoref, getCustomizationConfigSpecs(virtualDevices, this.imageDisks));
    }
    return vmMoref;
}
Also used : ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator) VirtualDiskSpec(com.vmware.vim25.VirtualDiskSpec) ClientUtils.fillInControllerUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.fillInControllerUnitNumber) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) ClientUtils.findFreeScsiUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeScsiUnit) VmConfigSpec(com.vmware.vim25.VmConfigSpec) ClientUtils.getFirstIdeController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstIdeController) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) Utils(com.vmware.xenon.common.Utils) Document(org.w3c.dom.Document) Map(java.util.Map) VirtualDevice(com.vmware.vim25.VirtualDevice) EnumSet(java.util.EnumSet) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) ClientUtils.createHdd(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createHdd) ClientUtils.getFirstScsiController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstScsiController) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ClientUtils.nextUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.nextUnitNumber) ClientUtils.getFirstSioController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstSioController) ClientUtils.getDatastorePathForDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastorePathForDisk) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo) VirtualMachineSnapshotInfo(com.vmware.vim25.VirtualMachineSnapshotInfo) DuplicateNameFaultMsg(com.vmware.vim25.DuplicateNameFaultMsg) ArrayUpdateOperation(com.vmware.vim25.ArrayUpdateOperation) UriUtils(com.vmware.xenon.common.UriUtils) ClientUtils.detachDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.detachDisk) VirtualFloppy(com.vmware.vim25.VirtualFloppy) ClientUtils.getStorageIOAllocationInfo(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getStorageIOAllocationInfo) Finder(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Finder) OvfDeployer(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfDeployer) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController) OptionValue(com.vmware.vim25.OptionValue) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ArrayList(java.util.ArrayList) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) VirtualCdrom(com.vmware.vim25.VirtualCdrom) STORAGE_REFERENCE(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_REFERENCE) OvfRetriever(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever) ClientUtils.getDiskProvisioningType(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskProvisioningType) DISK_DATASTORE_NAME(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_DATASTORE_NAME) VirtualMachineRelocateDiskMoveOptions(com.vmware.vim25.VirtualMachineRelocateDiskMoveOptions) InvalidCollectorVersionFaultMsg(com.vmware.vim25.InvalidCollectorVersionFaultMsg) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) DiskStatus(com.vmware.photon.controller.model.resources.DiskService.DiskStatus) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) ClientUtils.getDiskMode(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskMode) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ClientUtils.findFreeUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeUnit) ClientUtils.insertCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertCdrom) MethodFault(com.vmware.vim25.MethodFault) Lock(java.util.concurrent.locks.Lock) VirtualDisk(com.vmware.vim25.VirtualDisk) Paths(java.nio.file.Paths) InvalidNameFaultMsg(com.vmware.vim25.InvalidNameFaultMsg) ClientUtils.insertFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertFloppy) VAppPropertySpec(com.vmware.vim25.VAppPropertySpec) VirtualDiskType(com.vmware.vim25.VirtualDiskType) VirtualEthernetCardMacType(com.vmware.vim25.VirtualEthernetCardMacType) OvfParser(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser) BaseHelper(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BaseHelper) LoggerFactory(org.slf4j.LoggerFactory) ClientUtils.toKb(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.toKb) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) VAppPropertyInfo(com.vmware.vim25.VAppPropertyInfo) ClientUtils.getPbmProfileSpec(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getPbmProfileSpec) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) TaskInfo(com.vmware.vim25.TaskInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VM_PATH_FORMAT(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.VM_PATH_FORMAT) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) DuplicateName(com.vmware.vim25.DuplicateName) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayOfVAppPropertyInfo(com.vmware.vim25.ArrayOfVAppPropertyInfo) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) VirtualPCIController(com.vmware.vim25.VirtualPCIController) ClientUtils.createCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createCdrom) Entry(java.util.Map.Entry) DiskService(com.vmware.photon.controller.model.resources.DiskService) VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) FileAlreadyExists(com.vmware.vim25.FileAlreadyExists) ClientUtils.makePathToVmdkFile(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.makePathToVmdkFile) HashMap(java.util.HashMap) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualMachineCloneSpec(com.vmware.vim25.VirtualMachineCloneSpec) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) NetworkDeviceBackingFactory(com.vmware.photon.controller.model.adapters.vsphere.network.NetworkDeviceBackingFactory) ClientUtils.getDatastoreFromStoragePolicy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastoreFromStoragePolicy) Logger(org.slf4j.Logger) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ReentrantLock(java.util.concurrent.locks.ReentrantLock) VirtualE1000(com.vmware.vim25.VirtualE1000) Operation(com.vmware.xenon.common.Operation) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_CONTROLLER_NUMBER) ClientUtils.createFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createFloppy) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) DISK_PARENT_DIRECTORY(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_PARENT_DIRECTORY) TimeUnit(java.util.concurrent.TimeUnit) VirtualDeviceConfigSpecOperation(com.vmware.vim25.VirtualDeviceConfigSpecOperation) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) VirtualSCSISharing(com.vmware.vim25.VirtualSCSISharing) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) Collections(java.util.Collections) TaskInfoState(com.vmware.vim25.TaskInfoState) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) VirtualMachineSnapshotInfo(com.vmware.vim25.VirtualMachineSnapshotInfo) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) ArrayList(java.util.ArrayList) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) TaskInfo(com.vmware.vim25.TaskInfo) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) VirtualMachineRelocateDiskMoveOptions(com.vmware.vim25.VirtualMachineRelocateDiskMoveOptions) VirtualPCIController(com.vmware.vim25.VirtualPCIController) VirtualCdrom(com.vmware.vim25.VirtualCdrom) ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDevice(com.vmware.vim25.VirtualDevice) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) VirtualMachineCloneSpec(com.vmware.vim25.VirtualMachineCloneSpec) ArrayOfVAppPropertyInfo(com.vmware.vim25.ArrayOfVAppPropertyInfo) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 10 with ArrayOfVirtualDevice

use of com.vmware.vim25.ArrayOfVirtualDevice in project photon-model by vmware.

the class InstanceClient method attachDisks.

/**
 * Creates disks and attaches them to the vm created by {@link #createInstance()}. The given
 * diskStates are enriched with data from vSphere and can be patched back to xenon.
 */
public void attachDisks(List<DiskStateExpanded> diskStates, boolean isImageDisks) throws Exception {
    if (this.vm == null) {
        throw new IllegalStateException("Cannot attach diskStates if VM is not created");
    }
    EnumSet<DiskType> notSupportedTypes = EnumSet.of(DiskType.SSD, DiskType.NETWORK);
    List<DiskStateExpanded> unsupportedDisks = diskStates.stream().filter(d -> notSupportedTypes.contains(d.type)).collect(Collectors.toList());
    if (!unsupportedDisks.isEmpty()) {
        throw new IllegalStateException("Some diskStates cannot be created: " + unsupportedDisks.stream().map(d -> d.documentSelfLink).collect(Collectors.toList()));
    }
    // the path to folder holding all vm files
    String dir = this.get.entityProp(this.vm, VimPath.vm_config_files_vmPathName);
    dir = Paths.get(dir).getParent().toString();
    ArrayOfVirtualDevice devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
    VirtualSCSIController scsiController = getFirstScsiController(devices);
    // Get available free unit numbers for the given scsi controller.
    Integer[] scsiUnits = findFreeScsiUnit(scsiController, devices.getVirtualDevice());
    VirtualDevice ideController = getFirstIdeController(devices);
    int ideUnit = findFreeUnit(ideController, devices.getVirtualDevice());
    VirtualDevice sioController = getFirstSioController(devices);
    int sioUnit = findFreeUnit(sioController, devices.getVirtualDevice());
    List<VirtualDeviceConfigSpec> newDisks = new ArrayList<>();
    boolean cdromAdded = false;
    List<DiskStateExpanded> disksToBeCustomized = null;
    int scsiUnitIndex = 0;
    for (DiskStateExpanded ds : diskStates) {
        String diskPath = VimUtils.uriToDatastorePath(ds.sourceImageReference);
        if (ds.type == DiskType.HDD) {
            // Find if there is a storage policy defined for this disk
            List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(ds);
            VirtualDeviceConfigSpec hdd;
            if (diskPath != null) {
                // create full clone of given disk
                hdd = createFullCloneAndAttach(diskPath, ds, dir, scsiController, scsiUnits[scsiUnitIndex], pbmSpec);
                newDisks.add(hdd);
                // When it is through clone, customize after the clone is complete.
                if (disksToBeCustomized == null) {
                    disksToBeCustomized = new ArrayList<>(diskStates.size());
                }
                if (isImageDisks) {
                    disksToBeCustomized.add(ds);
                }
            } else {
                String dsDirForDisk = getDatastorePathForDisk(ds, dir);
                String diskName = makePathToVmdkFile(ds.name, dsDirForDisk);
                hdd = createHdd(scsiController.getKey(), scsiUnits[scsiUnitIndex], ds, diskName, getDataStoreForDisk(ds, pbmSpec), pbmSpec);
                newDisks.add(hdd);
            }
            scsiUnitIndex++;
        }
        if (ds.type == DiskType.CDROM) {
            VirtualDeviceConfigSpec cdrom = createCdrom(ideController, ideUnit);
            fillInControllerUnitNumber(ds, ideUnit);
            ideUnit = nextUnitNumber(ideUnit);
            if (diskPath != null) {
                // mount iso image
                insertCdrom((VirtualCdrom) cdrom.getDevice(), diskPath);
            }
            newDisks.add(cdrom);
            cdromAdded = true;
        }
        if (ds.type == DiskType.FLOPPY) {
            VirtualDeviceConfigSpec floppy = createFloppy(sioController, sioUnit);
            fillInControllerUnitNumber(ds, sioUnit);
            sioUnit = nextUnitNumber(sioUnit);
            if (diskPath != null) {
                // mount iso image
                insertFloppy((VirtualFloppy) floppy.getDevice(), diskPath);
            }
            newDisks.add(floppy);
        }
        // mark disk as attached
        ds.status = DiskStatus.ATTACHED;
    }
    // add a cdrom so that ovf transport works
    if (!cdromAdded && isImageDisks) {
        VirtualDeviceConfigSpec cdrom = createCdrom(ideController, ideUnit);
        newDisks.add(cdrom);
    }
    // add disks one at a time
    for (VirtualDeviceConfigSpec newDisk : newDisks) {
        VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
        spec.getDeviceChange().add(newDisk);
        ManagedObjectReference reconfigureTask = getVimPort().reconfigVMTask(this.vm, spec);
        TaskInfo info = waitTaskEnd(reconfigureTask);
        if (info.getState() == TaskInfoState.ERROR) {
            VimUtils.rethrow(info.getError());
        }
    }
    // If disks are created through full clone, then reconfigure
    if (disksToBeCustomized != null && !disksToBeCustomized.isEmpty()) {
        // Get the hardware devices once again as they are reconfigured
        devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
        reconfigureBootDisk(this.vm, getCustomizationConfigSpecs(devices, disksToBeCustomized));
    }
}
Also used : ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator) VirtualDiskSpec(com.vmware.vim25.VirtualDiskSpec) ClientUtils.fillInControllerUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.fillInControllerUnitNumber) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) ClientUtils.findFreeScsiUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeScsiUnit) VmConfigSpec(com.vmware.vim25.VmConfigSpec) ClientUtils.getFirstIdeController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstIdeController) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) Utils(com.vmware.xenon.common.Utils) Document(org.w3c.dom.Document) Map(java.util.Map) VirtualDevice(com.vmware.vim25.VirtualDevice) EnumSet(java.util.EnumSet) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) ClientUtils.createHdd(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createHdd) ClientUtils.getFirstScsiController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstScsiController) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ClientUtils.nextUnitNumber(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.nextUnitNumber) ClientUtils.getFirstSioController(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getFirstSioController) ClientUtils.getDatastorePathForDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastorePathForDisk) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo) VirtualMachineSnapshotInfo(com.vmware.vim25.VirtualMachineSnapshotInfo) DuplicateNameFaultMsg(com.vmware.vim25.DuplicateNameFaultMsg) ArrayUpdateOperation(com.vmware.vim25.ArrayUpdateOperation) UriUtils(com.vmware.xenon.common.UriUtils) ClientUtils.detachDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.detachDisk) VirtualFloppy(com.vmware.vim25.VirtualFloppy) ClientUtils.getStorageIOAllocationInfo(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getStorageIOAllocationInfo) Finder(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Finder) OvfDeployer(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfDeployer) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController) OptionValue(com.vmware.vim25.OptionValue) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ArrayList(java.util.ArrayList) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) VirtualCdrom(com.vmware.vim25.VirtualCdrom) STORAGE_REFERENCE(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_REFERENCE) OvfRetriever(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfRetriever) ClientUtils.getDiskProvisioningType(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskProvisioningType) DISK_DATASTORE_NAME(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_DATASTORE_NAME) VirtualMachineRelocateDiskMoveOptions(com.vmware.vim25.VirtualMachineRelocateDiskMoveOptions) InvalidCollectorVersionFaultMsg(com.vmware.vim25.InvalidCollectorVersionFaultMsg) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) DiskStatus(com.vmware.photon.controller.model.resources.DiskService.DiskStatus) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) ClientUtils.getDiskMode(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDiskMode) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ClientUtils.findFreeUnit(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findFreeUnit) ClientUtils.insertCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertCdrom) MethodFault(com.vmware.vim25.MethodFault) Lock(java.util.concurrent.locks.Lock) VirtualDisk(com.vmware.vim25.VirtualDisk) Paths(java.nio.file.Paths) InvalidNameFaultMsg(com.vmware.vim25.InvalidNameFaultMsg) ClientUtils.insertFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.insertFloppy) VAppPropertySpec(com.vmware.vim25.VAppPropertySpec) VirtualDiskType(com.vmware.vim25.VirtualDiskType) VirtualEthernetCardMacType(com.vmware.vim25.VirtualEthernetCardMacType) OvfParser(com.vmware.photon.controller.model.adapters.vsphere.ovf.OvfParser) BaseHelper(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BaseHelper) LoggerFactory(org.slf4j.LoggerFactory) ClientUtils.toKb(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.toKb) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) VAppPropertyInfo(com.vmware.vim25.VAppPropertyInfo) ClientUtils.getPbmProfileSpec(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getPbmProfileSpec) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) TaskInfo(com.vmware.vim25.TaskInfo) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VM_PATH_FORMAT(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.VM_PATH_FORMAT) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) DuplicateName(com.vmware.vim25.DuplicateName) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayOfVAppPropertyInfo(com.vmware.vim25.ArrayOfVAppPropertyInfo) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) VirtualPCIController(com.vmware.vim25.VirtualPCIController) ClientUtils.createCdrom(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createCdrom) Entry(java.util.Map.Entry) DiskService(com.vmware.photon.controller.model.resources.DiskService) VimPath(com.vmware.photon.controller.model.adapters.vsphere.util.VimPath) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) FileAlreadyExists(com.vmware.vim25.FileAlreadyExists) ClientUtils.makePathToVmdkFile(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.makePathToVmdkFile) HashMap(java.util.HashMap) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualMachineCloneSpec(com.vmware.vim25.VirtualMachineCloneSpec) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) NetworkDeviceBackingFactory(com.vmware.photon.controller.model.adapters.vsphere.network.NetworkDeviceBackingFactory) ClientUtils.getDatastoreFromStoragePolicy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getDatastoreFromStoragePolicy) Logger(org.slf4j.Logger) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ReentrantLock(java.util.concurrent.locks.ReentrantLock) VirtualE1000(com.vmware.vim25.VirtualE1000) Operation(com.vmware.xenon.common.Operation) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_CONTROLLER_NUMBER) ClientUtils.createFloppy(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.createFloppy) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) NetworkInterfaceStateWithDetails(com.vmware.photon.controller.model.adapters.vsphere.ProvisionContext.NetworkInterfaceStateWithDetails) DISK_PARENT_DIRECTORY(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_PARENT_DIRECTORY) TimeUnit(java.util.concurrent.TimeUnit) VirtualDeviceConfigSpecOperation(com.vmware.vim25.VirtualDeviceConfigSpecOperation) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) VirtualSCSISharing(com.vmware.vim25.VirtualSCSISharing) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) Collections(java.util.Collections) TaskInfoState(com.vmware.vim25.TaskInfoState) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayList(java.util.ArrayList) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) VirtualDiskType(com.vmware.vim25.VirtualDiskType) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) TaskInfo(com.vmware.vim25.TaskInfo) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ArrayOfVirtualDevice (com.vmware.vim25.ArrayOfVirtualDevice)14 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)12 VirtualDisk (com.vmware.vim25.VirtualDisk)11 URI (java.net.URI)10 HashMap (java.util.HashMap)10 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)9 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 DiskService (com.vmware.photon.controller.model.resources.DiskService)9 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)9 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)9 VirtualDevice (com.vmware.vim25.VirtualDevice)9 VirtualDiskType (com.vmware.vim25.VirtualDiskType)9 Operation (com.vmware.xenon.common.Operation)9 UriUtils (com.vmware.xenon.common.UriUtils)9 Utils (com.vmware.xenon.common.Utils)9 ClientUtils.findMatchingVirtualDevice (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice)8 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)8 DiskStateExpanded (com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded)8 TaskInfo (com.vmware.vim25.TaskInfo)8 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)8