This is an automated email from the ASF dual-hosted git repository.

harikrishna pushed a commit to branch VMDynamicScalabilityGranularity
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit b60de9c01e347569525516f29a80afbfadb79e5e
Author: Harikrishna Patnala <[email protected]>
AuthorDate: Fri Jan 29 10:48:07 2021 +0530

    Dynamic Scaling option granularity
---
 .../java/com/cloud/offering/ServiceOffering.java   |  2 +
 api/src/main/java/com/cloud/vm/UserVmService.java  |  6 +-
 api/src/main/java/com/cloud/vm/VirtualMachine.java |  2 +
 .../org/apache/cloudstack/api/ApiConstants.java    |  1 +
 .../admin/offering/CreateServiceOfferingCmd.java   |  9 +++
 .../api/command/user/vm/DeployVMCmd.java           |  9 +++
 .../api/response/ServiceOfferingResponse.java      | 13 +++-
 .../cloudstack/api/response/SystemVmResponse.java  | 12 +++
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |  2 +
 .../java/com/cloud/service/ServiceOfferingVO.java  | 67 +++++-----------
 .../engine/cloud/entity/api/db/VMEntityVO.java     |  8 ++
 .../resources/META-INF/db/schema-41400to41500.sql  |  2 +-
 .../resources/META-INF/db/schema-41510to41600.sql  | 90 ++++++++++++++++++++++
 .../cloudstack/quota/vo/ServiceOfferingVO.java     |  8 ++
 ...ernetesClusterResourceModifierActionWorker.java |  2 +-
 .../KubernetesClusterStartWorker.java              |  7 +-
 .../main/java/com/cloud/api/ApiResponseHelper.java |  1 +
 .../api/query/dao/ServiceOfferingJoinDaoImpl.java  |  1 +
 .../cloud/api/query/vo/ServiceOfferingJoinVO.java  | 11 +++
 .../configuration/ConfigurationManagerImpl.java    |  6 +-
 .../com/cloud/hypervisor/HypervisorGuruBase.java   |  3 +-
 .../com/cloud/network/as/AutoScaleManagerImpl.java |  6 +-
 .../main/java/com/cloud/vm/UserVmManagerImpl.java  | 71 +++++++++++------
 .../vm/DeploymentPlanningManagerImplTest.java      |  6 +-
 24 files changed, 254 insertions(+), 91 deletions(-)

diff --git a/api/src/main/java/com/cloud/offering/ServiceOffering.java 
b/api/src/main/java/com/cloud/offering/ServiceOffering.java
index 2a80ba5..1637622 100644
--- a/api/src/main/java/com/cloud/offering/ServiceOffering.java
+++ b/api/src/main/java/com/cloud/offering/ServiceOffering.java
@@ -116,4 +116,6 @@ public interface ServiceOffering extends DiskOffering, 
InfrastructureEntity, Int
     String getDeploymentPlanner();
 
     boolean isDynamic();
+
+    boolean isDynamicallyScalable();
 }
diff --git a/api/src/main/java/com/cloud/vm/UserVmService.java 
b/api/src/main/java/com/cloud/vm/UserVmService.java
index 56a6dfd..ec95972 100644
--- a/api/src/main/java/com/cloud/vm/UserVmService.java
+++ b/api/src/main/java/com/cloud/vm/UserVmService.java
@@ -218,7 +218,7 @@ public interface UserVmService {
         String userData, String sshKeyPair, Map<Long, IpAddresses> 
requestedIps, IpAddresses defaultIp, Boolean displayVm, String keyboard,
         List<Long> affinityGroupIdList, Map<String, String> customParameter, 
String customId, Map<String, Map<Integer, String>> dhcpOptionMap,
         Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap,
-        Map<String, String> userVmOVFProperties) throws 
InsufficientCapacityException,
+        Map<String, String> userVmOVFProperties, Boolean 
dynamicScalingEnabled) throws InsufficientCapacityException,
         ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException;
 
     /**
@@ -300,7 +300,7 @@ public interface UserVmService {
         HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, 
IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String 
keyboard,
         List<Long> affinityGroupIdList, Map<String, String> customParameters, 
String customId, Map<String, Map<Integer, String>> dhcpOptionMap,
         Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap,
-        Map<String, String> userVmOVFProperties) throws 
InsufficientCapacityException,
+        Map<String, String> userVmOVFProperties, Boolean 
dynamicScalingEnabled) throws InsufficientCapacityException,
         ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException;
 
     /**
@@ -379,7 +379,7 @@ public interface UserVmService {
         String hostName, String displayName, Long diskOfferingId, Long 
diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, 
String userData,
         String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses 
defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList,
         Map<String, String> customParameters, String customId, Map<String, 
Map<Integer, String>> dhcpOptionMap, Map<Long, DiskOffering> 
dataDiskTemplateToDiskOfferingMap,
-        Map<String, String> templateOvfPropertiesMap)
+        Map<String, String> templateOvfPropertiesMap, Boolean 
dynamicScalingEnabled)
 
         throws InsufficientCapacityException, ConcurrentOperationException, 
ResourceUnavailableException, StorageUnavailableException, 
ResourceAllocationException;
 
diff --git a/api/src/main/java/com/cloud/vm/VirtualMachine.java 
b/api/src/main/java/com/cloud/vm/VirtualMachine.java
index 4d6014f..e216b08 100644
--- a/api/src/main/java/com/cloud/vm/VirtualMachine.java
+++ b/api/src/main/java/com/cloud/vm/VirtualMachine.java
@@ -339,4 +339,6 @@ public interface VirtualMachine extends RunningOn, 
ControlledEntity, Partition,
     @Override
     boolean isDisplay();
 
+    Boolean isDynamicallyScalable();
+
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java 
b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
index 0087fee..27b0f7a 100644
--- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
@@ -831,6 +831,7 @@ public class ApiConstants {
     public static final String CROSS_ZONES = "crossZones";
     public static final String TEMPLATETYPE = "templatetype";
     public static final String SOURCETEMPLATEID = "sourcetemplateid";
+    public static final String DynamicScalingEnabled = "dynamicscalingenabled";
 
     public enum BootType {
         UEFI, BIOS;
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
 
b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
index 3219422..3c8ca79 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java
@@ -223,6 +223,11 @@ public class CreateServiceOfferingCmd extends BaseCmd {
     @Parameter(name = ApiConstants.STORAGE_POLICY, type = CommandType.UUID, 
entityType = VsphereStoragePoliciesResponse.class,required = false, description 
= "Name of the storage policy defined at vCenter, this is applicable only for 
VMware", since = "4.15")
     private Long storagePolicy;
 
+    @Parameter(name = ApiConstants.DynamicScalingEnabled,
+            type = CommandType.BOOLEAN,
+            description = "true if virtual machine needs to be dynamically 
scalable of cpu or memory")
+    protected Boolean isDynamicScalingEnabled;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -433,6 +438,10 @@ public class CreateServiceOfferingCmd extends BaseCmd {
         return storagePolicy;
     }
 
+    public Boolean getDynamicScalingEnabled() {
+        return isDynamicScalingEnabled == null ? Boolean.TRUE : 
isDynamicScalingEnabled;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java 
b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index 6d7cc9c..d6f3727 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -235,6 +235,11 @@ public class DeployVMCmd extends 
BaseAsyncCreateCustomIdCmd implements SecurityG
     @LogLevel(LogLevel.Log4jLevel.Off)
     private Map vAppNetworks;
 
+    @Parameter(name = ApiConstants.DynamicScalingEnabled,
+            type = CommandType.BOOLEAN,
+            description = "true if virtual machine needs to be dynamically 
scalable")
+    protected Boolean isDynamicScalingEnabled;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -623,6 +628,10 @@ public class DeployVMCmd extends 
BaseAsyncCreateCustomIdCmd implements SecurityG
         return bootIntoSetup;
     }
 
+    public Boolean getDynamicScalingEnabled() {
+        return isDynamicScalingEnabled == null ? Boolean.TRUE : 
isDynamicScalingEnabled;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
 
b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
index 05fcfbd..40be57c 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
@@ -204,6 +204,10 @@ public class ServiceOfferingResponse extends BaseResponse {
     @Param(description = "Root disk size in GB", since = "4.15")
     private Long rootDiskSize;
 
+    @SerializedName("dynamicscalingenabled")
+    @Param(description = "true if virtual machine needs to be dynamically 
scalable of cpu or memory")
+    private Boolean dynamicscalingenabled;
+
     public ServiceOfferingResponse() {
     }
 
@@ -457,7 +461,6 @@ public class ServiceOfferingResponse extends BaseResponse {
 
     public void setIscutomized(boolean iscutomized) {
         this.isCustomized = iscutomized;
-
     }
 
     public void setCacheMode(String cacheMode) {
@@ -475,4 +478,12 @@ public class ServiceOfferingResponse extends BaseResponse {
     public void setRootDiskSize(Long rootDiskSize) {
         this.rootDiskSize = rootDiskSize;
     }
+
+    public Boolean getDynamicscalingenabled() {
+        return dynamicscalingenabled;
+    }
+
+    public void setDynamicscalingenabled(Boolean dynamicscalingenabled) {
+        this.dynamicscalingenabled = dynamicscalingenabled;
+    }
 }
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java 
b/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java
index 934e84f..bfc9f9a 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java
@@ -170,6 +170,10 @@ public class SystemVmResponse extends BaseResponse {
     @Param(description = "the systemvm agent version", since = "4.13.1")
     private String version;
 
+    @SerializedName(ApiConstants.IS_DYNAMICALLY_SCALABLE)
+    @Param(description = "true if vm contains XS/VMWare tools inorder to 
support dynamic scaling of VM cpu/memory.")
+    private Boolean isDynamicallyScalable;
+
     @Override
     public String getObjectId() {
         return this.getId();
@@ -442,4 +446,12 @@ public class SystemVmResponse extends BaseResponse {
     public void setVersion(String version) {
         this.version = version;
     }
+
+    public Boolean getDynamicallyScalable() {
+        return isDynamicallyScalable;
+    }
+
+    public void setDynamicallyScalable(Boolean dynamicallyScalable) {
+        isDynamicallyScalable = dynamicallyScalable;
+    }
 }
diff --git 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
index f1ab9cd..d3c9c37 100755
--- 
a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
+++ 
b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -3685,6 +3685,8 @@ public class VirtualMachineManagerImpl extends 
ManagerBase implements VirtualMac
         if (currentServiceOffering.isDynamic() && 
!newServiceOffering.isDynamic()) {
             removeCustomOfferingDetails(vmId);
         }
+        Boolean dynamicScalingEnabled = vmForUpdate.isDynamicallyScalable() && 
newServiceOffering.isDynamicallyScalable() && 
UserVmManager.EnableDynamicallyScaleVm.valueIn(vmForUpdate.getDataCenterId());
+        vmForUpdate.setDynamicallyScalable(dynamicScalingEnabled);
         return _vmDao.update(vmId, vmForUpdate);
     }
 
diff --git 
a/engine/schema/src/main/java/com/cloud/service/ServiceOfferingVO.java 
b/engine/schema/src/main/java/com/cloud/service/ServiceOfferingVO.java
index 3a5f318..c265bcd 100644
--- a/engine/schema/src/main/java/com/cloud/service/ServiceOfferingVO.java
+++ b/engine/schema/src/main/java/com/cloud/service/ServiceOfferingVO.java
@@ -75,6 +75,9 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
     @Column(name = "deployment_planner")
     private String deploymentPlanner = null;
 
+    @Column(name = "dynamically_scalable")
+    private boolean dynamicallyScalable;
+
     // This is a delayed load value.  If the value is null,
     // then this field has not been loaded yet.
     // Call service offering dao to load it.
@@ -91,7 +94,7 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
     }
 
     public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, 
Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, 
String displayText,
-            ProvisioningType provisioningType, boolean useLocalStorage, 
boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type 
vmType, boolean defaultUse) {
+                             ProvisioningType provisioningType, boolean 
useLocalStorage, boolean recreatable, String tags, boolean systemUse, 
VirtualMachine.Type vmType, boolean defaultUse) {
         super(name, displayText, provisioningType, false, tags, recreatable, 
useLocalStorage, systemUse, true);
         this.cpu = cpu;
         this.ramSize = ramSize;
@@ -105,8 +108,9 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
         this.vmType = vmType == null ? null : vmType.toString().toLowerCase();
     }
 
-    public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, 
Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, 
boolean limitCpuUse,
-                             boolean volatileVm, String displayText, 
ProvisioningType provisioningType, boolean useLocalStorage, boolean 
recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType) {
+    public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, 
Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA,
+                             boolean limitResourceUse, boolean volatileVm, 
String displayText, ProvisioningType provisioningType, boolean useLocalStorage, 
boolean recreatable, String tags, boolean systemUse,
+                             VirtualMachine.Type vmType, String hostTag, 
String deploymentPlanner, Boolean dynamicScalingEnabled) {
         super(name, displayText, provisioningType, false, tags, recreatable, 
useLocalStorage, systemUse, true);
         this.cpu = cpu;
         this.ramSize = ramSize;
@@ -114,55 +118,12 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
         this.rateMbps = rateMbps;
         this.multicastRateMbps = multicastRateMbps;
         this.offerHA = offerHA;
-        this.limitCpuUse = limitCpuUse;
+        this.limitCpuUse = limitResourceUse;
         this.volatileVm = volatileVm;
         this.vmType = vmType == null ? null : vmType.toString().toLowerCase();
-    }
-
-    public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, 
Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA,
-                             boolean limitResourceUse, boolean volatileVm, 
String displayText, ProvisioningType provisioningType, boolean useLocalStorage, 
boolean recreatable, String tags, boolean systemUse,
-                             VirtualMachine.Type vmType, String hostTag) {
-        this(name,
-            cpu,
-            ramSize,
-            speed,
-            rateMbps,
-            multicastRateMbps,
-            offerHA,
-            limitResourceUse,
-            volatileVm,
-            displayText,
-            provisioningType,
-            useLocalStorage,
-            recreatable,
-            tags,
-            systemUse,
-            vmType
-        );
         this.hostTag = hostTag;
-    }
-
-    public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, 
Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA,
-                             boolean limitResourceUse, boolean volatileVm, 
String displayText, ProvisioningType provisioningType, boolean useLocalStorage, 
boolean recreatable, String tags, boolean systemUse,
-                             VirtualMachine.Type vmType, String hostTag, 
String deploymentPlanner) {
-        this(name,
-            cpu,
-            ramSize,
-            speed,
-            rateMbps,
-            multicastRateMbps,
-            offerHA,
-            limitResourceUse,
-            volatileVm,
-            displayText,
-            provisioningType,
-            useLocalStorage,
-            recreatable,
-            tags,
-            systemUse,
-            vmType,
-                hostTag);
         this.deploymentPlanner = deploymentPlanner;
+        this.dynamicallyScalable = dynamicScalingEnabled;
     }
 
     public ServiceOfferingVO(ServiceOfferingVO offering) {
@@ -189,6 +150,7 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
         volatileVm = offering.isVolatileVm();
         hostTag = offering.getHostTag();
         vmType = offering.getSystemVmType();
+        dynamicallyScalable = offering.isDynamicallyScalable();
     }
 
     @Override
@@ -334,4 +296,13 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
     public boolean isCustomCpuSpeedSupported() {
         return isCustomized() && getDetail("minCPU") != null;
     }
+
+    @Override
+    public boolean isDynamicallyScalable() {
+        return dynamicallyScalable;
+    }
+
+    public void setDynamicallyScalable(boolean dynamicallyScalable) {
+        this.dynamicallyScalable = dynamicallyScalable;
+    }
 }
diff --git 
a/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
 
b/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
index 4ab5f42..494ffc6 100644
--- 
a/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
+++ 
b/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
@@ -189,6 +189,9 @@ public class VMEntityVO implements VirtualMachine, 
FiniteStateObject<State, Virt
     @Column(name = "backup_volumes")
     private String backupVolumes;
 
+    @Column(name = "dynamically_scalable")
+    protected boolean dynamicallyScalable;
+
     @Transient
     private VMReservationVO vmReservation;
 
@@ -561,6 +564,11 @@ public class VMEntityVO implements VirtualMachine, 
FiniteStateObject<State, Virt
         return display;
     }
 
+    @Override
+    public Boolean isDynamicallyScalable() {
+        return dynamicallyScalable;
+    }
+
     public void setDisplay(boolean display) {
         this.display = display;
     }
diff --git 
a/engine/schema/src/main/resources/META-INF/db/schema-41400to41500.sql 
b/engine/schema/src/main/resources/META-INF/db/schema-41400to41500.sql
index 9ead785..055061f 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41400to41500.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41400to41500.sql
@@ -842,4 +842,4 @@ ALTER TABLE `cloud_usage`.`cloud_usage` ADD COLUMN 
`is_hidden` smallint(1) NOT N
 UPDATE `cloud`.`data_center` JOIN (SELECT COUNT(1) AS count FROM 
`cloud`.`data_center` WHERE `sort_key` != 0) AS tbl_tmp SET `sort_key` = `id` 
WHERE count = 0;
 
 -- Fix description of volume.stats.interval which is in milliseconds not 
seconds
-UPDATE `cloud`.`configuration` SET `description` = 'Interval (in milliseconds) 
to report volume statistics' WHERE `name` = 'volume.stats.interval';
+UPDATE `cloud`.`configuration` SET `description` = 'Interval (in milliseconds) 
to report volume statistics' WHERE `name` = 'volume.stats.interval';
\ No newline at end of file
diff --git 
a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql 
b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql
index 0588c6d..d47cdc7 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql
@@ -19,3 +19,93 @@
 -- Schema upgrade from 4.15.1.0 to 4.16.0.0
 --;
 
+-- Adding dynamic scalable flag for service offering table
+ALTER TABLE `cloud`.`service_offering` ADD COLUMN `dynamically_scalable` 
tinyint(1) unsigned NOT NULL DEFAULT 1  COMMENT 'true(1) if VM needs to be 
dynamically scalable of cpu or memory';
+DROP VIEW IF EXISTS `cloud`.`service_offering_view`;
+CREATE VIEW `cloud`.`service_offering_view` AS
+    SELECT
+        `service_offering`.`id` AS `id`,
+        `disk_offering`.`uuid` AS `uuid`,
+        `disk_offering`.`name` AS `name`,
+        `disk_offering`.`display_text` AS `display_text`,
+        `disk_offering`.`provisioning_type` AS `provisioning_type`,
+        `disk_offering`.`created` AS `created`,
+        `disk_offering`.`tags` AS `tags`,
+        `disk_offering`.`removed` AS `removed`,
+        `disk_offering`.`use_local_storage` AS `use_local_storage`,
+        `disk_offering`.`system_use` AS `system_use`,
+        `disk_offering`.`customized_iops` AS `customized_iops`,
+        `disk_offering`.`min_iops` AS `min_iops`,
+        `disk_offering`.`max_iops` AS `max_iops`,
+        `disk_offering`.`hv_ss_reserve` AS `hv_ss_reserve`,
+        `disk_offering`.`bytes_read_rate` AS `bytes_read_rate`,
+        `disk_offering`.`bytes_read_rate_max` AS `bytes_read_rate_max`,
+        `disk_offering`.`bytes_read_rate_max_length` AS 
`bytes_read_rate_max_length`,
+        `disk_offering`.`bytes_write_rate` AS `bytes_write_rate`,
+        `disk_offering`.`bytes_write_rate_max` AS `bytes_write_rate_max`,
+        `disk_offering`.`bytes_write_rate_max_length` AS 
`bytes_write_rate_max_length`,
+        `disk_offering`.`iops_read_rate` AS `iops_read_rate`,
+        `disk_offering`.`iops_read_rate_max` AS `iops_read_rate_max`,
+        `disk_offering`.`iops_read_rate_max_length` AS 
`iops_read_rate_max_length`,
+        `disk_offering`.`iops_write_rate` AS `iops_write_rate`,
+        `disk_offering`.`iops_write_rate_max` AS `iops_write_rate_max`,
+        `disk_offering`.`iops_write_rate_max_length` AS 
`iops_write_rate_max_length`,
+        `disk_offering`.`cache_mode` AS `cache_mode`,
+        `disk_offering`.`disk_size` AS `root_disk_size`,
+        `service_offering`.`cpu` AS `cpu`,
+        `service_offering`.`speed` AS `speed`,
+        `service_offering`.`ram_size` AS `ram_size`,
+        `service_offering`.`nw_rate` AS `nw_rate`,
+        `service_offering`.`mc_rate` AS `mc_rate`,
+        `service_offering`.`ha_enabled` AS `ha_enabled`,
+        `service_offering`.`limit_cpu_use` AS `limit_cpu_use`,
+        `service_offering`.`host_tag` AS `host_tag`,
+        `service_offering`.`default_use` AS `default_use`,
+        `service_offering`.`vm_type` AS `vm_type`,
+        `service_offering`.`sort_key` AS `sort_key`,
+        `service_offering`.`is_volatile` AS `is_volatile`,
+        `service_offering`.`deployment_planner` AS `deployment_planner`,
+        `service_offering`.`dynamically_scalable` AS `dynamically_scalable`,
+        `vsphere_storage_policy`.`value` AS `vsphere_storage_policy`,
+        GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id,
+        GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid,
+        GROUP_CONCAT(DISTINCT(domain.name)) AS domain_name,
+        GROUP_CONCAT(DISTINCT(domain.path)) AS domain_path,
+        GROUP_CONCAT(DISTINCT(zone.id)) AS zone_id,
+        GROUP_CONCAT(DISTINCT(zone.uuid)) AS zone_uuid,
+        GROUP_CONCAT(DISTINCT(zone.name)) AS zone_name,
+        IFNULL(`min_compute_details`.`value`, `cpu`) AS min_cpu,
+        IFNULL(`max_compute_details`.`value`, `cpu`) AS max_cpu,
+        IFNULL(`min_memory_details`.`value`, `ram_size`) AS min_memory,
+        IFNULL(`max_memory_details`.`value`, `ram_size`) AS max_memory
+    FROM
+        `cloud`.`service_offering`
+            INNER JOIN
+        `cloud`.`disk_offering_view` AS `disk_offering` ON service_offering.id 
= disk_offering.id
+            LEFT JOIN
+        `cloud`.`service_offering_details` AS `domain_details` ON 
`domain_details`.`service_offering_id` = `disk_offering`.`id` AND 
`domain_details`.`name`='domainid'
+            LEFT JOIN
+        `cloud`.`domain` AS `domain` ON FIND_IN_SET(`domain`.`id`, 
`domain_details`.`value`)
+            LEFT JOIN
+        `cloud`.`service_offering_details` AS `zone_details` ON 
`zone_details`.`service_offering_id` = `disk_offering`.`id` AND 
`zone_details`.`name`='zoneid'
+            LEFT JOIN
+        `cloud`.`data_center` AS `zone` ON FIND_IN_SET(`zone`.`id`, 
`zone_details`.`value`)
+                       LEFT JOIN
+               `cloud`.`service_offering_details` AS `min_compute_details` ON 
`min_compute_details`.`service_offering_id` = `disk_offering`.`id`
+                               AND `min_compute_details`.`name` = 
'mincpunumber'
+                       LEFT JOIN
+               `cloud`.`service_offering_details` AS `max_compute_details` ON 
`max_compute_details`.`service_offering_id` = `disk_offering`.`id`
+                               AND `max_compute_details`.`name` = 
'maxcpunumber'
+                       LEFT JOIN
+               `cloud`.`service_offering_details` AS `min_memory_details` ON 
`min_memory_details`.`service_offering_id` = `disk_offering`.`id`
+                               AND `min_memory_details`.`name` = 'minmemory'
+                       LEFT JOIN
+               `cloud`.`service_offering_details` AS `max_memory_details` ON 
`max_memory_details`.`service_offering_id` = `disk_offering`.`id`
+                               AND `max_memory_details`.`name` = 'maxmemory'
+                       LEFT JOIN
+               `cloud`.`service_offering_details` AS `vsphere_storage_policy` 
ON `vsphere_storage_policy`.`service_offering_id` = `disk_offering`.`id`
+                               AND `vsphere_storage_policy`.`name` = 
'storagepolicy'
+    WHERE
+        `disk_offering`.`state`='Active'
+    GROUP BY
+        `service_offering`.`id`;
\ No newline at end of file
diff --git 
a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/ServiceOfferingVO.java
 
b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/ServiceOfferingVO.java
index 5ac401e..873aa38 100644
--- 
a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/ServiceOfferingVO.java
+++ 
b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/ServiceOfferingVO.java
@@ -75,6 +75,9 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
     @Column(name = "deployment_planner")
     private String deploymentPlanner = null;
 
+    @Column(name = "dynamically_scalable")
+    private boolean dynamicallyScalable;
+
     @Transient
     Map<String, String> details = new HashMap<String, String>();
 
@@ -284,4 +287,9 @@ public class ServiceOfferingVO extends DiskOfferingVO 
implements ServiceOffering
     public void setDynamicFlag(boolean isdynamic) {
         isDynamic = isdynamic;
     }
+
+    @Override
+    public boolean isDynamicallyScalable() {
+        return dynamicallyScalable;
+    }
 }
diff --git 
a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java
 
b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java
index b715f09..e998bf1 100644
--- 
a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java
+++ 
b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java
@@ -339,7 +339,7 @@ public class KubernetesClusterResourceModifierActionWorker 
extends KubernetesClu
         nodeVm = userVmService.createAdvancedVirtualMachine(zone, 
serviceOffering, clusterTemplate, networkIds, owner,
                 hostName, hostName, null, null, null,
                 Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, 
base64UserData, kubernetesCluster.getKeyPair(),
-                null, addrs, null, null, null, customParameterMap, null, null, 
null, null);
+                null, addrs, null, null, null, customParameterMap, null, null, 
null, null, true);
         if (LOGGER.isInfoEnabled()) {
             LOGGER.info(String.format("Created node VM : %s, %s in the 
Kubernetes cluster : %s", hostName, nodeVm.getUuid(), 
kubernetesCluster.getName()));
         }
diff --git 
a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java
 
b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java
index 855c264..a1d533b 100644
--- 
a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java
+++ 
b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java
@@ -72,6 +72,7 @@ import com.cloud.vm.Nic;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.ReservationContextImpl;
 import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.UserVmManager;
 import com.google.common.base.Strings;
 
 public class KubernetesClusterStartWorker extends 
KubernetesClusterResourceModifierActionWorker {
@@ -208,10 +209,11 @@ public class KubernetesClusterStartWorker extends 
KubernetesClusterResourceModif
             logAndThrow(Level.ERROR, "Failed to read Kubernetes master 
configuration file", e);
         }
         String base64UserData = 
Base64.encodeBase64String(k8sMasterConfig.getBytes(StringUtils.getPreferredCharset()));
+        Boolean dynamicScalingEnabled = 
serviceOffering.isDynamicallyScalable() && 
clusterTemplate.isDynamicallyScalable() && 
UserVmManager.EnableDynamicallyScaleVm.valueIn(zone.getId());
         masterVm = userVmService.createAdvancedVirtualMachine(zone, 
serviceOffering, clusterTemplate, networkIds, owner,
                 hostName, hostName, null, null, null,
                 Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, 
base64UserData, kubernetesCluster.getKeyPair(),
-                requestedIps, addrs, null, null, null, customParameterMap, 
null, null, null, null);
+                requestedIps, addrs, null, null, null, customParameterMap, 
null, null, null, null, dynamicScalingEnabled);
         if (LOGGER.isInfoEnabled()) {
             LOGGER.info(String.format("Created master VM ID: %s, %s in the 
Kubernetes cluster : %s", masterVm.getUuid(), hostName, 
kubernetesCluster.getName()));
         }
@@ -262,10 +264,11 @@ public class KubernetesClusterStartWorker extends 
KubernetesClusterResourceModif
             logAndThrow(Level.ERROR, "Failed to read Kubernetes master 
configuration file", e);
         }
         String base64UserData = 
Base64.encodeBase64String(k8sMasterConfig.getBytes(StringUtils.getPreferredCharset()));
+        Boolean dynamicScalingEnabled = 
serviceOffering.isDynamicallyScalable() && 
clusterTemplate.isDynamicallyScalable() && 
UserVmManager.EnableDynamicallyScaleVm.valueIn(zone.getId());
         additionalMasterVm = userVmService.createAdvancedVirtualMachine(zone, 
serviceOffering, clusterTemplate, networkIds, owner,
                 hostName, hostName, null, null, null,
                 Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, 
base64UserData, kubernetesCluster.getKeyPair(),
-                null, addrs, null, null, null, customParameterMap, null, null, 
null, null);
+                null, addrs, null, null, null, customParameterMap, null, null, 
null, null, dynamicScalingEnabled);
         if (LOGGER.isInfoEnabled()) {
             LOGGER.info(String.format("Created master VM ID : %s, %s in the 
Kubernetes cluster : %s", additionalMasterVm.getUuid(), hostName, 
kubernetesCluster.getName()));
         }
diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java 
b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
index b03fa7d..8657038 100644
--- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
@@ -1415,6 +1415,7 @@ public class ApiResponseHelper implements 
ResponseGenerator {
                 vmResponse.setState(vm.getState().toString());
             }
 
+            vmResponse.setDynamicallyScalable(vm.isDynamicallyScalable());
             // for console proxies, add the active sessions
             if (vm.getType() == Type.ConsoleProxy) {
                 ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
diff --git 
a/server/src/main/java/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java 
b/server/src/main/java/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java
index 87b0374..7692f54 100644
--- 
a/server/src/main/java/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java
+++ 
b/server/src/main/java/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java
@@ -113,6 +113,7 @@ public class ServiceOfferingJoinDaoImpl extends 
GenericDaoBase<ServiceOfferingJo
         offeringResponse.setObjectName("serviceoffering");
         offeringResponse.setIscutomized(offering.isDynamic());
         offeringResponse.setCacheMode(offering.getCacheMode());
+        
offeringResponse.setDynamicscalingenabled(offering.isDynamicallyScalable());
 
         if (offeringDetails != null && !offeringDetails.isEmpty()) {
             String vsphereStoragePolicyId = 
offeringDetails.get(ApiConstants.STORAGE_POLICY);
diff --git 
a/server/src/main/java/com/cloud/api/query/vo/ServiceOfferingJoinVO.java 
b/server/src/main/java/com/cloud/api/query/vo/ServiceOfferingJoinVO.java
index 4d9b2cd..e549bac 100644
--- a/server/src/main/java/com/cloud/api/query/vo/ServiceOfferingJoinVO.java
+++ b/server/src/main/java/com/cloud/api/query/vo/ServiceOfferingJoinVO.java
@@ -193,6 +193,9 @@ public class ServiceOfferingJoinVO extends BaseViewVO 
implements InternalIdentit
     @Column(name = "root_disk_size")
     private Long rootDiskSize;
 
+    @Column(name = "dynamically_scalable")
+    private boolean dynamicallyScalable;
+
     public ServiceOfferingJoinVO() {
     }
 
@@ -397,4 +400,12 @@ public class ServiceOfferingJoinVO extends BaseViewVO 
implements InternalIdentit
     public Long getRootDiskSize() {
         return rootDiskSize ;
     }
+
+    public boolean isDynamicallyScalable() {
+        return dynamicallyScalable;
+    }
+
+    public void setDynamicallyScalable(boolean dynamicallyScalable) {
+        this.dynamicallyScalable = dynamicallyScalable;
+    }
 }
diff --git 
a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java 
b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
index 1db461d..3f6991b 100755
--- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2480,7 +2480,7 @@ public class ConfigurationManagerImpl extends ManagerBase 
implements Configurati
                 cmd.getBytesWriteRate(), cmd.getBytesWriteRateMax(), 
cmd.getBytesWriteRateMaxLength(),
                 cmd.getIopsReadRate(), cmd.getIopsReadRateMax(), 
cmd.getIopsReadRateMaxLength(),
                 cmd.getIopsWriteRate(), cmd.getIopsWriteRateMax(), 
cmd.getIopsWriteRateMaxLength(),
-                cmd.getHypervisorSnapshotReserve(), cmd.getCacheMode(), 
storagePolicyId);
+                cmd.getHypervisorSnapshotReserve(), cmd.getCacheMode(), 
storagePolicyId, cmd.getDynamicScalingEnabled());
     }
 
     protected ServiceOfferingVO createServiceOffering(final long userId, final 
boolean isSystem, final VirtualMachine.Type vmType,
@@ -2491,7 +2491,7 @@ public class ConfigurationManagerImpl extends ManagerBase 
implements Configurati
             Long bytesWriteRate, Long bytesWriteRateMax, Long 
bytesWriteRateMaxLength,
             Long iopsReadRate, Long iopsReadRateMax, Long 
iopsReadRateMaxLength,
             Long iopsWriteRate, Long iopsWriteRateMax, Long 
iopsWriteRateMaxLength,
-            final Integer hypervisorSnapshotReserve, String cacheMode, final 
Long storagePolicyID) {
+            final Integer hypervisorSnapshotReserve, String cacheMode, final 
Long storagePolicyID, final Boolean dynamicScalingEnabled) {
         // Filter child domains when both parent and child domains are present
         List<Long> filteredDomainIds = filterChildSubDomains(domainIds);
 
@@ -2523,7 +2523,7 @@ public class ConfigurationManagerImpl extends ManagerBase 
implements Configurati
 
         ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, 
speed, networkRate, null, offerHA,
                 limitResourceUse, volatileVm, displayText, 
typedProvisioningType, localStorageRequired, false, tags, isSystem, vmType,
-                hostTag, deploymentPlanner);
+                hostTag, deploymentPlanner, dynamicScalingEnabled);
 
         if (Boolean.TRUE.equals(isCustomizedIops) || isCustomizedIops == null) 
{
                 minIops = null;
diff --git a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java 
b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java
index 2ae35fc..3e3885d 100644
--- a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java
+++ b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java
@@ -52,7 +52,6 @@ import com.cloud.utils.StringUtils;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
-import com.cloud.vm.UserVmManager;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
@@ -240,7 +239,7 @@ public abstract class HypervisorGuruBase extends 
AdapterBase implements Hypervis
         // Workaround to make sure the TO has the UUID we need for Niciri 
integration
         VMInstanceVO vmInstance = _virtualMachineDao.findById(to.getId());
         // check if XStools/VMWare tools are present in the VM and dynamic 
scaling feature is enabled (per zone/global)
-        Boolean isDynamicallyScalable = vmInstance.isDynamicallyScalable() && 
UserVmManager.EnableDynamicallyScaleVm.valueIn(vm.getDataCenterId());
+        Boolean isDynamicallyScalable = vmInstance.isDynamicallyScalable();
         to.setEnableDynamicallyScaleVm(isDynamicallyScalable);
         to.setUuid(vmInstance.getUuid());
 
diff --git 
a/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java 
b/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java
index c710549..5e7f0a9 100644
--- a/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java
+++ b/server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java
@@ -1325,18 +1325,18 @@ public class AutoScaleManagerImpl<Type> extends 
ManagerBase implements AutoScale
                 vm = 
_userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, 
template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" +
                     getCurrentTimeStampString(),
                     "autoScaleVm-" + asGroup.getId() + "-" + 
getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, 
HTTPMethod.GET, null, null, null,
-                    null, true, null, null, null, null, null, null, null);
+                    null, true, null, null, null, null, null, null, null, 
true);
             } else {
                 if (zone.isSecurityGroupEnabled()) {
                     vm = 
_userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, 
template, null, null,
                         owner, "autoScaleVm-" + asGroup.getId() + "-" + 
getCurrentTimeStampString(),
                         "autoScaleVm-" + asGroup.getId() + "-" + 
getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, 
HTTPMethod.GET, null, null,
-                        null, null, true, null, null, null, null, null, null, 
null);
+                        null, null, true, null, null, null, null, null, null, 
null, true);
 
                 } else {
                     vm = _userVmService.createAdvancedVirtualMachine(zone, 
serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" +
                         getCurrentTimeStampString(), "autoScaleVm-" + 
asGroup.getId() + "-" + getCurrentTimeStampString(),
-                        null, null, null, HypervisorType.XenServer, 
HTTPMethod.GET, null, null, null, addrs, true, null, null, null, null, null, 
null, null);
+                        null, null, null, HypervisorType.XenServer, 
HTTPMethod.GET, null, null, null, addrs, true, null, null, null, null, null, 
null, null, true);
 
                 }
             }
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index 286fe2e..96daf19 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -1850,6 +1850,10 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering);
 
         ServiceOfferingVO currentServiceOffering = 
_offeringDao.findByIdIncludingRemoved(vmInstance.getId(), 
vmInstance.getServiceOfferingId());
+        if (newServiceOffering.isDynamicallyScalable() != 
currentServiceOffering.isDynamicallyScalable()) {
+            throw new InvalidParameterValueException("Unable to Scale VM: 
since dynamicscalingenabled flag is not same for new service offering and old 
service offering");
+        }
+
         int newCpu = newServiceOffering.getCpu();
         int newMemory = newServiceOffering.getRamSize();
         int newSpeed = newServiceOffering.getSpeed();
@@ -2716,10 +2720,6 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             userData = vm.getUserData();
         }
 
-        if (isDynamicallyScalable == null) {
-            isDynamicallyScalable = vm.isDynamicallyScalable();
-        }
-
         if (osTypeId == null) {
             osTypeId = vm.getGuestOSId();
         }
@@ -2730,6 +2730,15 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
         if (isDynamicallyScalable == null) {
             isDynamicallyScalable = vm.isDynamicallyScalable();
+        } else {
+            if (isDynamicallyScalable == true) {
+                if (!offering.isDynamicallyScalable()) {
+                    throw new InvalidParameterValueException("Dynamic Scaling 
cannot be enabled on the VM since service offering is not dynamic scaling 
enabled");
+                }
+                if 
(!UserVmManager.EnableDynamicallyScaleVm.valueIn(vm.getDataCenterId())) {
+                    throw new InvalidParameterValueException("Dynamic Scaling 
cannot be enabled on the VM since global configuration 
\"enable.dynamic.scale.vm\" is false");
+                }
+            }
         }
 
         boolean isVMware = (vm.getHypervisorType() == HypervisorType.VMware);
@@ -3180,7 +3189,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             Account owner, String hostName, String displayName, Long 
diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, 
HTTPMethod httpmethod,
             String userData, String sshKeyPair, Map<Long, IpAddresses> 
requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, 
List<Long> affinityGroupIdList,
             Map<String, String> customParametes, String customId, Map<String, 
Map<Integer, String>> dhcpOptionMap,
-            Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap, 
Map<String, String> userVmOVFProperties) throws InsufficientCapacityException, 
ConcurrentOperationException, ResourceUnavailableException,
+            Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap, 
Map<String, String> userVmOVFProperties, Boolean dynamicScalingEnabled) throws 
InsufficientCapacityException, ConcurrentOperationException, 
ResourceUnavailableException,
     StorageUnavailableException, ResourceAllocationException {
 
         Account caller = CallContext.current().getCallingAccount();
@@ -3229,7 +3238,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
         return createVirtualMachine(zone, serviceOffering, template, hostName, 
displayName, owner, diskOfferingId, diskSize, networkList, securityGroupIdList, 
group, httpmethod,
                 userData, sshKeyPair, hypervisor, caller, requestedIps, 
defaultIps, displayVm, keyboard, affinityGroupIdList, customParametes, 
customId, dhcpOptionMap,
-                dataDiskTemplateToDiskOfferingMap, userVmOVFProperties);
+                dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, 
dynamicScalingEnabled);
 
     }
 
@@ -3239,7 +3248,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             List<Long> securityGroupIdList, Account owner, String hostName, 
String displayName, Long diskOfferingId, Long diskSize, String group, 
HypervisorType hypervisor,
             HTTPMethod httpmethod, String userData, String sshKeyPair, 
Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, 
String keyboard,
             List<Long> affinityGroupIdList, Map<String, String> 
customParameters, String customId, Map<String, Map<Integer, String>> 
dhcpOptionMap,
-            Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap, 
Map<String, String> userVmOVFProperties) throws InsufficientCapacityException, 
ConcurrentOperationException,
+            Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap, 
Map<String, String> userVmOVFProperties, Boolean dynamicScalingEnabled) throws 
InsufficientCapacityException, ConcurrentOperationException,
     ResourceUnavailableException, StorageUnavailableException, 
ResourceAllocationException {
 
         Account caller = CallContext.current().getCallingAccount();
@@ -3340,7 +3349,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
         return createVirtualMachine(zone, serviceOffering, template, hostName, 
displayName, owner, diskOfferingId, diskSize, networkList, securityGroupIdList, 
group, httpmethod,
                 userData, sshKeyPair, hypervisor, caller, requestedIps, 
defaultIps, displayVm, keyboard, affinityGroupIdList, customParameters, 
customId, dhcpOptionMap, dataDiskTemplateToDiskOfferingMap,
-                userVmOVFProperties);
+                userVmOVFProperties, dynamicScalingEnabled);
     }
 
     @Override
@@ -3349,7 +3358,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             String hostName, String displayName, Long diskOfferingId, Long 
diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, 
String userData,
             String sshKeyPair, Map<Long, IpAddresses> requestedIps, 
IpAddresses defaultIps, Boolean displayvm, String keyboard, List<Long> 
affinityGroupIdList,
             Map<String, String> customParametrs, String customId, Map<String, 
Map<Integer, String>> dhcpOptionsMap, Map<Long, DiskOffering> 
dataDiskTemplateToDiskOfferingMap,
-            Map<String, String> userVmOVFPropertiesMap) throws 
InsufficientCapacityException, ConcurrentOperationException, 
ResourceUnavailableException,
+            Map<String, String> userVmOVFPropertiesMap, Boolean 
dynamicScalingEnabled) throws InsufficientCapacityException, 
ConcurrentOperationException, ResourceUnavailableException,
     StorageUnavailableException, ResourceAllocationException {
 
         Account caller = CallContext.current().getCallingAccount();
@@ -3401,7 +3410,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
         return createVirtualMachine(zone, serviceOffering, template, hostName, 
displayName, owner, diskOfferingId, diskSize, networkList, null, group, 
httpmethod, userData,
                 sshKeyPair, hypervisor, caller, requestedIps, defaultIps, 
displayvm, keyboard, affinityGroupIdList, customParametrs, customId, 
dhcpOptionsMap,
-                dataDiskTemplateToDiskOfferingMap, userVmOVFPropertiesMap);
+                dataDiskTemplateToDiskOfferingMap, userVmOVFPropertiesMap, 
dynamicScalingEnabled);
     }
 
     private NetworkVO getNetworkToAddToNetworkList(VirtualMachineTemplate 
template, Account owner, HypervisorType hypervisor,
@@ -3516,11 +3525,11 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
     @DB
     private UserVm createVirtualMachine(DataCenter zone, ServiceOffering 
serviceOffering, VirtualMachineTemplate tmplt, String hostName, String 
displayName, Account owner,
-            Long diskOfferingId, Long diskSize, List<NetworkVO> networkList, 
List<Long> securityGroupIdList, String group, HTTPMethod httpmethod, String 
userData,
-            String sshKeyPair, HypervisorType hypervisor, Account caller, 
Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean 
isDisplayVm, String keyboard,
-            List<Long> affinityGroupIdList, Map<String, String> 
customParameters, String customId, Map<String, Map<Integer, String>> 
dhcpOptionMap,
-            Map<Long, DiskOffering> datadiskTemplateToDiskOfferringMap,
-            Map<String, String> userVmOVFPropertiesMap) throws 
InsufficientCapacityException, ResourceUnavailableException,
+                                        Long diskOfferingId, Long diskSize, 
List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, 
HTTPMethod httpmethod, String userData,
+                                        String sshKeyPair, HypervisorType 
hypervisor, Account caller, Map<Long, IpAddresses> requestedIps, IpAddresses 
defaultIps, Boolean isDisplayVm, String keyboard,
+                                        List<Long> affinityGroupIdList, 
Map<String, String> customParameters, String customId, Map<String, Map<Integer, 
String>> dhcpOptionMap,
+                                        Map<Long, DiskOffering> 
datadiskTemplateToDiskOfferringMap,
+                                        Map<String, String> 
userVmOVFPropertiesMap, Boolean dynamicScalingEnabled) throws 
InsufficientCapacityException, ResourceUnavailableException,
     ConcurrentOperationException, StorageUnavailableException, 
ResourceAllocationException {
 
         _accountMgr.checkAccess(caller, null, true, owner);
@@ -3873,9 +3882,11 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             }
         }
 
+        dynamicScalingEnabled = 
checkIfDynamicScalingCanBeEnabled(dynamicScalingEnabled, offering, template, 
zone.getId());
+
         UserVmVO vm = commitUserVm(zone, template, hostName, displayName, 
owner, diskOfferingId, diskSize, userData, caller, isDisplayVm, keyboard, 
accountId, userId, offering,
                 isIso, sshPublicKey, networkNicMap, id, instanceName, 
uuidName, hypervisorType, customParameters, dhcpOptionMap,
-                datadiskTemplateToDiskOfferringMap, userVmOVFPropertiesMap);
+                datadiskTemplateToDiskOfferringMap, userVmOVFPropertiesMap, 
dynamicScalingEnabled);
 
         // Assign instance to the group
         try {
@@ -3899,6 +3910,15 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         return vm;
     }
 
+    private Boolean checkIfDynamicScalingCanBeEnabled(Boolean 
dynamicScalingEnabled, ServiceOfferingVO offering, VMTemplateVO template, Long 
zoneId) {
+        if (dynamicScalingEnabled) {
+            if (!(offering.isDynamicallyScalable() && 
template.isDynamicallyScalable() && 
UserVmManager.EnableDynamicallyScaleVm.valueIn(zoneId))) {
+                s_logger.info("VM cannot be configured to be dynamically 
scalable if any of the service offering's dynamic scaling property, template's 
dynamic scaling property or global setting is false");
+            }
+        }
+        return dynamicScalingEnabled && offering.isDynamicallyScalable() && 
template.isDynamicallyScalable() && 
UserVmManager.EnableDynamicallyScaleVm.valueIn(zoneId);
+    }
+
     /**
      * Configures the Root disk size via User`s custom parameters.
      * If the Service Offering has the Root Disk size field configured then 
the User`s root disk custom parameter is overwritten by the service offering.
@@ -3977,14 +3997,14 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                                   final long accountId, final long userId, 
final ServiceOffering offering, final boolean isIso, final String sshPublicKey, 
final LinkedHashMap<String, List<NicProfile>> networkNicMap,
                                   final long id, final String instanceName, 
final String uuidName, final HypervisorType hypervisorType, final Map<String, 
String> customParameters,
                                   final Map<String, Map<Integer, String>> 
extraDhcpOptionMap, final Map<Long, DiskOffering> 
dataDiskTemplateToDiskOfferingMap,
-                                  final Map<String, String> 
userVmOVFPropertiesMap, final VirtualMachine.PowerState powerState) throws 
InsufficientCapacityException {
+                                  final Map<String, String> 
userVmOVFPropertiesMap, final VirtualMachine.PowerState powerState, final 
Boolean dynamicScalingEnabled) throws InsufficientCapacityException {
         return Transaction.execute(new 
TransactionCallbackWithException<UserVmVO, InsufficientCapacityException>() {
             @Override
             public UserVmVO doInTransaction(TransactionStatus status) throws 
InsufficientCapacityException {
                 UserVmVO vm = new UserVmVO(id, instanceName, displayName, 
template.getId(), hypervisorType, template.getGuestOSId(), offering.isOfferHA(),
                         offering.getLimitCpuUse(), owner.getDomainId(), 
owner.getId(), userId, offering.getId(), userData, hostName, diskOfferingId);
                 vm.setUuid(uuidName);
-                vm.setDynamicallyScalable(template.isDynamicallyScalable());
+                vm.setDynamicallyScalable(dynamicScalingEnabled);
 
                 Map<String, String> details = template.getDetails();
                 if (details != null && !details.isEmpty()) {
@@ -4164,13 +4184,13 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             final long accountId, final long userId, final ServiceOfferingVO 
offering, final boolean isIso, final String sshPublicKey, final 
LinkedHashMap<String, List<NicProfile>> networkNicMap,
             final long id, final String instanceName, final String uuidName, 
final HypervisorType hypervisorType, final Map<String, String> 
customParameters, final Map<String,
             Map<Integer, String>> extraDhcpOptionMap, final Map<Long, 
DiskOffering> dataDiskTemplateToDiskOfferingMap,
-            Map<String, String> userVmOVFPropertiesMap) throws 
InsufficientCapacityException {
+            Map<String, String> userVmOVFPropertiesMap, final Boolean 
dynamicScalingEnabled) throws InsufficientCapacityException {
         return commitUserVm(false, zone, null, null, template, hostName, 
displayName, owner,
                 diskOfferingId, diskSize, userData, caller, isDisplayVm, 
keyboard,
                 accountId, userId, offering, isIso, sshPublicKey, 
networkNicMap,
                 id, instanceName, uuidName, hypervisorType, customParameters,
                 extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap,
-                userVmOVFPropertiesMap, null);
+                userVmOVFPropertiesMap, null, dynamicScalingEnabled);
     }
 
     public void validateRootDiskResize(final HypervisorType hypervisorType, 
Long rootDiskSize, VMTemplateVO templateVO, UserVmVO vm, final Map<String, 
String> customParameters) throws InvalidParameterValueException
@@ -5253,6 +5273,8 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             }
         }
 
+        Boolean dynamicScalingEnabled = cmd.getDynamicScalingEnabled();
+
         VirtualMachineTemplate template = 
_entityMgr.findById(VirtualMachineTemplate.class, templateId);
         // Make sure a valid template ID was specified
         if (template == null) {
@@ -5310,14 +5332,14 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                 vm = createBasicSecurityGroupVirtualMachine(zone, 
serviceOffering, template, getSecurityGroupIdList(cmd), owner, name, 
displayName, diskOfferingId,
                         size , group , cmd.getHypervisor(), 
cmd.getHttpMethod(), userData , sshKeyPairName , cmd.getIpToNetworkMap(), 
addrs, displayVm , keyboard , cmd.getAffinityGroupIdList(),
                         cmd.getDetails(), cmd.getCustomId(), 
cmd.getDhcpOptionsMap(),
-                        dataDiskTemplateToDiskOfferingMap, 
userVmOVFProperties);
+                        dataDiskTemplateToDiskOfferingMap, 
userVmOVFProperties, dynamicScalingEnabled);
             }
         } else {
             if (zone.isSecurityGroupEnabled())  {
                 vm = createAdvancedSecurityGroupVirtualMachine(zone, 
serviceOffering, template, networkIds, getSecurityGroupIdList(cmd), owner, name,
                         displayName, diskOfferingId, size, group, 
cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, 
cmd.getIpToNetworkMap(), addrs, displayVm, keyboard,
                         cmd.getAffinityGroupIdList(), cmd.getDetails(), 
cmd.getCustomId(), cmd.getDhcpOptionsMap(),
-                        dataDiskTemplateToDiskOfferingMap, 
userVmOVFProperties);
+                        dataDiskTemplateToDiskOfferingMap, 
userVmOVFProperties, dynamicScalingEnabled);
 
             } else {
                 if (cmd.getSecurityGroupIdList() != null && 
!cmd.getSecurityGroupIdList().isEmpty()) {
@@ -5325,7 +5347,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                 }
                 vm = createAdvancedVirtualMachine(zone, serviceOffering, 
template, networkIds, owner, name, displayName, diskOfferingId, size, group,
                         cmd.getHypervisor(), cmd.getHttpMethod(), userData, 
sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, 
cmd.getAffinityGroupIdList(), cmd.getDetails(),
-                        cmd.getCustomId(), cmd.getDhcpOptionsMap(), 
dataDiskTemplateToDiskOfferingMap, userVmOVFProperties);
+                        cmd.getCustomId(), cmd.getDhcpOptionsMap(), 
dataDiskTemplateToDiskOfferingMap, userVmOVFProperties, dynamicScalingEnabled);
             }
         }
         // check if this templateId has a child ISO
@@ -7351,11 +7373,12 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
         final String uuidName = _uuidMgr.generateUuid(UserVm.class, null);
         final Host lastHost = powerState != VirtualMachine.PowerState.PowerOn 
? host : null;
+        final Boolean dynamicScalingEnabled = 
serviceOffering.isDynamicallyScalable() && template.isDynamicallyScalable() && 
UserVmManager.EnableDynamicallyScaleVm.valueIn(zone.getId());
         return commitUserVm(true, zone, host, lastHost, template, hostName, 
displayName, owner,
                 null, null, userData, caller, isDisplayVm, keyboard,
                 accountId, userId, serviceOffering, 
template.getFormat().equals(ImageFormat.ISO), sshPublicKey, null,
                 id, instanceName, uuidName, hypervisorType, customParameters,
-                null, null, null, powerState);
+                null, null, null, powerState, dynamicScalingEnabled);
     }
 
     @Override
diff --git 
a/server/src/test/java/com/cloud/vm/DeploymentPlanningManagerImplTest.java 
b/server/src/test/java/com/cloud/vm/DeploymentPlanningManagerImplTest.java
index d356570..20e9ea6 100644
--- a/server/src/test/java/com/cloud/vm/DeploymentPlanningManagerImplTest.java
+++ b/server/src/test/java/com/cloud/vm/DeploymentPlanningManagerImplTest.java
@@ -196,7 +196,7 @@ public class DeploymentPlanningManagerImplTest {
         ServiceOfferingVO svcOffering =
             new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, 
false, false, "test dpm",
                     ProvisioningType.THIN, false, false, null, false, 
VirtualMachine.Type.User,
-                    null, "FirstFitPlanner");
+                    null, "FirstFitPlanner", true);
         Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
 
         DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
@@ -211,7 +211,7 @@ public class DeploymentPlanningManagerImplTest {
         ServiceOfferingVO svcOffering =
             new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, 
false, false, "test dpm",
                     ProvisioningType.THIN, false, false, null, false, 
VirtualMachine.Type.User,
-                    null, "UserDispersingPlanner");
+                    null, "UserDispersingPlanner", true);
         Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
 
         DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
@@ -227,7 +227,7 @@ public class DeploymentPlanningManagerImplTest {
         ServiceOfferingVO svcOffering =
             new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, 
false, false, "test dpm",
                 ProvisioningType.THIN, false, false, null, false, 
VirtualMachine.Type.User,
-                    null, "FirstFitPlanner");
+                    null, "FirstFitPlanner", true);
         Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
 
         DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);

Reply via email to