Search in sources :

Example 1 with VmConfigInfo

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

the class VmwareResource method setVAppPropertiesToConfigSpec.

/**
 * Set the vApp configuration to vmConfig spec, copying existing configuration from vAppConfig
 * and seting properties values from ovfProperties
 */
protected void setVAppPropertiesToConfigSpec(VmConfigInfo vAppConfig, Map<String, String> ovfProperties, VirtualMachineConfigSpec vmConfig, VmwareHypervisorHost hyperHost) throws Exception {
    VmConfigSpec vmConfigSpec = new VmConfigSpec();
    vmConfigSpec.getEula().addAll(vAppConfig.getEula());
    vmConfigSpec.setInstallBootStopDelay(vAppConfig.getInstallBootStopDelay());
    vmConfigSpec.setInstallBootRequired(vAppConfig.isInstallBootRequired());
    vmConfigSpec.setIpAssignment(vAppConfig.getIpAssignment());
    vmConfigSpec.getOvfEnvironmentTransport().addAll(vAppConfig.getOvfEnvironmentTransport());
    // For backward compatibility, prior to Vmware 6.5 use EDIT operation instead of ADD
    boolean useEditOperation = hyperHost.getContext().getServiceContent().getAbout().getApiVersion().compareTo("6.5") < 1;
    vmConfigSpec.getProduct().addAll(copyVAppConfigProductSectionFromOVF(vAppConfig, useEditOperation));
    vmConfigSpec.getProperty().addAll(copyVAppConfigPropertySectionFromOVF(vAppConfig, ovfProperties, useEditOperation));
    vmConfigSpec.getOvfSection().addAll(copyVAppConfigOvfSectionFromOVF(vAppConfig, useEditOperation));
    vmConfig.setVAppConfig(vmConfigSpec);
}
Also used : VmConfigSpec(com.vmware.vim25.VmConfigSpec)

Example 2 with VmConfigInfo

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

the class VmwareResource method copyVAppConfigProductSectionFromOVF.

/**
 * Set the product section spec from existing vApp configuration
 */
protected List<VAppProductSpec> copyVAppConfigProductSectionFromOVF(VmConfigInfo vAppConfig, boolean useEdit) {
    List<VAppProductInfo> productFromOvf = vAppConfig.getProduct();
    List<VAppProductSpec> specs = new ArrayList<>();
    for (VAppProductInfo info : productFromOvf) {
        VAppProductSpec spec = new VAppProductSpec();
        spec.setInfo(info);
        s_logger.info("Procuct info KEY " + info.getKey());
        spec.setOperation(useEdit ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD);
        specs.add(spec);
    }
    return specs;
}
Also used : ArrayList(java.util.ArrayList) VAppProductSpec(com.vmware.vim25.VAppProductSpec) VAppProductInfo(com.vmware.vim25.VAppProductInfo)

Example 3 with VmConfigInfo

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

the class VmwareResource method copyVAppConfigPropertySectionFromOVF.

/**
 * Set the properties section from existing vApp configuration and values set on ovfProperties
 */
protected List<VAppPropertySpec> copyVAppConfigPropertySectionFromOVF(VmConfigInfo vAppConfig, Map<String, String> ovfProperties, boolean useEdit) {
    List<VAppPropertyInfo> productFromOvf = vAppConfig.getProperty();
    List<VAppPropertySpec> specs = new ArrayList<>();
    for (VAppPropertyInfo info : productFromOvf) {
        VAppPropertySpec spec = new VAppPropertySpec();
        if (ovfProperties.containsKey(info.getId())) {
            String value = ovfProperties.get(info.getId());
            info.setValue(value);
            s_logger.info("Setting OVF property ID = " + info.getId() + " VALUE = " + value);
        }
        spec.setInfo(info);
        spec.setOperation(useEdit ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD);
        specs.add(spec);
    }
    return specs;
}
Also used : ArrayList(java.util.ArrayList) VAppPropertyInfo(com.vmware.vim25.VAppPropertyInfo) VAppPropertySpec(com.vmware.vim25.VAppPropertySpec)

Example 4 with VmConfigInfo

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

the class VmwareStorageProcessor method copyTemplateFromSecondaryToPrimary.

private Pair<VirtualMachineMO, Long> copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl, String templatePathAtSecondaryStorage, String templateName, String templateUuid, boolean createSnapshot, String nfsVersion, String configuration) throws Exception {
    String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, nfsVersion);
    s_logger.info(String.format("Init copy of template [name: %s, path in secondary storage: %s, configuration: %s] in secondary storage [url: %s, mount point: %s] to primary storage.", templateName, templatePathAtSecondaryStorage, configuration, secondaryStorageUrl, secondaryMountPoint));
    String srcOVAFileName = VmwareStorageLayoutHelper.getTemplateOnSecStorageFilePath(secondaryMountPoint, templatePathAtSecondaryStorage, templateName, ImageFormat.OVA.getFileExtension());
    String srcFileName = getOVFFilePath(srcOVAFileName);
    if (srcFileName == null) {
        Script command = new Script("tar", 0, s_logger);
        command.add("--no-same-owner");
        command.add("-xf", srcOVAFileName);
        command.setWorkDir(secondaryMountPoint + "/" + templatePathAtSecondaryStorage);
        s_logger.info("Executing command: " + command.toString());
        String result = command.execute();
        if (result != null) {
            String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName;
            s_logger.error(msg);
            throw new Exception(msg);
        }
    }
    srcFileName = getOVFFilePath(srcOVAFileName);
    if (srcFileName == null) {
        String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName;
        s_logger.error(msg);
        throw new Exception(msg);
    }
    if (datastoreMo.getDatastoreType().equalsIgnoreCase("VVOL")) {
        templateUuid = CustomFieldConstants.CLOUD_UUID + "-" + templateUuid;
    }
    VmConfigInfo vAppConfig;
    s_logger.debug(String.format("Deploying OVF template %s with configuration %s.", templateName, configuration));
    hyperHost.importVmFromOVF(srcFileName, templateUuid, datastoreMo, "thin", configuration);
    VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(templateUuid);
    if (vmMo == null) {
        String msg = "Failed to import OVA template. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + templatePathAtSecondaryStorage + ", templateName: " + templateName + ", templateUuid: " + templateUuid;
        s_logger.error(msg);
        throw new Exception(msg);
    } else {
        vAppConfig = vmMo.getConfigInfo().getVAppConfig();
        if (vAppConfig != null) {
            s_logger.info("Found vApp configuration");
        }
    }
    OVAProcessor processor = new OVAProcessor();
    Map<String, Object> params = new HashMap<>();
    params.put(StorageLayer.InstanceConfigKey, _storage);
    processor.configure("OVA Processor", params);
    long virtualSize = processor.getTemplateVirtualSize(secondaryMountPoint + "/" + templatePathAtSecondaryStorage, templateName);
    if (createSnapshot) {
        if (vmMo.createSnapshot("cloud.template.base", "Base snapshot", false, false)) {
            // the same template may be deployed with multiple copies at per-datastore per-host basis,
            // save the original template name from CloudStack DB as the UUID to associate them.
            vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, templateName);
            if (vAppConfig == null || (vAppConfig.getProperty().size() == 0)) {
                vmMo.markAsTemplate();
            }
        } else {
            vmMo.destroy();
            String msg = "Unable to create base snapshot for template, templateName: " + templateName + ", templateUuid: " + templateUuid;
            s_logger.error(msg);
            throw new Exception(msg);
        }
    }
    return new Pair<>(vmMo, virtualSize);
}
Also used : Script(com.cloud.utils.script.Script) OVAProcessor(com.cloud.storage.template.OVAProcessor) HashMap(java.util.HashMap) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VStorageObject(com.vmware.vim25.VStorageObject) VmConfigInfo(com.vmware.vim25.VmConfigInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Pair(com.cloud.utils.Pair)

Example 5 with VmConfigInfo

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

the class VirtualMachineMO method cloneFromDiskChain.

public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception {
    assert (disks != null);
    assert (disks.length >= 1);
    HostMO hostMo = getRunningHost();
    VirtualMachineConfigInfo vmConfigInfo = getConfigInfo();
    if (!hostMo.createBlankVm(clonedVmName, 1, cpuSpeedMHz, 0, false, memoryMb, 0, vmConfigInfo.getGuestId(), morDs, false))
        throw new Exception("Unable to create a blank VM");
    VirtualMachineMO clonedVmMo = hostMo.findVmOnHyperHost(clonedVmName);
    if (clonedVmMo == null)
        throw new Exception("Unable to find just-created blank VM");
    boolean bSuccess = false;
    try {
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
        deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
        VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, -1, disks, morDs, -1, 1);
        deviceConfigSpecArray[0].setDevice(device);
        deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
        vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
        clonedVmMo.configureVm(vmConfigSpec);
        bSuccess = true;
    } finally {
        if (!bSuccess) {
            clonedVmMo.detachAllDisks();
            clonedVmMo.destroy();
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo)

Aggregations

ArrayList (java.util.ArrayList)3 VmConfigInfo (com.vmware.vim25.VmConfigInfo)2 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)1 OVAProcessor (com.cloud.storage.template.OVAProcessor)1 Pair (com.cloud.utils.Pair)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Script (com.cloud.utils.script.Script)1 VAppOvfSectionInfo (com.vmware.vim25.VAppOvfSectionInfo)1 VAppOvfSectionSpec (com.vmware.vim25.VAppOvfSectionSpec)1 VAppProductInfo (com.vmware.vim25.VAppProductInfo)1 VAppProductSpec (com.vmware.vim25.VAppProductSpec)1 VAppPropertyInfo (com.vmware.vim25.VAppPropertyInfo)1 VAppPropertySpec (com.vmware.vim25.VAppPropertySpec)1 VStorageObject (com.vmware.vim25.VStorageObject)1 VirtualDevice (com.vmware.vim25.VirtualDevice)1 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)1 VirtualMachineConfigInfo (com.vmware.vim25.VirtualMachineConfigInfo)1 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)1 VmConfigSpec (com.vmware.vim25.VmConfigSpec)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1