Updated Branches:
  refs/heads/4.3 cb70ed155 -> 089c7bc9f

CLOUDSTACK-5161 use a map to specify the custom parameters instead of having 
one parameter each


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/089c7bc9
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/089c7bc9
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/089c7bc9

Branch: refs/heads/4.3
Commit: 089c7bc9f8f0861bb2eedc340ae623f5abeccfc3
Parents: cb70ed1
Author: Bharat Kumar <bharat.ku...@citrix.com>
Authored: Thu Nov 28 12:34:16 2013 +0530
Committer: Jayapal <jaya...@apache.org>
Committed: Tue Dec 3 16:53:58 2013 +0530

----------------------------------------------------------------------
 api/src/com/cloud/vm/UserVmService.java         |  27 ++--
 .../api/command/user/vm/DeployVMCmd.java        |  66 ++++-----
 .../service/VolumeOrchestrationService.java     |   2 +-
 .../service/api/OrchestrationService.java       |   4 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java |   2 +-
 .../engine/orchestration/CloudOrchestrator.java |   3 +-
 .../orchestration/VolumeOrchestrator.java       |   5 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 135 +++++++------------
 8 files changed, 100 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/api/src/com/cloud/vm/UserVmService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/UserVmService.java 
b/api/src/com/cloud/vm/UserVmService.java
index 6fc8b54..e6ca719 100755
--- a/api/src/com/cloud/vm/UserVmService.java
+++ b/api/src/com/cloud/vm/UserVmService.java
@@ -203,11 +203,11 @@ public interface UserVmService {
      *             available.
      * @throws InsufficientResourcesException
      */
-    UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, 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 defaultIp, 
Boolean displayVm, String keyboard, List<Long> affinityGroupIdList, Integer 
cpuSpeed, Integer memory, Integer cpuNumber, Long rootdisksize)
-            throws InsufficientCapacityException, 
ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException;
+    UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, 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 defaultIp, Boolean 
displayVm, String keyboard,
+                                                  List<Long> 
affinityGroupIdList, Map<String, String> customParameter) throws 
InsufficientCapacityException,
+        ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException;
 
     /**
      * Creates a User VM in Advanced Zone (Security Group feature is enabled) 
in
@@ -282,10 +282,11 @@ public interface UserVmService {
      *             available.
      * @throws InsufficientResourcesException
      */
-    UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> 
networkIdList, 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, Integer cpuSpeed, Integer memory, Integer 
cpuNumber, Long rootdisksize)
-            throws InsufficientCapacityException, 
ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException;
+    UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> 
networkIdList,
+                                                     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) throws 
InsufficientCapacityException,
+        ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException;
 
     /**
      * Creates a User VM in Advanced Zone (Security Group feature is disabled)
@@ -357,10 +358,10 @@ public interface UserVmService {
      *             available.
      * @throws InsufficientResourcesException
      */
-    UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering 
serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, 
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, Integer cpuSpeed, 
Integer memory, Integer cpuNumber, Long rootdkisksize)
+    UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering 
serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, 
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)
 
             throws InsufficientCapacityException, 
ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java 
b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index 3643f91..a8a21ab 100755
--- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -188,17 +188,11 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
     @Parameter(name=ApiConstants.DISPLAY_VM, type=CommandType.BOOLEAN, 
since="4.2", description="an optional field, whether to the display the vm to 
the end user or not.")
     private Boolean displayVm;
 
-    @Parameter(name=ApiConstants.CPU_SPEED, type = CommandType.INTEGER, 
since="4.3", description = "optional field to specify the cpu speed when using 
dynamic compute offering.")
-    private Integer cpuSpeed;
-
-    @Parameter(name=ApiConstants.MEMORY, type = CommandType.INTEGER, 
since="4.3", description = "optional field to specify the memory when using 
dynamic compute offering")
-    private Integer memory;
-
-    @Parameter(name=ApiConstants.CPU_NUMBER, type=CommandType.INTEGER, 
since="4.3", description = "optional field to specify the number of cpu cores 
when using dynamic offering.")
-    private Integer cpuNumber;
-
-    @Parameter(name=ApiConstants.ROOT_DISK_SIZE, type=CommandType.LONG, 
since="4.3", description = "optional field to specify the number of cpu cores 
when using dynamic offering.")
-    private Long rootdisksize;
+    @Parameter(name = ApiConstants.CUSTOM_PARAMETERS,
+               type = CommandType.MAP,
+               since= "4.3",
+               description = "used to specify the custom parameters.")
+    private  Map customParameters;
 
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
@@ -227,6 +221,21 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
         return domainId;
     }
 
+    public Map<String, String> getCustomParameters() {
+        Map<String,String> customparameterMap = new HashMap<String, String>();
+        if (customParameters != null && customParameters.size() !=0){
+            Collection parameterCollection = customParameters.values();
+            Iterator iter = parameterCollection.iterator();
+            while (iter.hasNext()) {
+                HashMap<String, String> value = (HashMap<String, String>) 
iter.next();
+                for (String key : value.keySet()) {
+                    customparameterMap.put(key, value.get(key));
+                }
+            }
+        }
+        return customparameterMap;
+    }
+
     public String getGroup() {
         return group;
     }
@@ -239,21 +248,6 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
         return displayVm;
     }
 
-    public Integer getMemory() {
-        return memory;
-    }
-
-    public Integer getCpuSpeed() {
-        return cpuSpeed;
-    }
-
-    public Integer getCpuNumber() {
-        return cpuNumber;
-    }
-
-    public Long getRootdisksize() {
-        return rootdisksize;
-    }
 
     public List<Long> getSecurityGroupIdList() {
         if (securityGroupNameList != null && securityGroupIdList != null) {
@@ -522,20 +516,26 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
                 if (getNetworkIds() != null) {
                     throw new InvalidParameterValueException("Can't specify 
network Ids in Basic zone");
                 } else {
-                    vm = 
_userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, 
template, getSecurityGroupIdList(), owner, name,
-                            displayName, diskOfferingId, size, group, 
getHypervisor(), getHttpMethod(), userData, sshKeyPairName, 
getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList(), 
cpuSpeed, memory, cpuNumber, rootdisksize);
+                    vm =
+                        
_userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, 
template, getSecurityGroupIdList(), owner, name, displayName,
+                            diskOfferingId, size, group, getHypervisor(), 
getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, 
displayVm, keyboard,
+                            getAffinityGroupIdList(), getCustomParameters());
                 }
             } else {
-                if (zone.isSecurityGroupEnabled())  {
-                    vm = 
_userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, 
template, getNetworkIds(), getSecurityGroupIdList(),
-                            owner, name, displayName, diskOfferingId, size, 
group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, 
getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList(), 
cpuSpeed, memory, cpuNumber, rootdisksize );
+                if (zone.isSecurityGroupEnabled()) {
+                    vm =
+                        
_userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, 
template, getNetworkIds(), getSecurityGroupIdList(), owner, name,
+                            displayName, diskOfferingId, size, group, 
getHypervisor(), getHttpMethod(), userData, sshKeyPairName, 
getIpToNetworkMap(), addrs, displayVm,
+                            keyboard, getAffinityGroupIdList(), 
getCustomParameters());
 
                 } else {
                     if (getSecurityGroupIdList() != null && 
!getSecurityGroupIdList().isEmpty()) {
                         throw new InvalidParameterValueException("Can't create 
vm with security groups; security group feature is not enabled per zone");
                     }
-                    vm = _userVmService.createAdvancedVirtualMachine(zone, 
serviceOffering, template, getNetworkIds(), owner, name, displayName,
-                            diskOfferingId, size, group, getHypervisor(), 
getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, 
displayVm, keyboard, getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, 
rootdisksize);
+                    vm =
+                        _userVmService.createAdvancedVirtualMachine(zone, 
serviceOffering, template, getNetworkIds(), owner, name, displayName, 
diskOfferingId, size,
+                            group, getHypervisor(), getHttpMethod(), userData, 
sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, 
getAffinityGroupIdList(),
+                            getCustomParameters());
 
                 }
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java
----------------------------------------------------------------------
diff --git 
a/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java
 
b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java
index ad957d5..a773ac4 100644
--- 
a/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java
+++ 
b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java
@@ -86,7 +86,7 @@ public interface VolumeOrchestrationService {
 
     boolean canVmRestartOnAnotherServer(long vmId);
 
-    DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering 
offering, Long rootDisksize, VirtualMachineTemplate template, VirtualMachine 
vm, Account owner);
+    DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering 
offering, VirtualMachineTemplate template, VirtualMachine vm, Account owner);
 
     String getVmNameFromVolumeId(long volumeId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
----------------------------------------------------------------------
diff --git 
a/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
 
b/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
index 8c58227..64ef063 100755
--- 
a/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
+++ 
b/engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java
@@ -55,7 +55,6 @@ public interface OrchestrationService {
      * @param computeTags tags for the compute
      * @param rootDiskTags tags for the root disk
      * @param networks networks that this VM should join
-     * @param rootDiskSize size the root disk in case of templates.
      * @return VirtualMachineEntity
      */
     @POST
@@ -74,8 +73,7 @@ public interface OrchestrationService {
             @QueryParam("compute-tags") List<String> computeTags,
             @QueryParam("root-disk-tags") List<String> rootDiskTags,
             @QueryParam("network-nic-map") Map<String, NicProfile> 
networkNicMap,
-            @QueryParam("deploymentplan") DeploymentPlan plan,
-            @QueryParam("root-disk-size") Long rootDiskSize
+            @QueryParam("deploymentplan") DeploymentPlan plan
             ) throws InsufficientCapacityException;
 
     @POST

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java 
b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 4e25493..40ab732 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -398,7 +398,7 @@ public class VirtualMachineManagerImpl extends ManagerBase 
implements VirtualMac
                 } else if (template.getFormat() == ImageFormat.BAREMETAL) {
                     // Do nothing
                 } else {
-                    volumeMgr.allocateTemplatedVolume(Type.ROOT, "ROOT-" + 
vmFinal.getId(), rootDiskOffering.first(), rootDiskOffering.second(), template, 
vmFinal, owner);
+                    volumeMgr.allocateTemplatedVolume(Type.ROOT, "ROOT-" + 
vmFinal.getId(), rootDiskOffering.first(), template, vmFinal, owner);
                 }
         
                 for (Map.Entry<? extends DiskOffering, Long> offering : 
dataDiskOfferingsFinal.entrySet()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java
index 5dd15ce..594b388 100755
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java
@@ -164,7 +164,7 @@ public class CloudOrchestrator implements 
OrchestrationService {
             Long diskSize,
             List<String> computeTags,
             List<String> rootDiskTags,
-            Map<String, NicProfile> networkNicMap, DeploymentPlan plan, Long 
rootDiskSize) throws InsufficientCapacityException {
+            Map<String, NicProfile> networkNicMap, DeploymentPlan plan) throws 
InsufficientCapacityException {
 
        // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, 
owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, 
networks, vmEntityManager);
 
@@ -193,7 +193,6 @@ public class CloudOrchestrator implements 
OrchestrationService {
 
                ServiceOfferingVO offering = 
_serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
                rootDiskOffering.first(offering);
-        rootDiskOffering.second(rootDiskSize);
 
                if(vm.getDiskOfferingId() != null){
                DiskOfferingVO diskOffering = 
_diskOfferingDao.findById(vm.getDiskOfferingId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
----------------------------------------------------------------------
diff --git 
a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
 
b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
index 71e8b7d..6a74912 100644
--- 
a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
+++ 
b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
@@ -587,13 +587,10 @@ public class VolumeOrchestrator extends ManagerBase 
implements VolumeOrchestrati
     }
 
     @Override
-    public DiskProfile allocateTemplatedVolume(Type type, String name, 
DiskOffering offering, Long rootDisksize, VirtualMachineTemplate template, 
VirtualMachine vm, Account owner) {
+    public DiskProfile allocateTemplatedVolume(Type type, String name, 
DiskOffering offering, VirtualMachineTemplate template, VirtualMachine vm, 
Account owner) {
         assert (template.getFormat() != ImageFormat.ISO) : "ISO is not a 
template really....";
 
         Long size = _tmpltMgr.getTemplateSize(template.getId(), 
vm.getDataCenterId());
-        if (rootDisksize != null) {
-            size = (rootDisksize * 1024 * 1024 * 1024);
-        }
         VolumeVO vol = new VolumeVO(type,
             name,
             vm.getDataCenterId(),

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/089c7bc9/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/com/cloud/vm/UserVmManagerImpl.java
index a16f51c..ac8be71 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2290,12 +2290,11 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = 
"deploying Vm", create = true)
-    public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, 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, Integer cpuSpeed, Integer memory, 
Integer cpuNumber, Long rootDiskSize)
-                    throws InsufficientCapacityException, 
ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException {
+    public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template,
+                                                         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> customParametes) throws 
InsufficientCapacityException,
+        ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException {
 
         Account caller = CallContext.current().getCallingAccount();
         List<NetworkVO> networkList = new ArrayList<NetworkVO>();
@@ -2343,20 +2342,18 @@ 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, cpuSpeed , memory, cpuNumber, rootDiskSize);
+        return createVirtualMachine(zone, serviceOffering, template, hostName, 
displayName, owner, diskOfferingId, diskSize, networkList, securityGroupIdList, 
group,
+            httpmethod, userData, sshKeyPair, hypervisor, caller, 
requestedIps, defaultIps, displayVm, keyboard, affinityGroupIdList, 
customParametes);
 
     }
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = 
"deploying Vm", create = true)
     public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> 
networkIdList,
-            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, Integer cpuSpeed, Integer memory, 
Integer cpuNumber, Long rootDiskSize) throws InsufficientCapacityException, 
ConcurrentOperationException,
-            ResourceUnavailableException, StorageUnavailableException, 
ResourceAllocationException {
+                                                            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) throws 
InsufficientCapacityException,
+        ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException {
 
         Account caller = CallContext.current().getCallingAccount();
         List<NetworkVO> networkList = new ArrayList<NetworkVO>();
@@ -2461,18 +2458,17 @@ 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, cpuSpeed, memory, cpuNumber, rootDiskSize);
+        return createVirtualMachine(zone, serviceOffering, template, hostName, 
displayName, owner, diskOfferingId, diskSize, networkList, securityGroupIdList, 
group,
+            httpmethod, userData, sshKeyPair, hypervisor, caller, 
requestedIps, defaultIps, displayVm, keyboard, affinityGroupIdList, 
customParameters);
     }
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = 
"deploying Vm", create = true)
-    public UserVm createAdvancedVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> 
networkIdList, 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, Integer cpuSpeed, Integer memory, Integer 
cpuNumber, Long rootDiskSize)
-                    throws InsufficientCapacityException, 
ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException {
+    public UserVm createAdvancedVirtualMachine(DataCenter zone, 
ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> 
networkIdList,
+                                               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> customParametrs) throws InsufficientCapacityException,
+        ConcurrentOperationException, ResourceUnavailableException, 
StorageUnavailableException, ResourceAllocationException {
 
         Account caller = CallContext.current().getCallingAccount();
         List<NetworkVO> networkList = new ArrayList<NetworkVO>();
@@ -2576,9 +2572,8 @@ 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, 
cpuSpeed, memory, cpuNumber, rootDiskSize);
+        return createVirtualMachine(zone, serviceOffering, template, hostName, 
displayName, owner, diskOfferingId, diskSize, networkList, null, group, 
httpmethod,
+            userData, sshKeyPair, hypervisor, caller, requestedIps, 
defaultIps, displayvm, keyboard, affinityGroupIdList, customParametrs);
     }
 
 
@@ -2590,11 +2585,11 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
     }
 
     @DB
-    protected 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 isDisplayVmEnabled, String 
keyboard, List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, 
Integer cpuNumber, Long rootDiskSize)
-                    throws InsufficientCapacityException, 
ResourceUnavailableException, ConcurrentOperationException, 
StorageUnavailableException, ResourceAllocationException {
+    protected 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 isDisplayVmEnabled, String 
keyboard, List<Long> affinityGroupIdList, Map<String, String> customParameters)
+        throws InsufficientCapacityException, ResourceUnavailableException, 
ConcurrentOperationException, StorageUnavailableException, 
ResourceAllocationException {
 
         _accountMgr.checkAccess(caller, null, true, owner);
 
@@ -2633,6 +2628,11 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         }
 
         ServiceOfferingVO offering = 
_serviceOfferingDao.findById(serviceOffering.getId());
+        if (offering.isDynamic()) {
+            offering.setDynamicFlag(true);
+            validateCustomParameters(offering, customParameters);
+            offering = _offeringDao.getcomputeOffering(offering, 
customParameters);
+        }
         // check if account/domain is with in resource limits to create a new 
vm
         boolean isIso = Storage.ImageFormat.ISO == template.getFormat();
         // For baremetal, size can be null
@@ -2644,14 +2644,9 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         if (diskOfferingId != null) {
             size += _diskOfferingDao.findById(diskOfferingId).getDiskSize();
         }
-        if (!offering.isDynamic()) {
-            resourceLimitCheck(owner, new Long(offering.getCpu()), new 
Long(offering.getRamSize()));
-        }
-        else {
-            resourceLimitCheck(owner, new Long(cpuSpeed), new Long(memory));
-        }
-        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.volume, (isIso
-                || diskOfferingId == null ? 1 : 2));
+        resourceLimitCheck(owner, new Long(offering.getCpu()), new 
Long(offering.getRamSize()));
+
+        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.volume, 
(isIso || diskOfferingId == null ? 1 : 2));
         _resourceLimitMgr.checkResourceLimit(owner, 
ResourceType.primary_storage, size);
 
         // verify security group ids
@@ -2838,35 +2833,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
 
         long id = _vmDao.getNextInSequence(Long.class, "id");
 
-        List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>();
-        if (offering.isDynamic()) {
-            //insert the custom value of dynamic parameters
-            if (offering.getCpu() == null) {
-                if ((cpuNumber != null) && (cpuNumber <= 0)) {
-                    throw new InvalidParameterValueException("Invalid CPU 
number value, specify a value between 1 and 2147483647");
-                }
-            }
-
-            if (offering.getSpeed() == null) {
-                if ((cpuSpeed != null) && (cpuSpeed <= 0)) {
-                    throw new InvalidParameterValueException("Invalid CPU 
speed value, specify a value between 1 and 2147483647");
-                }
-            }
-
-            if (offering.getRamSize() == null) {
-                if ((memory != null) && (memory < 32)) {
-                    throw new InvalidParameterValueException("Invalid memory 
value, specify a value between 32 and 2147483647 MB");
-                }
-            }
 
-            details.add(new UserVmDetailVO(id, 
UsageEventVO.DynamicParameters.cpuNumber.toString(), cpuNumber.toString()));
-            details.add(new UserVmDetailVO(id, 
UsageEventVO.DynamicParameters.cpuSpeed.toString(), cpuSpeed.toString()));
-            details.add(new UserVmDetailVO(id, 
UsageEventVO.DynamicParameters.memory.toString(), memory.toString()));
-            offering.setCpu(cpuNumber);
-            offering.setRamSize(memory);
-            offering.setSpeed(cpuSpeed);
-            offering.setDynamicFlag(true);
-        }
         if (hostName != null) {
             // Check is hostName is RFC compliant
             checkNameForRFCCompliance(hostName);
@@ -2937,9 +2904,9 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
             hypervisorType = template.getHypervisorType();
         }
 
-        UserVmVO vm = commitUserVm(zone, template, hostName, displayName, 
owner, diskOfferingId, diskSize, userData,
-                hypervisor, caller, isDisplayVmEnabled, keyboard, accountId, 
offering, isIso, sshPublicKey,
-                networkNicMap, id, instanceName, uuidName, hypervisorType, 
rootDiskSize, details);
+        UserVmVO vm =
+            commitUserVm(zone, template, hostName, displayName, owner, 
diskOfferingId, diskSize, userData, hypervisor, caller, isDisplayVmEnabled, 
keyboard, accountId,
+                offering, isIso, sshPublicKey, networkNicMap, id, 
instanceName, uuidName, hypervisorType, customParameters);
 
         // Assign instance to the group
         try {
@@ -2968,13 +2935,12 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         return _instance + "-" + uuidName;
     }
 
-    private UserVmVO commitUserVm(final DataCenter zone, final 
VirtualMachineTemplate template, final String hostName,
-            final String displayName, final Account owner, final Long 
diskOfferingId, final Long diskSize, final String userData,
-            final HypervisorType hypervisor, final Account caller, final 
Boolean isDisplayVmEnabled, final String keyboard, final long accountId,
-            final ServiceOfferingVO offering, final boolean isIso, final 
String sshPublicKey,
-            final LinkedHashMap<String, NicProfile> networkNicMap, final long 
id, final String instanceName, final String uuidName,
-            final HypervisorType hypervisorType, final Long rootDiskSize,final 
List<UserVmDetailVO> vmdetails) throws InsufficientCapacityException {
-        return Transaction.execute(new 
TransactionCallbackWithException<UserVmVO,InsufficientCapacityException>() {
+    private UserVmVO commitUserVm(final DataCenter zone, final 
VirtualMachineTemplate template, final String hostName, final String 
displayName, final Account owner,
+        final Long diskOfferingId, final Long diskSize, final String userData, 
final HypervisorType hypervisor, final Account caller, final Boolean 
isDisplayVmEnabled,
+        final String keyboard, final long accountId, final ServiceOfferingVO 
offering, final boolean isIso, final String sshPublicKey,
+        final LinkedHashMap<String, NicProfile> networkNicMap, final long id, 
final String instanceName, final String uuidName, final HypervisorType 
hypervisorType,
+        final Map<String, String> customParameters) throws 
InsufficientCapacityException {
+        return Transaction.execute(new 
TransactionCallbackWithException<UserVmVO, InsufficientCapacityException>() {
             @Override
             public UserVmVO doInTransaction(TransactionStatus status) throws 
InsufficientCapacityException {
                 UserVmVO vm = new UserVmVO(id, instanceName, displayName,
@@ -3039,9 +3005,9 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                 }
 
                 _vmDao.persist(vm);
-                if (vmdetails != null && vmdetails.size() >0) {
-                    for (UserVmDetailVO detail : vmdetails) {
-                        vm.setDetail(detail.getName(), detail.getValue());
+                if (customParameters != null && customParameters.size() > 0) {
+                    for (String key : customParameters.keySet()) {
+                        vm.setDetail(key, customParameters.get(key));
                     }
                 }
                 _vmDao.saveDetails(vm);
@@ -3058,7 +3024,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                 if(isIso){
                     _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), 
Long.toString(owner.getAccountId()), vm.getIsoId().toString(), hostName, 
displayName, hypervisor.name(), guestOSCategory.getName(), offering.getCpu(), 
offering.getSpeed(), offering.getRamSize(), diskSize,  computeTags, 
rootDiskTags, networkNicMap, plan);
                 }else {
-                    _orchSrvc.createVirtualMachine(vm.getUuid(), 
Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, 
displayName, hypervisor.name(), offering.getCpu(),  offering.getSpeed(), 
offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, 
plan, rootDiskSize);
+                    _orchSrvc.createVirtualMachine(vm.getUuid(), 
Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, 
displayName, hypervisor.name(), offering.getCpu(),  offering.getSpeed(), 
offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, 
plan);
                 }
 
 
@@ -3074,13 +3040,8 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                             VirtualMachine.class.getName(), vm.getUuid());
                 }
                 else {
-                    HashMap<String, String> vmdetailsMap = new HashMap<String, 
String>();
-                    for (UserVmDetailVO vmdetail :vmdetails) {
-                        vmdetailsMap.put(vmdetail.getName(), 
vmdetail.getValue());
-                    }
-                    
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, 
zone.getId(), vm.getId(),
-                            vm.getHostName(), offering.getId(), 
template.getId(), hypervisorType.toString(),
-                            VirtualMachine.class.getName(), vm.getUuid(), 
vmdetailsMap);
+                    
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, 
zone.getId(), vm.getId(), vm.getHostName(), offering.getId(),
+                        template.getId(), hypervisorType.toString(), 
VirtualMachine.class.getName(), vm.getUuid(), customParameters);
                 }
 
                 //Update Resource Count for the given account

Reply via email to