5959import org .apache .cloudstack .utils .volume .VirtualMachineDiskInfo ;
6060import org .apache .cloudstack .vm .UnmanagedInstanceTO ;
6161import org .apache .commons .collections .CollectionUtils ;
62+ import org .apache .commons .collections .MapUtils ;
6263import org .apache .commons .lang .ArrayUtils ;
6364import org .apache .commons .lang .StringUtils ;
6465import org .apache .commons .lang .math .NumberUtils ;
@@ -2336,7 +2337,7 @@ protected StartAnswer execute(StartCommand cmd) {
23362337 configBasicExtraOption (extraOptions , vmSpec );
23372338
23382339 if (deployAsIs ) {
2339- setDeployAsIsProperties (vmMo , deployAsIsInfo , vmConfigSpec );
2340+ setDeployAsIsProperties (vmMo , deployAsIsInfo , vmConfigSpec , hyperHost );
23402341 }
23412342
23422343 configNvpExtraOption (extraOptions , vmSpec , nicUuidToDvSwitchUuid );
@@ -2563,12 +2564,12 @@ private String getBootModeFromVmSpec(VirtualMachineTO vmSpec, boolean deployAsIs
25632564 * Set OVF properties (if available)
25642565 */
25652566 private void setDeployAsIsProperties (VirtualMachineMO vmMo , DeployAsIsInfoTO deployAsIsInfo ,
2566- VirtualMachineConfigSpec vmConfigSpec ) throws Exception {
2567- if (deployAsIsInfo != null ) {
2567+ VirtualMachineConfigSpec vmConfigSpec , VmwareHypervisorHost hyperHost ) throws Exception {
2568+ if (deployAsIsInfo != null && MapUtils . isNotEmpty ( deployAsIsInfo . getProperties ()) ) {
25682569 Map <String , String > properties = deployAsIsInfo .getProperties ();
25692570 VmConfigInfo vAppConfig = vmMo .getConfigInfo ().getVAppConfig ();
25702571 s_logger .info ("Copying OVF properties to the values the user provided" );
2571- setVAppPropertiesToConfigSpec (vAppConfig , properties , vmConfigSpec );
2572+ setVAppPropertiesToConfigSpec (vAppConfig , properties , vmConfigSpec , hyperHost );
25722573 }
25732574 }
25742575
@@ -2660,13 +2661,13 @@ private void setBootOptions(VirtualMachineTO vmSpec, String bootMode, VirtualMac
26602661 /**
26612662 * Set the ovf section spec from existing vApp configuration
26622663 */
2663- protected List <VAppOvfSectionSpec > copyVAppConfigOvfSectionFromOVF (VmConfigInfo vAppConfig ) {
2664+ protected List <VAppOvfSectionSpec > copyVAppConfigOvfSectionFromOVF (VmConfigInfo vAppConfig , boolean useEdit ) {
26642665 List <VAppOvfSectionInfo > ovfSection = vAppConfig .getOvfSection ();
26652666 List <VAppOvfSectionSpec > specs = new ArrayList <>();
26662667 for (VAppOvfSectionInfo info : ovfSection ) {
26672668 VAppOvfSectionSpec spec = new VAppOvfSectionSpec ();
26682669 spec .setInfo (info );
2669- spec .setOperation (ArrayUpdateOperation .ADD );
2670+ spec .setOperation (useEdit ? ArrayUpdateOperation . EDIT : ArrayUpdateOperation .ADD );
26702671 specs .add (spec );
26712672 }
26722673 return specs ;
@@ -2694,17 +2695,19 @@ private String getPropertyValue(OVFPropertyTO prop) {
26942695 /**
26952696 * Set the properties section from existing vApp configuration and values set on ovfProperties
26962697 */
2697- protected List <VAppPropertySpec > copyVAppConfigPropertySectionFromOVF (VmConfigInfo vAppConfig , Map <String , String > ovfProperties ) {
2698+ protected List <VAppPropertySpec > copyVAppConfigPropertySectionFromOVF (VmConfigInfo vAppConfig , Map <String , String > ovfProperties ,
2699+ boolean useEdit ) {
26982700 List <VAppPropertyInfo > productFromOvf = vAppConfig .getProperty ();
26992701 List <VAppPropertySpec > specs = new ArrayList <>();
27002702 for (VAppPropertyInfo info : productFromOvf ) {
27012703 VAppPropertySpec spec = new VAppPropertySpec ();
27022704 if (ovfProperties .containsKey (info .getId ())) {
27032705 String value = ovfProperties .get (info .getId ());
27042706 info .setValue (value );
2707+ s_logger .info ("Setting OVF property ID = " + info .getId () + " VALUE = " + value );
27052708 }
27062709 spec .setInfo (info );
2707- spec .setOperation (ArrayUpdateOperation .ADD );
2710+ spec .setOperation (useEdit ? ArrayUpdateOperation . EDIT : ArrayUpdateOperation .ADD );
27082711 specs .add (spec );
27092712 }
27102713 return specs ;
@@ -2713,13 +2716,14 @@ protected List<VAppPropertySpec> copyVAppConfigPropertySectionFromOVF(VmConfigIn
27132716 /**
27142717 * Set the product section spec from existing vApp configuration
27152718 */
2716- protected List <VAppProductSpec > copyVAppConfigProductSectionFromOVF (VmConfigInfo vAppConfig ) {
2719+ protected List <VAppProductSpec > copyVAppConfigProductSectionFromOVF (VmConfigInfo vAppConfig , boolean useEdit ) {
27172720 List <VAppProductInfo > productFromOvf = vAppConfig .getProduct ();
27182721 List <VAppProductSpec > specs = new ArrayList <>();
27192722 for (VAppProductInfo info : productFromOvf ) {
27202723 VAppProductSpec spec = new VAppProductSpec ();
27212724 spec .setInfo (info );
2722- spec .setOperation (ArrayUpdateOperation .ADD );
2725+ s_logger .info ("Procuct info KEY " + info .getKey ());
2726+ spec .setOperation (useEdit ? ArrayUpdateOperation .EDIT : ArrayUpdateOperation .ADD );
27232727 specs .add (spec );
27242728 }
27252729 return specs ;
@@ -2731,16 +2735,19 @@ protected List<VAppProductSpec> copyVAppConfigProductSectionFromOVF(VmConfigInfo
27312735 */
27322736 protected void setVAppPropertiesToConfigSpec (VmConfigInfo vAppConfig ,
27332737 Map <String , String > ovfProperties ,
2734- VirtualMachineConfigSpec vmConfig ) throws Exception {
2738+ VirtualMachineConfigSpec vmConfig , VmwareHypervisorHost hyperHost ) throws Exception {
27352739 VmConfigSpec vmConfigSpec = new VmConfigSpec ();
27362740 vmConfigSpec .getEula ().addAll (vAppConfig .getEula ());
27372741 vmConfigSpec .setInstallBootStopDelay (vAppConfig .getInstallBootStopDelay ());
27382742 vmConfigSpec .setInstallBootRequired (vAppConfig .isInstallBootRequired ());
27392743 vmConfigSpec .setIpAssignment (vAppConfig .getIpAssignment ());
27402744 vmConfigSpec .getOvfEnvironmentTransport ().addAll (vAppConfig .getOvfEnvironmentTransport ());
2741- vmConfigSpec .getProduct ().addAll (copyVAppConfigProductSectionFromOVF (vAppConfig ));
2742- vmConfigSpec .getProperty ().addAll (copyVAppConfigPropertySectionFromOVF (vAppConfig , ovfProperties ));
2743- vmConfigSpec .getOvfSection ().addAll (copyVAppConfigOvfSectionFromOVF (vAppConfig ));
2745+
2746+ // For backward compatibility, prior to Vmware 6.5 use EDIT operation instead of ADD
2747+ boolean useEditOperation = hyperHost .getContext ().getServiceContent ().getAbout ().getApiVersion ().compareTo ("6.5" ) < 1 ;
2748+ vmConfigSpec .getProduct ().addAll (copyVAppConfigProductSectionFromOVF (vAppConfig , useEditOperation ));
2749+ vmConfigSpec .getProperty ().addAll (copyVAppConfigPropertySectionFromOVF (vAppConfig , ovfProperties , useEditOperation ));
2750+ vmConfigSpec .getOvfSection ().addAll (copyVAppConfigOvfSectionFromOVF (vAppConfig , useEditOperation ));
27442751 vmConfig .setVAppConfig (vmConfigSpec );
27452752 }
27462753
0 commit comments