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);
}
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;
}
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;
}
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);
}
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();
}
}
}
Aggregations