-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix VMware OVF properties copy from template #4738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -55,6 +55,7 @@ | |||||
| import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo; | ||||||
| import org.apache.cloudstack.vm.UnmanagedInstanceTO; | ||||||
| import org.apache.commons.collections.CollectionUtils; | ||||||
| import org.apache.commons.collections.MapUtils; | ||||||
| import org.apache.commons.lang.ArrayUtils; | ||||||
| import org.apache.commons.lang.StringUtils; | ||||||
| import org.apache.commons.lang.math.NumberUtils; | ||||||
|
|
@@ -2330,7 +2331,7 @@ protected StartAnswer execute(StartCommand cmd) { | |||||
| configBasicExtraOption(extraOptions, vmSpec); | ||||||
|
|
||||||
| if (deployAsIs) { | ||||||
| setDeployAsIsProperties(vmMo, deployAsIsInfo, vmConfigSpec); | ||||||
| setDeployAsIsProperties(vmMo, deployAsIsInfo, vmConfigSpec, hyperHost); | ||||||
| } | ||||||
|
|
||||||
| configNvpExtraOption(extraOptions, vmSpec, nicUuidToDvSwitchUuid); | ||||||
|
|
@@ -2557,12 +2558,12 @@ private String getBootModeFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs | |||||
| * Set OVF properties (if available) | ||||||
| */ | ||||||
| private void setDeployAsIsProperties(VirtualMachineMO vmMo, DeployAsIsInfoTO deployAsIsInfo, | ||||||
| VirtualMachineConfigSpec vmConfigSpec) throws Exception { | ||||||
| if (deployAsIsInfo != null) { | ||||||
| VirtualMachineConfigSpec vmConfigSpec, VmwareHypervisorHost hyperHost) throws Exception { | ||||||
| if (deployAsIsInfo != null && MapUtils.isNotEmpty(deployAsIsInfo.getProperties())) { | ||||||
| Map<String, String> properties = deployAsIsInfo.getProperties(); | ||||||
| VmConfigInfo vAppConfig = vmMo.getConfigInfo().getVAppConfig(); | ||||||
| s_logger.info("Copying OVF properties to the values the user provided"); | ||||||
| setVAppPropertiesToConfigSpec(vAppConfig, properties, vmConfigSpec); | ||||||
| setVAppPropertiesToConfigSpec(vAppConfig, properties, vmConfigSpec, hyperHost); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -2654,13 +2655,13 @@ private void setBootOptions(VirtualMachineTO vmSpec, String bootMode, VirtualMac | |||||
| /** | ||||||
| * Set the ovf section spec from existing vApp configuration | ||||||
| */ | ||||||
| protected List<VAppOvfSectionSpec> copyVAppConfigOvfSectionFromOVF(VmConfigInfo vAppConfig) { | ||||||
| protected List<VAppOvfSectionSpec> copyVAppConfigOvfSectionFromOVF(VmConfigInfo vAppConfig, boolean useEdit) { | ||||||
| List<VAppOvfSectionInfo> ovfSection = vAppConfig.getOvfSection(); | ||||||
| List<VAppOvfSectionSpec> specs = new ArrayList<>(); | ||||||
| for (VAppOvfSectionInfo info : ovfSection) { | ||||||
| VAppOvfSectionSpec spec = new VAppOvfSectionSpec(); | ||||||
| spec.setInfo(info); | ||||||
| spec.setOperation(ArrayUpdateOperation.ADD); | ||||||
| spec.setOperation(useEdit ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD); | ||||||
| specs.add(spec); | ||||||
| } | ||||||
| return specs; | ||||||
|
|
@@ -2688,17 +2689,19 @@ private String getPropertyValue(OVFPropertyTO prop) { | |||||
| /** | ||||||
| * Set the properties section from existing vApp configuration and values set on ovfProperties | ||||||
| */ | ||||||
| protected List<VAppPropertySpec> copyVAppConfigPropertySectionFromOVF(VmConfigInfo vAppConfig, Map<String, String> 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(ArrayUpdateOperation.ADD); | ||||||
| spec.setOperation(useEdit ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD); | ||||||
| specs.add(spec); | ||||||
| } | ||||||
| return specs; | ||||||
|
|
@@ -2707,13 +2710,14 @@ protected List<VAppPropertySpec> copyVAppConfigPropertySectionFromOVF(VmConfigIn | |||||
| /** | ||||||
| * Set the product section spec from existing vApp configuration | ||||||
| */ | ||||||
| protected List<VAppProductSpec> copyVAppConfigProductSectionFromOVF(VmConfigInfo vAppConfig) { | ||||||
| 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); | ||||||
| spec.setOperation(ArrayUpdateOperation.ADD); | ||||||
| s_logger.info("Procuct info KEY " + info.getKey()); | ||||||
| spec.setOperation(useEdit ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD); | ||||||
| specs.add(spec); | ||||||
| } | ||||||
| return specs; | ||||||
|
|
@@ -2725,16 +2729,19 @@ protected List<VAppProductSpec> copyVAppConfigProductSectionFromOVF(VmConfigInfo | |||||
| */ | ||||||
| protected void setVAppPropertiesToConfigSpec(VmConfigInfo vAppConfig, | ||||||
| Map<String, String> ovfProperties, | ||||||
| VirtualMachineConfigSpec vmConfig) throws Exception { | ||||||
| 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()); | ||||||
| vmConfigSpec.getProduct().addAll(copyVAppConfigProductSectionFromOVF(vAppConfig)); | ||||||
| vmConfigSpec.getProperty().addAll(copyVAppConfigPropertySectionFromOVF(vAppConfig, ovfProperties)); | ||||||
| vmConfigSpec.getOvfSection().addAll(copyVAppConfigOvfSectionFromOVF(vAppConfig)); | ||||||
|
|
||||||
| // 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; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| vmConfigSpec.getProduct().addAll(copyVAppConfigProductSectionFromOVF(vAppConfig, useEditOperation)); | ||||||
| vmConfigSpec.getProperty().addAll(copyVAppConfigPropertySectionFromOVF(vAppConfig, ovfProperties, useEditOperation)); | ||||||
| vmConfigSpec.getOvfSection().addAll(copyVAppConfigOvfSectionFromOVF(vAppConfig, useEditOperation)); | ||||||
| vmConfig.setVAppConfig(vmConfigSpec); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Product - typo