Search in sources :

Example 1 with ArrayOfVirtualDevice

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

the class ClientUtils method attachDiskToVM.

public static String attachDiskToVM(ArrayOfVirtualDevice devices, ManagedObjectReference vm, DiskService.DiskStateExpanded diskState, ManagedObjectReference diskDatastore, Connection connection, VimPortType vimPort) throws Exception {
    String diskPath = VimUtils.uriToDatastorePath(diskState.sourceImageReference);
    String diskFullPath = CustomProperties.of(diskState).getString(DISK_FULL_PATH, null);
    Boolean insertCdRom = CustomProperties.of(diskState).getBoolean(INSERT_CDROM, false);
    VirtualDeviceConfigSpec deviceConfigSpec = null;
    if (diskState.type == DiskService.DiskType.HDD) {
        VirtualSCSIController scsiController = getFirstScsiController(devices);
        // Get available free unit numbers for the given scsi controller.
        Integer[] scsiUnits = findFreeScsiUnit(scsiController, devices.getVirtualDevice());
        List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(diskState);
        deviceConfigSpec = createHdd(scsiController.getKey(), scsiUnits[0], diskState, diskFullPath, diskDatastore, pbmSpec, false);
    } else if (diskState.type == DiskService.DiskType.CDROM) {
        if (insertCdRom) {
            if (diskPath == null) {
                throw new IllegalStateException(String.format("Cannot insert empty iso file into CD-ROM"));
            }
            // Find first available CD ROM to insert the iso file
            VirtualCdrom cdrom = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualCdrom).map(d -> (VirtualCdrom) d).findFirst().orElse(null);
            if (cdrom == null) {
                throw new IllegalStateException(String.format("Could not find Virtual CD ROM to insert %s.", diskPath));
            }
            insertCdrom(cdrom, diskPath);
            deviceConfigSpec = new VirtualDeviceConfigSpec();
            deviceConfigSpec.setDevice(cdrom);
            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
        } else {
            VirtualDevice ideController = getFirstIdeController(devices);
            int ideUnit = findFreeUnit(ideController, devices.getVirtualDevice());
            int availableUnitNumber = nextUnitNumber(ideUnit);
            deviceConfigSpec = createCdrom(ideController, availableUnitNumber);
            fillInControllerUnitNumber(diskState, availableUnitNumber);
            if (diskPath != null) {
                // mount iso image
                insertCdrom((VirtualCdrom) deviceConfigSpec.getDevice(), diskPath);
            }
            // Live add of cd-rom is not possible. Hence it needs to be powered off
            // Power off is needed to ADD cd-rom
            powerOffVm(connection, vimPort, vm);
        }
    } else if (diskState.type == DiskService.DiskType.FLOPPY) {
        VirtualDevice sioController = getFirstSioController(devices);
        int sioUnit = findFreeUnit(sioController, devices.getVirtualDevice());
        int availableUnitNumber = nextUnitNumber(sioUnit);
        deviceConfigSpec = createFloppy(sioController, availableUnitNumber);
        fillInControllerUnitNumber(diskState, availableUnitNumber);
        if (diskPath != null) {
            insertFloppy((VirtualFloppy) deviceConfigSpec.getDevice(), diskPath);
        }
        // Power off is needed to ADD floppy
        powerOffVm(connection, vimPort, vm);
    }
    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    spec.getDeviceChange().add(deviceConfigSpec);
    ManagedObjectReference reconfigureTask = vimPort.reconfigVMTask(vm, spec);
    TaskInfo info = VimUtils.waitTaskEnd(connection, reconfigureTask);
    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }
    if (!insertCdRom && diskState.type != DiskService.DiskType.HDD) {
        // This means it is CDROM or Floppy. Hence power on the VM as it is powered off to
        // perform the operation
        powerOnVM(connection, vimPort, vm);
    }
    return diskFullPath;
}
Also used : PbmPlacementHub(com.vmware.pbm.PbmPlacementHub) SSLContext(javax.net.ssl.SSLContext) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) InvalidDatastoreFaultMsg(com.vmware.vim25.InvalidDatastoreFaultMsg) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) StringUtils(org.apache.commons.lang3.StringUtils) FileNotFoundFaultMsg(com.vmware.vim25.FileNotFoundFaultMsg) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) PbmProfileId(com.vmware.pbm.PbmProfileId) VirtualDeviceConfigSpecFileOperation(com.vmware.vim25.VirtualDeviceConfigSpecFileOperation) VimPortType(com.vmware.vim25.VimPortType) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) VirtualDevice(com.vmware.vim25.VirtualDevice) EnumSet(java.util.EnumSet) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) VirtualDiskFlatVer1BackingInfo(com.vmware.vim25.VirtualDiskFlatVer1BackingInfo) LIMIT_IOPS(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.LIMIT_IOPS) GregorianCalendar(java.util.GregorianCalendar) KeyManagementException(java.security.KeyManagementException) ServiceClient(com.vmware.xenon.common.ServiceClient) Executors(java.util.concurrent.Executors) NettyHttpServiceClient(com.vmware.xenon.common.http.netty.NettyHttpServiceClient) PERSISTENT(com.vmware.vim25.VirtualDiskMode.PERSISTENT) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UriUtils(com.vmware.xenon.common.UriUtils) VirtualFloppy(com.vmware.vim25.VirtualFloppy) Finder(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Finder) INSERT_CDROM(com.vmware.photon.controller.model.constants.PhotonModelConstants.INSERT_CDROM) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) VirtualCdromAtapiBackingInfo(com.vmware.vim25.VirtualCdromAtapiBackingInfo) ArrayList(java.util.ArrayList) VirtualCdrom(com.vmware.vim25.VirtualCdrom) DISK_FULL_PATH(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_FULL_PATH) Calendar(java.util.Calendar) DEVICE_STATUS(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DEVICE_STATUS) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualDisk(com.vmware.vim25.VirtualDisk) Paths(java.nio.file.Paths) SHARES_LEVEL(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.SHARES_LEVEL) X509TrustManager(javax.net.ssl.X509TrustManager) StorageIOAllocationInfo(com.vmware.vim25.StorageIOAllocationInfo) VirtualDiskType(com.vmware.vim25.VirtualDiskType) Service(com.vmware.xenon.common.Service) SHARES(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.SHARES) URISyntaxException(java.net.URISyntaxException) QueryTask(com.vmware.xenon.services.common.QueryTask) LoggerFactory(org.slf4j.LoggerFactory) TrustManager(javax.net.ssl.TrustManager) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) VirtualDeviceFileBackingInfo(com.vmware.vim25.VirtualDeviceFileBackingInfo) 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) SharesInfo(com.vmware.vim25.SharesInfo) VirtualCdromIsoBackingInfo(com.vmware.vim25.VirtualCdromIsoBackingInfo) DiskStateExpanded(com.vmware.photon.controller.model.resources.DiskService.DiskStateExpanded) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) Objects(java.util.Objects) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) PROVISION_TYPE(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVISION_TYPE) DiskService(com.vmware.photon.controller.model.resources.DiskService) DISK_MODE_INDEPENDENT(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_MODE_INDEPENDENT) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) HashMap(java.util.HashMap) DISK_MODE_PERSISTENT(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_MODE_PERSISTENT) Level(java.util.logging.Level) DEVICE_CONNECTED(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DEVICE_CONNECTED) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) InvalidDatastorePathFaultMsg(com.vmware.vim25.InvalidDatastorePathFaultMsg) SharesLevel(com.vmware.vim25.SharesLevel) Logger(org.slf4j.Logger) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) VirtualIDEController(com.vmware.vim25.VirtualIDEController) VirtualFloppyDeviceBackingInfo(com.vmware.vim25.VirtualFloppyDeviceBackingInfo) Operation(com.vmware.xenon.common.Operation) PbmFaultFaultMsg(com.vmware.pbm.PbmFaultFaultMsg) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.DISK_CONTROLLER_NUMBER) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualDiskMode(com.vmware.vim25.VirtualDiskMode) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) Consumer(java.util.function.Consumer) VirtualDeviceConfigSpecOperation(com.vmware.vim25.VirtualDeviceConfigSpecOperation) VirtualFloppyImageBackingInfo(com.vmware.vim25.VirtualFloppyImageBackingInfo) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) VirtualSIOController(com.vmware.vim25.VirtualSIOController) VIRTUAL_MACHINE_LINK(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.VIRTUAL_MACHINE_LINK) TaskInfoState(com.vmware.vim25.TaskInfoState) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualCdrom(com.vmware.vim25.VirtualCdrom) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualMachineDefinedProfileSpec(com.vmware.vim25.VirtualMachineDefinedProfileSpec) TaskInfo(com.vmware.vim25.TaskInfo) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with ArrayOfVirtualDevice

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

the class InstanceDiskClient method detachDiskFromVM.

public void detachDiskFromVM() throws Exception {
    ArrayOfVirtualDevice devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
    VirtualDisk vd = (VirtualDisk) findMatchingVirtualDevice(getListOfVirtualDisk(devices), this.diskState);
    if (vd == null) {
        throw new IllegalStateException(String.format("Matching Virtual Disk is not for disk %s.", this.diskState.documentSelfLink));
    }
    // Detach the disk from VM.
    detachDisk(this.connection, vd, this.vm, getVimPort());
}
Also used : ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) VirtualDisk(com.vmware.vim25.VirtualDisk) ClientUtils.updateDiskStateFromVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.updateDiskStateFromVirtualDisk)

Example 3 with ArrayOfVirtualDevice

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

the class InstanceDiskClient method attachDiskToVM.

public DiskService.DiskState attachDiskToVM() throws Exception {
    ArrayOfVirtualDevice devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
    String diskDatastoreName = CustomProperties.of(this.diskState).getString(DISK_DATASTORE_NAME);
    ManagedObjectReference diskDsMoref = null;
    if (diskDatastoreName != null) {
        diskDsMoref = this.finder.datastore(diskDatastoreName).object;
    }
    String diskFullPath = ClientUtils.attachDiskToVM(devices, this.vm, this.diskState, diskDsMoref, this.connection, this.getVimPort());
    devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
    // Update the diskState
    if (this.diskState.type == DiskService.DiskType.HDD) {
        this.diskState.sourceImageReference = VimUtils.datastorePathToUri(diskFullPath);
        VirtualDisk vd = (VirtualDisk) findMatchingVirtualDevice(getListOfVirtualDisk(devices), this.diskState);
        if (vd != null) {
            updateDiskStateFromVirtualDisk(vd, this.diskState);
        }
    } else if (this.diskState.type == DiskService.DiskType.CDROM) {
        Boolean insertCdRom = CustomProperties.of(this.diskState).getBoolean(INSERT_CDROM, false);
        VirtualDevice virtualDevice = findMatchingVirtualDevice(getListOfVirtualCdRom(devices), this.diskState);
        if (virtualDevice != null) {
            if (insertCdRom) {
                DiskService.DiskStateExpanded matchedDs = findMatchingDiskState(virtualDevice, this.context.computeDiskStates);
                if (matchedDs.customProperties == null) {
                    matchedDs.customProperties = new HashMap<>();
                }
                matchedDs.customProperties.putAll(this.diskState.customProperties);
                updateDiskStateFromVirtualDevice(virtualDevice, matchedDs, virtualDevice.getBacking(), CustomProperties.of(this.diskState).getString(CustomProperties.DATACENTER_SELF_LINK));
                CustomProperties.of(matchedDs).put(TEMPLATE_DISK_LINK, this.diskState.documentSelfLink);
                return matchedDs;
            } else {
                updateDiskStateFromVirtualDevice(virtualDevice, this.diskState, virtualDevice.getBacking(), CustomProperties.of(this.diskState).getString(CustomProperties.DATACENTER_SELF_LINK));
            }
        }
    } else {
        // This would be Floppy
        VirtualDevice virtualDevice = findMatchingVirtualDevice(getListOfVirtualFloppy(devices), this.diskState);
        if (virtualDevice != null) {
            updateDiskStateFromVirtualDevice(virtualDevice, this.diskState, virtualDevice.getBacking(), CustomProperties.of(this.diskState).getString(CustomProperties.DATACENTER_SELF_LINK));
        }
    }
    return this.diskState;
}
Also used : HashMap(java.util.HashMap) ClientUtils.findMatchingVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.findMatchingVirtualDevice) ClientUtils.updateDiskStateFromVirtualDevice(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.updateDiskStateFromVirtualDevice) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayOfVirtualDevice(com.vmware.vim25.ArrayOfVirtualDevice) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk) VirtualDisk(com.vmware.vim25.VirtualDisk) ClientUtils.updateDiskStateFromVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.updateDiskStateFromVirtualDisk) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with ArrayOfVirtualDevice

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

the class InstanceClient method customizeAfterClone.

private void customizeAfterClone() throws Exception {
    VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
    // is takes precedence
    if (this.ctx.child.description.cpuCount > 0) {
        spec.setNumCPUs((int) this.ctx.child.description.cpuCount);
    }
    String gt = CustomProperties.of(this.ctx.child).getString(CustomProperties.GUEST_ID, null);
    if (gt != null) {
        spec.setGuestId(gt);
    }
    if (this.ctx.child.description.totalMemoryBytes > 0) {
        spec.setMemoryMB(toMemoryMb(this.ctx.child.description.totalMemoryBytes));
    }
    recordTimestamp(spec.getExtraConfig());
    // set ovf environment
    ArrayOfVAppPropertyInfo infos = this.get.entityProp(this.vm, VimPath.vm_config_vAppConfig_property);
    populateCloudConfig(spec, infos);
    // remove nics and attach to proper networks if nics are configured
    ArrayOfVirtualDevice devices = null;
    if (this.ctx.nics != null && this.ctx.nics.size() > 0) {
        devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
        devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualEthernetCard).forEach(nic -> {
            VirtualDeviceConfigSpec removeNicChange = new VirtualDeviceConfigSpec();
            removeNicChange.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
            removeNicChange.setDevice(nic);
            spec.getDeviceChange().add(removeNicChange);
        });
        for (NetworkInterfaceStateWithDetails niState : this.ctx.nics) {
            VirtualDevice nic = createNic(niState, null);
            addDeviceToVm(spec, nic);
        }
    }
    // Find whether it has HDD disk
    if (this.imageDisks != null && !this.imageDisks.isEmpty()) {
        // Iterate over each of the VirtualDisk and reconfigure if needed
        if (devices == null) {
            devices = this.get.entityProp(this.vm, VimPath.vm_config_hardware_device);
        }
        spec.getDeviceChange().addAll(getCustomizationConfigSpecs(devices, this.imageDisks));
    }
    // set the maximum snapshot limit if specified
    final String snapshotLimit = CustomProperties.of(this.ctx.child).getString(CustomProperties.SNAPSHOT_MAXIMUM_LIMIT);
    recordSnapshotLimit(spec.getExtraConfig(), snapshotLimit);
    ManagedObjectReference task = getVimPort().reconfigVMTask(this.vm, spec);
    TaskInfo info = waitTaskEnd(task);
    if (info.getState() == TaskInfoState.ERROR) {
        VimUtils.rethrow(info.getError());
    }
    // If there are any data disks then attach then to the VM
    if (this.dataDisks != null && !this.dataDisks.isEmpty()) {
        attachDisks(this.dataDisks, false);
    }
    // If there are any external disks, then attach then to the VM
    attachExternalDisks();
}
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) TaskInfo(com.vmware.vim25.TaskInfo) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) 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) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard) ArrayOfVAppPropertyInfo(com.vmware.vim25.ArrayOfVAppPropertyInfo) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with ArrayOfVirtualDevice

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

the class InstanceClient method getCustomizationConfigSpecs.

/**
 * Get customization config spec for all the image disks if any
 */
private List<VirtualDeviceConfigSpec> getCustomizationConfigSpecs(ArrayOfVirtualDevice devices, List<DiskStateExpanded> diskStates) throws FinderException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    List<VirtualDeviceConfigSpec> specs = new ArrayList<>();
    List<VirtualDisk> virtualDisks = devices.getVirtualDevice().stream().filter(d -> d instanceof VirtualDisk).map(d -> (VirtualDisk) d).collect(Collectors.toList());
    for (VirtualDisk vd : virtualDisks) {
        VirtualDeviceConfigSpec diskSpec = getBootDiskCustomizeConfigSpec(findMatchingImageDiskState(vd, diskStates), vd);
        if (diskSpec != null) {
            specs.add(diskSpec);
        }
    }
    return specs;
}
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) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) ArrayList(java.util.ArrayList) VirtualDisk(com.vmware.vim25.VirtualDisk) ClientUtils.getListOfVirtualDisk(com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk)

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