Search in sources :

Example 1 with VirtualDiskType

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

the class TestVSphereOvfProvisionTaskBase method deployOvfAndReturnComputeState.

private ComputeService.ComputeState deployOvfAndReturnComputeState(boolean isStoragePolicyBased, boolean withAdditionalDisks, Map<String, String> customProperties, boolean isSnapshotLimitCase) throws Throwable {
    ComputeService.ComputeState vm = null;
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    ComputeDescriptionService.ComputeDescription computeDesc = createTemplate();
    ImportOvfRequest req = new ImportOvfRequest();
    req.ovfUri = this.ovfUri;
    req.template = computeDesc;
    Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
    CompletableFuture<Operation> f = this.host.sendWithFuture(op);
    // depending on OVF location you may want to increase the timeout
    f.get(360, TimeUnit.SECONDS);
    snapshotFactoryState("ovf", ComputeDescriptionService.class);
    enumerateComputes(this.computeHost);
    String descriptionLink = findFirstOvfDescriptionLink();
    this.bootDisk = createBootDiskWithCustomProperties(CLOUD_CONFIG_DATA, isStoragePolicyBased, customProperties);
    vm = createVmState(descriptionLink, withAdditionalDisks, customProperties, isSnapshotLimitCase);
    // set timeout for the next step, vmdk upload may take some time
    host.setTimeoutSeconds(60 * 5);
    // provision
    ProvisionComputeTaskService.ProvisionComputeTaskState outTask = createProvisionTask(vm);
    awaitTaskEnd(outTask);
    vm = getComputeState(vm);
    snapshotFactoryState("ovf", ComputeService.class);
    if (!isMock() && withAdditionalDisks || customProperties.get(PROVISION_TYPE) != null) {
        BasicConnection connection = createConnection();
        GetMoRef get = new GetMoRef(connection);
        List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
        if (customProperties.get(PROVISION_TYPE) != null) {
            VirtualDiskType diskProvisionType = VirtualDiskType.fromValue(customProperties.get(PROVISION_TYPE));
            VirtualDisk bootDisk = virtualDisks.stream().filter(vd -> vd.getUnitNumber() == 0).findFirst().orElse(null);
            VirtualDiskFlatVer2BackingInfo backing = (VirtualDiskFlatVer2BackingInfo) bootDisk.getBacking();
            if (VirtualDiskType.THIN == diskProvisionType) {
                assertTrue(backing.isThinProvisioned());
            } else if (VirtualDiskType.THICK == diskProvisionType) {
                assertFalse(backing.isThinProvisioned());
            } else if (VirtualDiskType.EAGER_ZEROED_THICK == diskProvisionType) {
                assertFalse(backing.isThinProvisioned());
                assertTrue(backing.isEagerlyScrub());
            }
        }
        if (withAdditionalDisks) {
            assertEquals(3, virtualDisks.size());
        }
    }
    return vm;
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) VirtualDiskType(com.vmware.vim25.VirtualDiskType) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) Operation(com.vmware.xenon.common.Operation) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ImportOvfRequest(com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)

Example 2 with VirtualDiskType

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

the class TestVSphereOvfProvisionTaskBase method buildBootDiskWithCustomProperties.

private DiskService.DiskState buildBootDiskWithCustomProperties(String cloudConfig, Map<String, String> customProperties) throws Throwable {
    HashMap<String, String> diskCustomProperties = new HashMap<>();
    VirtualDiskType diskProvisionType = customProperties.get(PROVISION_TYPE) != null ? VirtualDiskType.fromValue(customProperties.get(PROVISION_TYPE)) : null;
    if (diskProvisionType == null) {
        diskProvisionType = VirtualDiskType.THIN;
    }
    diskCustomProperties.put(DISK_MODE_PERSISTENT, "true");
    diskCustomProperties.put(PROVISION_TYPE, diskProvisionType.value());
    diskCustomProperties.put(SHARES_LEVEL, SharesLevel.HIGH.value());
    diskCustomProperties.put(LIMIT_IOPS, "100");
    DiskService.DiskState res = buildBootDisk(cloudConfig);
    res.customProperties = diskCustomProperties;
    return res;
}
Also used : HashMap(java.util.HashMap) VirtualDiskType(com.vmware.vim25.VirtualDiskType) DiskService(com.vmware.photon.controller.model.resources.DiskService)

Example 3 with VirtualDiskType

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

the class InstanceClient method setProvisioningType.

private VirtualMachineRelocateSpecDiskLocator setProvisioningType(VirtualDisk vDisk, ManagedObjectReference datastore, List<VirtualMachineDefinedProfileSpec> pbmSpec) throws InvalidPropertyFaultMsg, FinderException, RuntimeFaultFaultMsg {
    if (vDisk == null) {
        return null;
    }
    // datastore from that.
    if (datastore == null) {
        ManagedObjectReference dsFromSp = getDatastoreFromStoragePolicy(this.connection, pbmSpec);
        datastore = dsFromSp == null ? getDatastore() : dsFromSp;
    }
    VirtualDiskFlatVer2BackingInfo flatBacking = (VirtualDiskFlatVer2BackingInfo) vDisk.getBacking();
    VirtualDiskType provisioningType = getDiskProvisioningType(this.bootDisk);
    boolean wasThinProvision = flatBacking.isThinProvisioned();
    Boolean wasEagerScrubbed = flatBacking.isEagerlyScrub() != null ? flatBacking.isEagerlyScrub() : false;
    if (provisioningType != null) {
        flatBacking.setThinProvisioned(provisioningType == VirtualDiskType.THIN);
        flatBacking.setEagerlyScrub(provisioningType == VirtualDiskType.EAGER_ZEROED_THICK);
    }
    VirtualMachineRelocateSpecDiskLocator diskLocator = new VirtualMachineRelocateSpecDiskLocator();
    diskLocator.setDiskId(vDisk.getKey());
    diskLocator.setDiskBackingInfo(flatBacking);
    diskLocator.setDatastore(datastore);
    Boolean isEagerScrub = flatBacking.isEagerlyScrub() != null ? flatBacking.isEagerlyScrub() : false;
    // to MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING
    if (wasThinProvision != flatBacking.isThinProvisioned() || !wasEagerScrubbed.equals(isEagerScrub)) {
        diskLocator.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.value());
    }
    return diskLocator;
}
Also used : VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDiskType(com.vmware.vim25.VirtualDiskType) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualMachineRelocateSpecDiskLocator(com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator)

Example 4 with VirtualDiskType

use of com.vmware.vim25.VirtualDiskType in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method createDisk.

// vmdkDatastorePath: [datastore name] vmdkFilePath
public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, VirtualDiskMode diskMode, String rdmDeviceName, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: " + vmdkDatastorePath + ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName + ", datastore: " + morDs.get_value() + ", controllerKey: " + controllerKey);
    assert (vmdkDatastorePath != null);
    assert (morDs != null);
    if (controllerKey < 0) {
        controllerKey = getIDEDeviceControllerKey();
    }
    VirtualDisk newDisk = new VirtualDisk();
    if (diskType == VirtualDiskType.thin || diskType == VirtualDiskType.preallocated || diskType == VirtualDiskType.eagerZeroedThick) {
        VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
        backingInfo.setDiskMode(diskMode.persistent.toString());
        if (diskType == VirtualDiskType.thin) {
            backingInfo.setThinProvisioned(true);
        } else {
            backingInfo.setThinProvisioned(false);
        }
        if (diskType == VirtualDiskType.eagerZeroedThick) {
            backingInfo.setEagerlyScrub(true);
        } else {
            backingInfo.setEagerlyScrub(false);
        }
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        newDisk.setBacking(backingInfo);
    } else if (diskType == VirtualDiskType.rdm || diskType == VirtualDiskType.rdmp) {
        VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
        if (diskType == VirtualDiskType.rdm) {
            backingInfo.setCompatibilityMode("virtualMode");
        } else {
            backingInfo.setCompatibilityMode("physicalMode");
        }
        backingInfo.setDeviceName(rdmDeviceName);
        if (diskType == VirtualDiskType.rdm) {
            backingInfo.setDiskMode(diskMode.persistent.toString());
        }
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        newDisk.setBacking(backingInfo);
    }
    int deviceNumber = getNextDeviceNumber(controllerKey);
    newDisk.setControllerKey(controllerKey);
    newDisk.setKey(-deviceNumber);
    newDisk.setUnitNumber(deviceNumber);
    newDisk.setCapacityInKB(sizeInMb * 1024);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(newDisk);
    deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
    deviceConfigSpecArray[0] = deviceConfigSpec;
    reConfigSpec.setDeviceChange(deviceConfigSpecArray);
    ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (!result.equals("sucess")) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - createDisk() done(failed)");
        throw new Exception("Unable to create disk " + vmdkDatastorePath + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    _context.waitForTaskProgressDone(morTask);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createDisk() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with VirtualDiskType

use of com.vmware.vim25.VirtualDiskType in project cloudstack by apache.

the class VirtualMachineMO method createDisk.

// vmdkDatastorePath: [datastore name] vmdkFilePath
public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, VirtualDiskMode diskMode, String rdmDeviceName, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " + vmdkDatastorePath + ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName + ", datastore: " + morDs.getValue() + ", controllerKey: " + controllerKey);
    assert (vmdkDatastorePath != null);
    assert (morDs != null);
    int ideControllerKey = getIDEDeviceControllerKey();
    if (controllerKey < 0) {
        controllerKey = ideControllerKey;
    }
    VirtualDisk newDisk = new VirtualDisk();
    if (diskType == VirtualDiskType.THIN || diskType == VirtualDiskType.PREALLOCATED || diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
        VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
        backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
        if (diskType == VirtualDiskType.THIN) {
            backingInfo.setThinProvisioned(true);
        } else {
            backingInfo.setThinProvisioned(false);
        }
        if (diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
            backingInfo.setEagerlyScrub(true);
        } else {
            backingInfo.setEagerlyScrub(false);
        }
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        newDisk.setBacking(backingInfo);
    } else if (diskType == VirtualDiskType.RDM || diskType == VirtualDiskType.RDMP) {
        VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
        if (diskType == VirtualDiskType.RDM) {
            backingInfo.setCompatibilityMode("virtualMode");
        } else {
            backingInfo.setCompatibilityMode("physicalMode");
        }
        backingInfo.setDeviceName(rdmDeviceName);
        if (diskType == VirtualDiskType.RDM) {
            backingInfo.setDiskMode(VirtualDiskMode.PERSISTENT.value());
        }
        backingInfo.setDatastore(morDs);
        backingInfo.setFileName(vmdkDatastorePath);
        newDisk.setBacking(backingInfo);
    }
    int deviceNumber = getNextDeviceNumber(controllerKey);
    newDisk.setControllerKey(controllerKey);
    newDisk.setKey(-deviceNumber);
    newDisk.setUnitNumber(deviceNumber);
    newDisk.setCapacityInKB(sizeInMb * 1024);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(newDisk);
    deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (!result) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - createDisk() done(failed)");
        throw new Exception("Unable to create disk " + vmdkDatastorePath + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    _context.waitForTaskProgressDone(morTask);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createDisk() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDiskRawDiskMappingVer1BackingInfo(com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)8 VirtualDiskType (com.vmware.vim25.VirtualDiskType)7 VirtualDisk (com.vmware.vim25.VirtualDisk)6 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)5 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)5 VirtualDiskRawDiskMappingVer1BackingInfo (com.vmware.vim25.VirtualDiskRawDiskMappingVer1BackingInfo)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ClientUtils.getListOfVirtualDisk (com.vmware.photon.controller.model.adapters.vsphere.ClientUtils.getListOfVirtualDisk)1 ImportOvfRequest (com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)1 BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)1 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)1 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)1 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)1 DiskService (com.vmware.photon.controller.model.resources.DiskService)1 ProvisionComputeTaskService (com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService)1 FileBackedVirtualDiskSpec (com.vmware.vim25.FileBackedVirtualDiskSpec)1 TaskInfo (com.vmware.vim25.TaskInfo)1