You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/07/04 00:26:28 UTC

[49/50] [abbrv] git commit: updated refs/heads/vmsync to 78fa5e1

Another merge to pull in object store fix.  Also to check how changes that are applied to both master and vmsync are merged


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

Branch: refs/heads/vmsync
Commit: 8d21f49ec95a8e2939ca56fa380e59f1eb9ac940
Parents: f737019 ab5f580
Author: Alex Huang <al...@gmail.com>
Authored: Wed Jul 3 15:01:23 2013 -0700
Committer: Alex Huang <al...@gmail.com>
Committed: Wed Jul 3 15:01:23 2013 -0700

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |   1 +
 .../affinitygroup/ListAffinityGroupsCmd.java    |   1 +
 .../firewall/DeleteEgressFirewallRuleCmd.java   |   2 +-
 .../gslb/AssignToGlobalLoadBalancerRuleCmd.java |  46 +-
 .../gslb/CreateGlobalLoadBalancerRuleCmd.java   |   4 +-
 .../gslb/UpdateGlobalLoadBalancerRuleCmd.java   |  18 +-
 .../user/template/DeleteTemplateCmd.java        |   4 +-
 .../command/user/vm/RemoveIpFromVmNicCmd.java   |   2 +-
 .../api/command/user/vm/ResetVMSSHKeyCmd.java   |   4 +-
 .../api/response/AccountResponse.java           |  35 +-
 .../api/response/ProjectResponse.java           | 268 +++++++-
 .../response/ResourceLimitAndCountResponse.java |  90 +++
 .../api/response/TemplateResponse.java          |  17 +-
 .../bridge/service/core/ec2/EC2Engine.java      |  11 +-
 .../stack/models/CloudStackDiskOffering.java    |   9 +
 .../classes/resources/messages.properties       |   3 +
 client/tomcatconf/commands.properties.in        |   2 +
 .../agent/api/routing/SetNetworkACLCommand.java |  13 +-
 .../api/routing/SiteLoadBalancerConfig.java     |  13 +
 docs/en-US/add-remove-nic.xml                   |   2 +
 docs/en-US/add-tier.xml                         |   9 +
 docs/en-US/creating-network-offerings.xml       |   4 +-
 docs/en-US/vlan-assign-isolated-nw.xml          |  62 ++
 docs/en-US/vlan-provisioning.xml                |   1 +
 .../datastore/db/PrimaryDataStoreDao.java       |  17 +-
 .../datastore/db/PrimaryDataStoreDaoImpl.java   |   4 +-
 .../engine/vm/VMEntityManagerImpl.java          |   9 -
 .../cloud/vm/VirtualMachineManagerImplTest.java |   2 +
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 250 ++------
 .../gslb/GlobalLoadBalancerLbRuleMapVO.java     |  16 +-
 .../storage/image/TemplateServiceImpl.java      |  73 ++-
 .../storage/image/store/TemplateObject.java     |  11 +
 .../storage/datastore/DataStoreManagerImpl.java |  16 +-
 .../datastore/PrimaryDataStoreEntityImpl.java   | 261 --------
 .../PrimaryDataStoreProviderManagerImpl.java    |   4 +
 .../BareMetalPingServiceImpl.java               |   1 +
 .../networkservice/BaremetalDhcpManager.java    |   1 +
 .../BaremetalDhcpManagerImpl.java               |   1 +
 .../BaremetalKickStartServiceImpl.java          |   1 +
 .../networkservice/BaremetalPxeManager.java     |   1 +
 .../networkservice/BaremetalPxeManagerImpl.java |   1 +
 .../networkservice/BaremetalPxeService.java     |   1 +
 .../networkservice/ListBaremetalDhcpCmd.java    | 104 ----
 .../ListBaremetalPxePingServersCmd.java         |  94 ---
 .../cloudstack/api/ListBaremetalDhcpCmd.java    | 106 ++++
 .../api/ListBaremetalPxePingServersCmd.java     |  97 +++
 .../vmware/manager/VmwareManagerImpl.java       |  76 ++-
 .../vmware/resource/VmwareResource.java         |  38 +-
 .../network/resource/NetscalerResource.java     |   7 +-
 server/src/com/cloud/api/ApiDBUtils.java        |  50 +-
 server/src/com/cloud/api/ApiResponseHelper.java |   1 +
 .../com/cloud/api/query/QueryManagerImpl.java   |  25 +-
 .../com/cloud/api/query/dao/AccountJoinDao.java |   6 +-
 .../cloud/api/query/dao/AccountJoinDaoImpl.java | 134 ++--
 .../cloud/api/query/dao/ProjectJoinDaoImpl.java |  14 +-
 .../cloud/api/query/dao/TemplateJoinDao.java    |   5 +-
 .../api/query/dao/TemplateJoinDaoImpl.java      | 102 +--
 .../com/cloud/api/query/vo/AsyncJobJoinVO.java  |  14 +-
 .../com/cloud/api/query/vo/ProjectJoinVO.java   |   8 +-
 .../com/cloud/api/query/vo/TemplateJoinVO.java  |  32 +
 .../com/cloud/capacity/CapacityManagerImpl.java |  11 +-
 .../configuration/ConfigurationManagerImpl.java |   4 +-
 .../com/cloud/network/NetworkManagerImpl.java   |   8 +-
 .../com/cloud/network/NetworkServiceImpl.java   |   5 +-
 .../security/SecurityGroupManagerImpl.java      |  13 +-
 .../com/cloud/server/ManagementServerImpl.java  |   2 +
 .../com/cloud/storage/StorageManagerImpl.java   |  36 +-
 .../storage/StoragePoolAutomationImpl.java      |  46 +-
 .../com/cloud/storage/VolumeManagerImpl.java    |   2 +-
 .../com/cloud/template/TemplateManagerImpl.java |   8 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java  |  21 +-
 .../GlobalLoadBalancingRulesServiceImpl.java    |  19 +-
 .../security/SecurityGroupManagerImplTest.java  |  76 +++
 ...GlobalLoadBalancingRulesServiceImplTest.java |   4 +-
 setup/db/db/schema-410to420.sql                 |  60 +-
 .../component/test_network_offering.py          | 147 -----
 .../component/test_shared_network_offering.py   | 213 +++++++
 test/integration/component/test_stopped_vm.py   |   7 -
 test/integration/component/test_update_vm.py    | 159 +++++
 test/integration/smoke/test_affinity_groups.py  |   2 +-
 ...deploy_vms_with_varied_deploymentplanners.py |   8 +-
 test/integration/smoke/test_network.py          |  18 +-
 test/integration/smoke/test_primary_storage.py  |   2 +-
 tools/apidoc/build-apidoc.sh                    |   1 -
 tools/eclipse/eclipse.epf                       | 616 +++++++++++++++++++
 tools/marvin/marvin/integration/lib/base.py     |   8 +-
 ui/css/cloudstack3.css                          |   2 +-
 ui/dictionary.jsp                               |   3 +
 ui/scripts/cloudStack.js                        |   4 +-
 ui/scripts/configuration.js                     |   5 +-
 ui/scripts/instances.js                         |   8 +-
 ui/scripts/system.js                            | 151 ++++-
 ui/scripts/ui-custom/installWizard.js           |  19 +
 ui/scripts/ui/core.js                           |   8 +-
 ui/scripts/ui/dialog.js                         |   4 +-
 ui/scripts/ui/widgets/multiEdit.js              |   5 +-
 ui/scripts/vpc.js                               | 399 +++++++++---
 utils/src/com/cloud/utils/EnumerationImpl.java  |  61 --
 98 files changed, 3024 insertions(+), 1345 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
index ca06160,40ba715..e14b967
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
@@@ -26,7 -24,9 +26,8 @@@ import org.apache.cloudstack.api.BaseLi
  import org.apache.cloudstack.api.Parameter;
  import org.apache.cloudstack.api.response.ListResponse;
  import org.apache.cloudstack.api.response.UserVmResponse;
 -import org.apache.log4j.Logger;
  
+ 
  @APICommand(name = "listAffinityGroups", description = "Lists affinity groups", responseObject = AffinityGroupResponse.class)
  public class ListAffinityGroupsCmd extends BaseListAccountResourcesCmd {
      public static final Logger s_logger = Logger.getLogger(ListAffinityGroupsCmd.class.getName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java
index b9781fb,ec824b7..c9cc1ad
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java
@@@ -98,7 -99,7 +98,7 @@@ public class DeleteEgressFirewallRuleCm
  
          if (result) {
              SuccessResponse response = new SuccessResponse(getCommandName());
--            this.setResponseObject(response);
++            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete egress firewall rule");
          }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java
index dcc75b5,c66cc46..fbb0364
--- a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java
@@@ -17,29 -17,28 +17,35 @@@
  
  package org.apache.cloudstack.api.command.user.region.ha.gslb;
  
 -import com.cloud.dao.EntityManager;
++import java.util.Collection;
++import java.util.HashMap;
++import java.util.Iterator;
 +import java.util.List;
++import java.util.Map;
 +
 +import javax.inject.Inject;
 +
 +import org.apache.log4j.Logger;
 +
 +import org.apache.cloudstack.api.APICommand;
 +import org.apache.cloudstack.api.ApiConstants;
 +import org.apache.cloudstack.api.ApiErrorCode;
 +import org.apache.cloudstack.api.BaseAsyncCmd;
 +import org.apache.cloudstack.api.Parameter;
 +import org.apache.cloudstack.api.ServerApiException;
 +import org.apache.cloudstack.api.response.FirewallRuleResponse;
 +import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
 +import org.apache.cloudstack.api.response.SuccessResponse;
 +import org.apache.cloudstack.context.CallContext;
 +
  import com.cloud.event.EventTypes;
  import com.cloud.exception.InvalidParameterValueException;
+ import com.cloud.network.rules.LoadBalancer;
  import com.cloud.region.ha.GlobalLoadBalancerRule;
  import com.cloud.region.ha.GlobalLoadBalancingRulesService;
  import com.cloud.user.Account;
 -import com.cloud.user.UserContext;
  import com.cloud.utils.StringUtils;
 -import org.apache.cloudstack.api.*;
 -import org.apache.cloudstack.api.response.FirewallRuleResponse;
 -import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
 -import org.apache.cloudstack.api.response.SuccessResponse;
 -import org.apache.log4j.Logger;
 -
 -import javax.inject.Inject;
 -import java.util.Collection;
 -import java.util.HashMap;
 -import java.util.Iterator;
 -import java.util.List;
 -import java.util.Map;
 -import java.util.UUID;
++import com.cloud.utils.db.EntityManager;
  
  @APICommand(name = "assignToGlobalLoadBalancerRule", description="Assign load balancer rule or list of load " +
          "balancer rules to a global load balancer rules.", responseObject=SuccessResponse.class)
@@@ -114,7 -151,7 +158,7 @@@ public class AssignToGlobalLoadBalancer
          boolean result = _gslbService.assignToGlobalLoadBalancerRule(this);
          if (result) {
              SuccessResponse response = new SuccessResponse(getCommandName());
--            this.setResponseObject(response);
++            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign global load balancer rule");
          }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java
index b31e969,d39e466..30262ec
--- a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java
@@@ -151,9 -143,9 +151,9 @@@ public class CreateGlobalLoadBalancerRu
      public void create() {
          try {
              GlobalLoadBalancerRule gslbRule = _gslbService.createGlobalLoadBalancerRule(this);
--            this.setEntityId(gslbRule.getId());
--            this.setEntityUuid(gslbRule.getUuid());
 -            UserContext.current().setEventDetails("Rule Id: " + getEntityId());
++            setEntityId(gslbRule.getId());
++            setEntityUuid(gslbRule.getUuid());
 +            CallContext.current().setEventDetails("Rule Id: " + getEntityId());
          } catch (Exception ex) {
              s_logger.warn("Exception: ", ex);
              throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java
index 101cde3,6671886..3ac4c4e
--- a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java
@@@ -17,23 -17,18 +17,25 @@@
  
  package org.apache.cloudstack.api.command.user.region.ha.gslb;
  
 +import javax.inject.Inject;
 +
 +import org.apache.log4j.Logger;
 +
 +import org.apache.cloudstack.api.APICommand;
 +import org.apache.cloudstack.api.ApiConstants;
++import org.apache.cloudstack.api.ApiErrorCode;
 +import org.apache.cloudstack.api.BaseAsyncCmd;
 +import org.apache.cloudstack.api.Parameter;
++import org.apache.cloudstack.api.ServerApiException;
 +import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
- import org.apache.cloudstack.api.response.LoadBalancerResponse;
++import org.apache.cloudstack.context.CallContext;
 +
  import com.cloud.event.EventTypes;
  import com.cloud.region.ha.GlobalLoadBalancerRule;
  import com.cloud.region.ha.GlobalLoadBalancingRulesService;
  import com.cloud.user.Account;
 -import org.apache.cloudstack.api.*;
 -import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
 -import org.apache.cloudstack.api.response.LoadBalancerResponse;
 -import org.apache.log4j.Logger;
 -
 -import javax.inject.Inject;
  
- @APICommand(name = "updateGlobalLoadBalancerRule", description = "update global load balancer rules.", responseObject = LoadBalancerResponse.class)
+ @APICommand(name = "updateGlobalLoadBalancerRule", description = "update global load balancer rules.", responseObject=GlobalLoadBalancerResponse.class)
  public class UpdateGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
      public static final Logger s_logger = Logger.getLogger(GlobalLoadBalancerResponse.class.getName());
  
@@@ -104,7 -99,15 +106,15 @@@
  
      @Override
      public void execute() {
-         _gslbService.updateGlobalLoadBalancerRule(this);
 -        com.cloud.user.UserContext.current().setEventDetails("Global Load balancer Id: "+getId());
++        CallContext.current().setEventDetails("Global Load balancer Id: " + getId());
+         GlobalLoadBalancerRule gslbRule = _gslbService.updateGlobalLoadBalancerRule(this);
+         if (gslbRule != null) {
+             GlobalLoadBalancerResponse response = _responseGenerator.createGlobalLoadBalancerResponse(gslbRule);
+             response.setResponseName(getCommandName());
 -            this.setResponseObject(response);
++            setResponseObject(response);
+         } else {
+             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update global load balancer rule");
+         }
      }
  
      @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java
index 2a8ba6d,b2be2f2..d64e538
--- a/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java
@@@ -98,10 -98,10 +98,12 @@@ public class DeleteTemplateCmd extends 
          return "Deleting template " + getId();
      }
  
++    @Override
      public ApiCommandJobType getInstanceType() {
          return ApiCommandJobType.Template;
      }
  
++    @Override
      public Long getInstanceId() {
          return getId();
      }
@@@ -112,7 -112,7 +114,7 @@@
          boolean result = _templateService.deleteTemplate(this);
          if (result) {
              SuccessResponse response = new SuccessResponse(getCommandName());
--            this.setResponseObject(response);
++            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete template");
          }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
index 6334c08,852f073..4a22452
--- a/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java
@@@ -149,7 -151,7 +149,7 @@@ public class RemoveIpFromVmNicCmd exten
              boolean result = _networkService.releaseSecondaryIpFromNic(id);
              if (result) {
                  SuccessResponse response = new SuccessResponse(getCommandName());
--                this.setResponseObject(response);
++                setResponseObject(response);
              } else {
                  throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove secondary  ip address for the nic");
              }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java
index 3fe4b24,372f2bc..e15abac
--- a/api/src/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java
@@@ -107,6 -108,6 +107,7 @@@ public class ResetVMSSHKeyCmd extends B
          return "resetting SSHKey for vm: " + getId();
      }
  
++    @Override
      public ApiCommandJobType getInstanceType() {
          return ApiCommandJobType.VirtualMachine;
      }
@@@ -127,6 -128,6 +128,7 @@@
          return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
      }
  
++    @Override
      public Long getInstanceId() {
          return getId();
      }
@@@ -142,7 -143,7 +144,7 @@@
          if (result != null) {
              UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
              response.setResponseName(getCommandName());
--            this.setResponseObject(response);
++            setResponseObject(response);
          } else {
              throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset vm SSHKey");
          }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/response/AccountResponse.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/response/AccountResponse.java
index e3ce512,0d4f239..630f4b6
--- a/api/src/org/apache/cloudstack/api/response/AccountResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/AccountResponse.java
@@@ -329,55 -346,68 +347,68 @@@ public class AccountResponse extends Ba
      public void setNetworkTotal(Long networkTotal) {
          this.networkTotal = networkTotal;
      }
 -    
 +
+     @Override
      public void setNetworkAvailable(String networkAvailable) {
          this.networkAvailable = networkAvailable;
      }
 -    
 +
+     @Override
      public void setCpuLimit(String cpuLimit) {
          this.cpuLimit = cpuLimit;
      }
 -    
 +
+     @Override
      public void setCpuTotal(Long cpuTotal) {
          this.cpuTotal = cpuTotal;
      }
 -    
 +
+     @Override
      public void setCpuAvailable(String cpuAvailable) {
          this.cpuAvailable = cpuAvailable;
      }
 -    
 +
+     @Override
      public void setMemoryLimit(String memoryLimit) {
          this.memoryLimit = memoryLimit;
      }
 -    
 +
+     @Override
      public void setMemoryTotal(Long memoryTotal) {
          this.memoryTotal = memoryTotal;
      }
 -    
 +
+     @Override
      public void setMemoryAvailable(String memoryAvailable) {
          this.memoryAvailable = memoryAvailable;
      }
 -    
 +
+     @Override
      public void setPrimaryStorageLimit(String primaryStorageLimit) {
          this.primaryStorageLimit = primaryStorageLimit;
      }
 -    
 +
+     @Override
      public void setPrimaryStorageTotal(Long primaryStorageTotal) {
          this.primaryStorageTotal = primaryStorageTotal;
      }
 -    
 +
+     @Override
      public void setPrimaryStorageAvailable(String primaryStorageAvailable) {
          this.primaryStorageAvailable = primaryStorageAvailable;
      }
 -    
 +
+     @Override
      public void setSecondaryStorageLimit(String secondaryStorageLimit) {
          this.secondaryStorageLimit = secondaryStorageLimit;
      }
 -    
 +
+     @Override
      public void setSecondaryStorageTotal(Long secondaryStorageTotal) {
          this.secondaryStorageTotal = secondaryStorageTotal;
      }
 -    
 +
+     @Override
      public void setSecondaryStorageAvailable(String secondaryStorageAvailable) {
          this.secondaryStorageAvailable = secondaryStorageAvailable;
      }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/response/ProjectResponse.java
----------------------------------------------------------------------
diff --cc api/src/org/apache/cloudstack/api/response/ProjectResponse.java
index 9775eb7,4fdd137..3ecde77
--- a/api/src/org/apache/cloudstack/api/response/ProjectResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/ProjectResponse.java
@@@ -55,7 -54,112 +55,112 @@@ public class ProjectResponse extends Ba
  
      @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with vm", responseObject = ResourceTagResponse.class)
      private List<ResourceTagResponse> tags = new ArrayList<ResourceTagResponse>();
 -    
 +
+     @SerializedName("networklimit") @Param(description="the total number of networks the project can own", since="4.2.0")
+     private String networkLimit;
+ 
+     @SerializedName("networktotal") @Param(description="the total number of networks owned by project", since="4.2.0")
+     private Long networkTotal;
+ 
+     @SerializedName("networkavailable") @Param(description="the total number of networks available to be created for this project", since="4.2.0")
+     private String networkAvailable;
+ 
+     @SerializedName("vpclimit") @Param(description="the total number of vpcs the project can own", since="4.2.0")
+     private String vpcLimit;
+ 
+     @SerializedName("vpctotal") @Param(description="the total number of vpcs owned by project", since="4.2.0")
+     private Long vpcTotal;
+ 
+     @SerializedName("vpcavailable") @Param(description="the total number of vpcs available to be created for this project", since="4.2.0")
+     private String vpcAvailable;
+ 
+     @SerializedName("cpulimit") @Param(description="the total number of cpu cores the project can own", since="4.2.0")
+     private String cpuLimit;
+ 
+     @SerializedName("cputotal") @Param(description="the total number of cpu cores owned by project", since="4.2.0")
+     private Long cpuTotal;
+ 
+     @SerializedName("cpuavailable") @Param(description="the total number of cpu cores available to be created for this project", since="4.2.0")
+     private String cpuAvailable;
+ 
+     @SerializedName("memorylimit") @Param(description="the total memory (in MB) the project can own", since="4.2.0")
+     private String memoryLimit;
+ 
+     @SerializedName("memorytotal") @Param(description="the total memory (in MB) owned by project", since="4.2.0")
+     private Long memoryTotal;
+ 
+     @SerializedName("memoryavailable") @Param(description="the total memory (in MB) available to be created for this project", since="4.2.0")
+     private String memoryAvailable;
+ 
+     @SerializedName("primarystoragelimit") @Param(description="the total primary storage space (in GiB) the project can own", since="4.2.0")
+     private String primaryStorageLimit;
+ 
+     @SerializedName("primarystoragetotal") @Param(description="the total primary storage space (in GiB) owned by project", since="4.2.0")
+     private Long primaryStorageTotal;
+ 
+     @SerializedName("primarystorageavailable") @Param(description="the total primary storage space (in GiB) available to be used for this project", since="4.2.0")
+     private String primaryStorageAvailable;
+ 
+     @SerializedName("secondarystoragelimit") @Param(description="the total secondary storage space (in GiB) the project can own", since="4.2.0")
+     private String secondaryStorageLimit;
+ 
+     @SerializedName("secondarystoragetotal") @Param(description="the total secondary storage space (in GiB) owned by project", since="4.2.0")
+     private Long secondaryStorageTotal;
+ 
+     @SerializedName("secondarystorageavailable") @Param(description="the total secondary storage space (in GiB) available to be used for this project", since="4.2.0")
+     private String secondaryStorageAvailable;
+     
+     @SerializedName(ApiConstants.VM_LIMIT) @Param(description="the total number of virtual machines that can be deployed by this project", since="4.2.0")
+     private String vmLimit;
+ 
+     @SerializedName(ApiConstants.VM_TOTAL) @Param(description="the total number of virtual machines deployed by this project", since="4.2.0")
+     private Long vmTotal;
+ 
+     @SerializedName(ApiConstants.VM_AVAILABLE) @Param(description="the total number of virtual machines available for this project to acquire", since="4.2.0")
+     private String vmAvailable;
+ 
+     @SerializedName(ApiConstants.IP_LIMIT) @Param(description="the total number of public ip addresses this project can acquire", since="4.2.0")
+     private String ipLimit;
+ 
+     @SerializedName(ApiConstants.IP_TOTAL) @Param(description="the total number of public ip addresses allocated for this project", since="4.2.0")
+     private Long ipTotal;
+ 
+     @SerializedName(ApiConstants.IP_AVAILABLE) @Param(description="the total number of public ip addresses available for this project to acquire", since="4.2.0")
+     private String ipAvailable;
+ 
+     @SerializedName("volumelimit") @Param(description="the total volume which can be used by this project", since="4.2.0")
+     private String volumeLimit;
+ 
+     @SerializedName("volumetotal") @Param(description="the total volume being used by this project", since="4.2.0")
+     private Long volumeTotal;
+ 
+     @SerializedName("volumeavailable") @Param(description="the total volume available for this project", since="4.2.0")
+     private String volumeAvailable;
+ 
+     @SerializedName("snapshotlimit") @Param(description="the total number of snapshots which can be stored by this project", since="4.2.0")
+     private String snapshotLimit;
+ 
+     @SerializedName("snapshottotal") @Param(description="the total number of snapshots stored by this project", since="4.2.0")
+     private Long snapshotTotal;
+ 
+     @SerializedName("snapshotavailable") @Param(description="the total number of snapshots available for this project", since="4.2.0")
+     private String snapshotAvailable;
+ 
+     @SerializedName("templatelimit") @Param(description="the total number of templates which can be created by this project", since="4.2.0")
+     private String templateLimit;
+ 
+     @SerializedName("templatetotal") @Param(description="the total number of templates which have been created by this project", since="4.2.0")
+     private Long templateTotal;
+ 
+     @SerializedName("templateavailable") @Param(description="the total number of templates available to be created by this project", since="4.2.0")
+     private String templateAvailable;
+ 
+     @SerializedName("vmstopped") @Param(description="the total number of virtual machines stopped for this project", since="4.2.0")
+     private Integer vmStopped;
+ 
+     @SerializedName("vmrunning") @Param(description="the total number of virtual machines running for this project", since="4.2.0")
+     private Integer vmRunning;
+ 
  
      public void setId(String id) {
          this.id = id;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
----------------------------------------------------------------------
diff --cc engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
index 3b25dfe,0000000..ca70be0
mode 100755,000000..100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/vm/VMEntityManagerImpl.java
@@@ -1,283 -1,0 +1,274 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with the License.  You may obtain a copy of the License at
 +//
 +//   http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +package org.apache.cloudstack.engine.vm;
 +
 +import java.util.ArrayList;
 +import java.util.HashMap;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.UUID;
 +
 +import javax.inject.Inject;
 +
 +import org.apache.log4j.Logger;
 +
 +import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 +import org.apache.cloudstack.engine.cloud.entity.VMEntityVO;
 +import org.apache.cloudstack.engine.cloud.entity.VMReservationVO;
 +import org.apache.cloudstack.engine.cloud.entity.dao.VMEntityDao;
 +import org.apache.cloudstack.engine.cloud.entity.dao.VMReservationDao;
 +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 +
 +import com.cloud.dc.DataCenter;
 +import com.cloud.deploy.DataCenterDeployment;
 +import com.cloud.deploy.DeployDestination;
 +import com.cloud.deploy.DeploymentPlan;
 +import com.cloud.deploy.DeploymentPlanner;
 +import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 +import com.cloud.deploy.DeploymentPlanningManager;
 +import com.cloud.exception.AffinityConflictException;
 +import com.cloud.exception.ConcurrentOperationException;
 +import com.cloud.exception.InsufficientCapacityException;
 +import com.cloud.exception.InsufficientServerCapacityException;
 +import com.cloud.exception.OperationTimedoutException;
 +import com.cloud.exception.ResourceUnavailableException;
 +import com.cloud.hypervisor.Hypervisor.HypervisorType;
 +import com.cloud.network.dao.NetworkDao;
 +import com.cloud.org.Cluster;
 +import com.cloud.service.dao.ServiceOfferingDao;
 +import com.cloud.storage.StoragePool;
 +import com.cloud.storage.Volume;
 +import com.cloud.storage.VolumeVO;
 +import com.cloud.storage.dao.DiskOfferingDao;
 +import com.cloud.storage.dao.VMTemplateDao;
 +import com.cloud.storage.dao.VolumeDao;
 +import com.cloud.user.dao.AccountDao;
 +import com.cloud.user.dao.UserDao;
 +import com.cloud.utils.db.EntityManager;
 +import com.cloud.utils.exception.CloudRuntimeException;
 +import com.cloud.vm.VMInstanceVO;
 +import com.cloud.vm.VirtualMachine;
 +import com.cloud.vm.VirtualMachineManager;
 +import com.cloud.vm.VirtualMachineProfile;
 +import com.cloud.vm.VirtualMachineProfileImpl;
 +import com.cloud.vm.dao.VMInstanceDao;
 +
 +public class VMEntityManagerImpl implements VMEntityManager {
 +
 +    private final static Logger s_logger = Logger.getLogger(VMEntityManagerImpl.class);
 +
 +    @Inject
 +    protected EntityManager _eneityMgr;
 +
 +    @Inject
 +    protected VMInstanceDao _vmDao;
 +
 +    @Inject
 +    protected VMTemplateDao _templateDao = null;
 +
 +    @Inject
 +    protected ServiceOfferingDao _serviceOfferingDao;
 +
 +    @Inject
 +    protected DiskOfferingDao _diskOfferingDao = null;
 +
 +    @Inject
 +    protected NetworkDao _networkDao;
 +
 +    @Inject
 +    protected AccountDao _accountDao = null;
 +
 +    @Inject
 +    protected UserDao _userDao = null;
 +
 +    @Inject
 +    protected VMEntityDao _vmEntityDao;
 +
 +    @Inject
 +    protected VMReservationDao _reservationDao;
 +
 +    @Inject
 +    protected VirtualMachineManager _itMgr;
 +
 +    @Inject
 +    protected List<DeploymentPlanner> _planners;
 +
 +    @Inject
 +    protected VolumeDao _volsDao;
 +
 +    @Inject
 +    protected PrimaryDataStoreDao _storagePoolDao;
 +
 +    @Inject
 +    DataStoreManager dataStoreMgr;
 +
 +    @Inject
 +    DeploymentPlanningManager _dpMgr;
 +
 +    @Inject
 +    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
 +
 +	@Override
 +	public VMEntityVO load(String vmId) {
 +		return _vmEntityDao.findByUuid(vmId);
 +	}
 +
 +	@Override
 +	public void save(VMEntityVO entity) {
 +	    _vmEntityDao.persist(entity);
 +
 +	}
 +
 +    protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) {
 +        VirtualMachine vm = vmProfile.getVirtualMachine();
 +        long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
 +
 +        if (vmGroupCount > 0) {
 +            return true;
 +        }
 +        return false;
 +    }
 +
 +    @Override
 +    public String reserve(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
 +            throws InsufficientCapacityException, ResourceUnavailableException {
 +
 +        //call planner and get the deployDestination.
 +        //load vm instance and offerings and call virtualMachineManagerImpl
 +        //FIXME: profile should work on VirtualMachineEntity
 +        VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
 +        VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm);
 +        DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
 +        if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){
 +            plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
 +        }
 +
 +        boolean planChangedByReadyVolume = false;
 +        List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
 +        if(!vols.isEmpty()){
 +            VolumeVO vol = vols.get(0);
 +            StoragePool pool = (StoragePool)dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
 +
 +            if (!pool.isInMaintenance()) {
 +                long rootVolDcId = pool.getDataCenterId();
 +                Long rootVolPodId = pool.getPodId();
 +                Long rootVolClusterId = pool.getClusterId();
 +                if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
 +                    Long clusterIdSpecified = planToDeploy.getClusterId();
 +                    if (clusterIdSpecified != null && rootVolClusterId != null) {
 +                        if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
 +                            // cannot satisfy the plan passed in to the
 +                            // planner
 +                            throw new ResourceUnavailableException("Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for "
 +                                    + vm, Cluster.class, clusterIdSpecified);
 +                        }
 +                    }
 +                    plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null);
 +                }else{
 +                    plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
 +                    planChangedByReadyVolume = true;
 +                }
 +            }
 +
 +        }
 +
 +        DeployDestination dest;
 +        try {
 +            dest = _dpMgr.planDeployment(vmProfile, plan, exclude);
 +        } catch (AffinityConflictException e) {
 +            throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
 +        }
 +
 +        if (dest != null) {
 +           //save destination with VMEntityVO
 +            VMReservationVO vmReservation = new VMReservationVO(vm.getId(), dest.getDataCenter().getId(), dest.getPod().getId(), dest.getCluster().getId(), dest.getHost().getId());
 +            Map<Long,Long> volumeReservationMap = new HashMap<Long,Long>();
 +
 +            if (vm.getHypervisorType() != HypervisorType.BareMetal) {
 +                for(Volume vo : dest.getStorageForDisks().keySet()){
 +                    volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
 +                }
 +                vmReservation.setVolumeReservation(volumeReservationMap);
 +            }
 +
 +            vmEntityVO.setVmReservation(vmReservation);
 +            _vmEntityDao.persist(vmEntityVO);
 +
 +            return vmReservation.getUuid();
 +        } else if (planChangedByReadyVolume) {
 +            // we could not reserve in the Volume's cluster - let the deploy
 +            // call retry it.
 +            return UUID.randomUUID().toString();
 +        }else{
 +            throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile,
 +                    DataCenter.class, plan.getDataCenterId(), areAffinityGroupsAssociated(vmProfile));
 +        }
 +
 +    }
 +
 +    @Override
 +    public void deploy(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException{
 +        //grab the VM Id and destination using the reservationId.
 +
 +        VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
 +
 +        VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
 +        if(vmReservation != null){
-             // Pass it down
-             Long poolId = null;
-             Map<Long, Long> storage = vmReservation.getVolumeReservation();
-             if (storage != null) {
-                 List<Long> volIdList = new ArrayList<Long>(storage.keySet());
-                 if (volIdList != null && !volIdList.isEmpty()) {
-                     poolId = storage.get(volIdList.get(0));
-                 }
-             }
 +
 +            DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(),
 +                    vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
 +            try {
 +                _itMgr.easyStart(vm.getUuid(), params, reservedPlan);
 +            } catch (CloudRuntimeException ex) {
 +                // Retry the deployment without using the reservation plan
 +                _itMgr.easyStart(vm.getUuid(), params, null);
 +            }
 +        } else {
 +            // no reservation found. Let VirtualMachineManager retry
 +            _itMgr.easyStart(vm.getUuid(), params, null);
 +        }
 +
 +    }
 +
 +    @Override
 +    public boolean stop(VMEntityVO vm, String caller) throws ResourceUnavailableException {
 +        try {
 +            _itMgr.easyStop(vm.getUuid());
 +            return true;
 +        } catch (CloudRuntimeException e) {
 +            s_logger.warn("Unable to stop " + vm, e);
 +            return false;
 +        }
 +
 +    }
 +
 +    @Override
 +    public boolean destroy(VMEntityVO vm, String caller) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException {
 +
 +        try {
 +            _itMgr.destroy(vm.getUuid());
 +            return true;
 +        } catch (CloudRuntimeException e) {
 +            s_logger.warn("Unable to destroy " + vm, e);
 +            return false;
 +        }
 +
 +
 +    }
 +
 +}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java
----------------------------------------------------------------------
diff --cc engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java
index ae9aab7,0000000..67a0af1
mode 100644,000000..100644
--- a/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java
+++ b/engine/orchestration/test/com/cloud/vm/VirtualMachineManagerImplTest.java
@@@ -1,444 -1,0 +1,446 @@@
 +// Licensed to the Apache Software Foundation (ASF) under one
 +// or more contributor license agreements.  See the NOTICE file
 +// distributed with this work for additional information
 +// regarding copyright ownership.  The ASF licenses this file
 +// to you under the Apache License, Version 2.0 (the
 +// "License"); you may not use this file except in compliance
 +// with the License.  You may obtain a copy of the License at
 +//
 +//   http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +
 +package com.cloud.vm;
 +
 +import static org.mockito.Matchers.any;
 +import static org.mockito.Matchers.anyLong;
 +import static org.mockito.Matchers.isA;
 +import static org.mockito.Mockito.doNothing;
 +import static org.mockito.Mockito.mock;
 +import static org.mockito.Mockito.when;
 +
 +import java.util.HashMap;
 +import java.util.Iterator;
 +import java.util.List;
 +import java.util.Map;
 +
 +import org.junit.Before;
 +import org.junit.Test;
 +import org.mockito.Mock;
 +import org.mockito.MockitoAnnotations;
 +import org.mockito.Spy;
 +
 +import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
 +import org.apache.cloudstack.config.ConfigDepot;
 +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 +
 +import com.cloud.agent.AgentManager;
 +import com.cloud.agent.api.Answer;
 +import com.cloud.agent.api.CheckVirtualMachineAnswer;
 +import com.cloud.agent.api.CheckVirtualMachineCommand;
 +import com.cloud.agent.api.MigrateWithStorageAnswer;
 +import com.cloud.agent.api.MigrateWithStorageCommand;
 +import com.cloud.agent.api.MigrateWithStorageCompleteAnswer;
 +import com.cloud.agent.api.MigrateWithStorageCompleteCommand;
 +import com.cloud.agent.api.MigrateWithStorageReceiveAnswer;
 +import com.cloud.agent.api.MigrateWithStorageReceiveCommand;
 +import com.cloud.agent.api.MigrateWithStorageSendAnswer;
 +import com.cloud.agent.api.MigrateWithStorageSendCommand;
 +import com.cloud.agent.api.PrepareForMigrationAnswer;
 +import com.cloud.agent.api.PrepareForMigrationCommand;
 +import com.cloud.agent.api.ScaleVmAnswer;
 +import com.cloud.agent.api.ScaleVmCommand;
 +import com.cloud.configuration.dao.ConfigurationDao;
 +import com.cloud.dc.dao.ClusterDao;
 +import com.cloud.dc.dao.DataCenterDao;
 +import com.cloud.dc.dao.HostPodDao;
 +import com.cloud.deploy.DeployDestination;
++import com.cloud.deploy.DeploymentPlanner;
 +import com.cloud.exception.ConcurrentOperationException;
 +import com.cloud.exception.ManagementServerException;
 +import com.cloud.exception.OperationTimedoutException;
 +import com.cloud.exception.ResourceUnavailableException;
 +import com.cloud.exception.VirtualMachineMigrationException;
 +import com.cloud.host.HostVO;
 +import com.cloud.host.dao.HostDao;
 +import com.cloud.hypervisor.Hypervisor.HypervisorType;
 +import com.cloud.hypervisor.HypervisorGuru;
 +import com.cloud.hypervisor.HypervisorGuruManager;
 +import com.cloud.network.NetworkManager;
 +import com.cloud.offering.ServiceOffering;
 +import com.cloud.service.ServiceOfferingVO;
 +import com.cloud.storage.DiskOfferingVO;
 +import com.cloud.storage.StoragePool;
 +import com.cloud.storage.StoragePoolHostVO;
 +import com.cloud.storage.VMTemplateVO;
 +import com.cloud.storage.Volume;
 +import com.cloud.storage.VolumeManager;
 +import com.cloud.storage.VolumeVO;
 +import com.cloud.storage.dao.DiskOfferingDao;
 +import com.cloud.storage.dao.StoragePoolHostDao;
 +import com.cloud.storage.dao.VMTemplateDao;
 +import com.cloud.storage.dao.VolumeDao;
 +import com.cloud.user.Account;
 +import com.cloud.user.AccountVO;
 +import com.cloud.user.UserVO;
 +import com.cloud.user.dao.AccountDao;
 +import com.cloud.user.dao.UserDao;
 +import com.cloud.utils.Pair;
 +import com.cloud.utils.db.EntityManager;
 +import com.cloud.utils.exception.CloudRuntimeException;
 +import com.cloud.vm.VirtualMachine.Event;
 +import com.cloud.vm.VirtualMachine.PowerState;
 +import com.cloud.vm.VirtualMachine.State;
 +import com.cloud.vm.dao.UserVmDao;
 +import com.cloud.vm.dao.UserVmDetailsDao;
 +import com.cloud.vm.dao.VMInstanceDao;
 +import com.cloud.vm.snapshot.VMSnapshotManager;
 +
 +public class VirtualMachineManagerImplTest {
 +
 +        @Spy VirtualMachineManagerImpl _vmMgr = new VirtualMachineManagerImpl();
 +        @Mock
 +        VolumeManager _storageMgr;
 +        @Mock
 +        Account _account;
 +        @Mock
 +        AgentManager _agentMgr;
 +        @Mock
 +        AccountDao _accountDao;
 +        @Mock
 +        ConfigurationDao _configDao;
 +        @Mock
 +        HostDao _hostDao;
 +        @Mock
 +        UserDao _userDao;
 +        @Mock
 +        UserVmDao _vmDao;
 +        @Mock
 +        ItWorkDao _workDao;
 +        @Mock
 +        VMInstanceDao _vmInstanceDao;
 +        @Mock
 +        VMTemplateDao _templateDao;
 +        @Mock
 +        VolumeDao _volsDao;
 +        @Mock
 +        RestoreVMCmd _restoreVMCmd;
 +        @Mock
 +        AccountVO _accountMock;
 +        @Mock
 +        UserVO _userMock;
 +        @Mock
 +        UserVmVO _vmMock;
 +        @Mock
 +        VMInstanceVO _vmInstance;
 +        @Mock
 +        HostVO _host;
 +        @Mock
 +        VMTemplateVO _templateMock;
 +        @Mock
 +        VolumeVO _volumeMock;
 +        @Mock
 +        List<VolumeVO> _rootVols;
 +        @Mock
 +        ItWorkVO _work;
 +        @Mock
 +    ConfigDepot _configDepot;
 +        @Mock
 +        HostVO hostVO;
 +        @Mock
 +        UserVmDetailVO _vmDetailVO;
 +
 +    @Mock
 +    EntityManager _entityMgr;
 +
 +        @Mock ClusterDao _clusterDao;
 +        @Mock HostPodDao _podDao;
 +        @Mock DataCenterDao _dcDao;
 +        @Mock DiskOfferingDao _diskOfferingDao;
 +        @Mock PrimaryDataStoreDao _storagePoolDao;
 +        @Mock UserVmDetailsDao _vmDetailsDao;
 +        @Mock StoragePoolHostDao _poolHostDao;
 +        @Mock NetworkManager _networkMgr;
 +        @Mock HypervisorGuruManager _hvGuruMgr;
 +        @Mock VMSnapshotManager _vmSnapshotMgr;
 +
 +        // Mock objects for vm migration with storage test.
 +        @Mock DiskOfferingVO _diskOfferingMock;
 +        @Mock StoragePoolVO _srcStoragePoolMock;
 +        @Mock StoragePoolVO _destStoragePoolMock;
 +        @Mock HostVO _srcHostMock;
 +        @Mock HostVO _destHostMock;
 +    @Mock
 +    Map<Volume, StoragePool> _volumeToPoolMock;
 +
 +        @Before
 +        public void setup(){
 +            MockitoAnnotations.initMocks(this);
 +
 +        _vmMgr._entityMgr = _entityMgr;
 +            _vmMgr._volsDao = _volsDao;
 +            _vmMgr._volumeMgr = _storageMgr;
 +            _vmMgr._hostDao = _hostDao;
 +            _vmMgr._nodeId = 1L;
 +/*
 +            _vmMgr._workDao = _workDao;
 +*/
 +            _vmMgr._agentMgr = _agentMgr;
 +            _vmMgr._poolHostDao= _poolHostDao;
 +            _vmMgr._networkMgr = _networkMgr;
 +            _vmMgr._hvGuruMgr = _hvGuruMgr;
 +            _vmMgr._vmSnapshotMgr = _vmSnapshotMgr;
 +            _vmMgr._vmDao = _vmInstanceDao;
 +        _vmMgr._configDepot = _configDepot;
 +
 +            when(_vmMock.getId()).thenReturn(314l);
 +            when(_vmInstance.getId()).thenReturn(1L);
 +            when(_vmInstance.getServiceOfferingId()).thenReturn(2L);
 +            when(_vmInstance.getInstanceName()).thenReturn("myVm");
 +            when(_vmInstance.getHostId()).thenReturn(2L);
 +            when(_vmInstance.getType()).thenReturn(VirtualMachine.Type.User);
 +            when(_host.getId()).thenReturn(1L);
 +            when(_hostDao.findById(anyLong())).thenReturn(null);
 +        when(_entityMgr.findById(ServiceOffering.class, anyLong())).thenReturn(getSvcoffering(512));
 +            when(_workDao.persist(_work)).thenReturn(_work);
 +            when(_workDao.update("1", _work)).thenReturn(true);
 +            when(_work.getId()).thenReturn("1");
 +            doNothing().when(_work).setStep(ItWorkVO.Step.Done);
 +            //doNothing().when(_volsDao).detachVolume(anyLong());
 +            //when(_work.setStep(ItWorkVO.Step.Done)).thenReturn("1");
 +
 +        }
 +
 +
 +    @Test(expected=CloudRuntimeException.class)
 +    public void testScaleVM1()  throws Exception {
 +
 +
 +        DeployDestination dest = new DeployDestination(null, null, null, _host);
 +        long l = 1L;
 +
 +        when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
 +        _vmMgr.migrateForScale(_vmInstance.getUuid(), l, dest, l);
 +
 +    }
 +
 +    @Test (expected=CloudRuntimeException.class)
 +    public void testScaleVM2()  throws Exception {
 +
 +        DeployDestination dest = new DeployDestination(null, null, null, _host);
 +        long l = 1L;
 +
 +        when(_vmInstance.getId()).thenReturn(3L);
 +        when(_vmDetailsDao.findDetail(3L, VirtualMachine.IsDynamicScalingEnabled)).thenReturn(_vmDetailVO);
 +        when(_vmDetailVO.getValue()).thenReturn("true");
 +        when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
 +        ServiceOfferingVO newServiceOffering = getSvcoffering(512);
 +        when(_hostDao.findById(_vmInstance.hostId)).thenReturn(hostVO);
 +        when(hostVO.getClusterId()).thenReturn(1L);
 +//        when(_configDepot.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0");
 +//        when(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0");
 +        when(_vmInstance.getHostId()).thenReturn(1L);
 +        when(_hostDao.findById(1L)).thenReturn(hostVO);
 +        when(_vmInstance.getDataCenterId()).thenReturn(1L);
 +        when(hostVO.getClusterId()).thenReturn(1L);
 +//        when(_configServer.getConfigValue(Config.EnableDynamicallyScaleVm.key(), Config.ConfigurationParameterScope.zone.toString(), 1L)).thenReturn("true");
 +//        when(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0");
 +//        when(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), 1L)).thenReturn("1.0");
 +        ScaleVmCommand reconfigureCmd = new ScaleVmCommand("myVmName", newServiceOffering.getCpu(),
 +                newServiceOffering.getSpeed(), newServiceOffering.getSpeed(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse(), true);
 +        Answer answer = new ScaleVmAnswer(reconfigureCmd, true, "details");
 +        when(_agentMgr.send(2l, reconfigureCmd)).thenReturn(null);
 +        _vmMgr.reConfigureVm(_vmInstance, getSvcoffering(256), false);
 +
 +    }
 +
 +    @Test (expected=CloudRuntimeException.class)
 +    public void testScaleVM3()  throws Exception {
 +
 +        /*VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
 +
 +        Long srcHostId = vm.getHostId();
 +        Long oldSvcOfferingId = vm.getServiceOfferingId();
 +        if (srcHostId == null) {
 +            throw new CloudRuntimeException("Unable to scale the vm because it doesn't have a host id");
 +        }*/
 +
 +        when(_vmInstance.getHostId()).thenReturn(null);
 +        when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
++        DeploymentPlanner.ExcludeList excludeHostList = new DeploymentPlanner.ExcludeList();
 +        _vmMgr.findHostAndMigrate(_vmInstance.getUuid(), 2l);
 +
 +    }
 +
 +
 +    private ServiceOfferingVO getSvcoffering(int ramSize){
 +
 +        long id  = 4L;
 +        String name = "name";
 +        String displayText = "displayText";
 +        int cpu = 1;
 +        //int ramSize = 256;
 +        int speed = 128;
 +
 +        boolean ha = false;
 +        boolean useLocalStorage = false;
 +
 +        ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, useLocalStorage, false, null, false, null, false);
 +        return serviceOffering;
 +    }
 +
 +    private void initializeMockConfigForMigratingVmWithVolumes() throws OperationTimedoutException,
 +        ResourceUnavailableException {
 +
 +        // Mock the source and destination hosts.
 +        when(_srcHostMock.getId()).thenReturn(5L);
 +        when(_destHostMock.getId()).thenReturn(6L);
 +        when(_hostDao.findById(5L)).thenReturn(_srcHostMock);
 +        when(_hostDao.findById(6L)).thenReturn(_destHostMock);
 +
 +        // Mock the vm being migrated.
 +        when(_vmMock.getId()).thenReturn(1L);
 +        when(_vmMock.getHypervisorType()).thenReturn(HypervisorType.XenServer);
 +        when(_vmMock.getState()).thenReturn(State.Running).thenReturn(State.Running).thenReturn(State.Migrating)
 +            .thenReturn(State.Migrating);
 +        when(_vmMock.getHostId()).thenReturn(5L);
 +        when(_vmInstance.getId()).thenReturn(1L);
 +        when(_vmInstance.getServiceOfferingId()).thenReturn(2L);
 +        when(_vmInstance.getInstanceName()).thenReturn("myVm");
 +        when(_vmInstance.getHostId()).thenReturn(5L);
 +        when(_vmInstance.getType()).thenReturn(VirtualMachine.Type.User);
 +        when(_vmInstance.getState()).thenReturn(State.Running).thenReturn(State.Running).thenReturn(State.Migrating)
 +            .thenReturn(State.Migrating);
 +
 +        // Mock the work item.
 +        when(_workDao.persist(any(ItWorkVO.class))).thenReturn(_work);
 +        when(_workDao.update("1", _work)).thenReturn(true);
 +        when(_work.getId()).thenReturn("1");
 +        doNothing().when(_work).setStep(ItWorkVO.Step.Done);
 +
 +        // Mock the vm guru and the user vm object that gets returned.
 +        _vmMgr._vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru>();
 +
 +        // Mock the iteration over all the volumes of an instance.
 +        Iterator<VolumeVO> volumeIterator = mock(Iterator.class);
 +        when(_volsDao.findUsableVolumesForInstance(anyLong())).thenReturn(_rootVols);
 +        when(_rootVols.iterator()).thenReturn(volumeIterator);
 +        when(volumeIterator.hasNext()).thenReturn(true, false);
 +        when(volumeIterator.next()).thenReturn(_volumeMock);
 +
 +        // Mock the disk offering and pool objects for a volume.
 +        when(_volumeMock.getDiskOfferingId()).thenReturn(5L);
 +        when(_volumeMock.getPoolId()).thenReturn(200L);
 +        when(_diskOfferingDao.findById(anyLong())).thenReturn(_diskOfferingMock);
 +        when(_storagePoolDao.findById(anyLong())).thenReturn(_srcStoragePoolMock);
 +
 +        // Mock the volume to pool mapping.
 +        when(_volumeToPoolMock.get(_volumeMock)).thenReturn(_destStoragePoolMock);
 +        when(_destStoragePoolMock.getId()).thenReturn(201L);
 +        when(_srcStoragePoolMock.getId()).thenReturn(200L);
 +        when(_destStoragePoolMock.isLocal()).thenReturn(false);
 +        when(_diskOfferingMock.getUseLocalStorage()).thenReturn(false);
 +        when(_poolHostDao.findByPoolHost(anyLong(), anyLong())).thenReturn(mock(StoragePoolHostVO.class));
 +
 +        // Mock hypervisor guru.
 +        HypervisorGuru guruMock = mock(HypervisorGuru.class);
 +        when(_hvGuruMgr.getGuru(HypervisorType.XenServer)).thenReturn(guruMock);
 +
 +        when(_srcHostMock.getClusterId()).thenReturn(3L);
 +        when(_destHostMock.getClusterId()).thenReturn(3L);
 +
 +        // Mock the commands and answers to the agent.
 +        PrepareForMigrationAnswer prepAnswerMock = mock(PrepareForMigrationAnswer.class);
 +        when(prepAnswerMock.getResult()).thenReturn(true);
 +        when(_agentMgr.send(anyLong(), isA(PrepareForMigrationCommand.class))).thenReturn(prepAnswerMock);
 +
 +        MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class);
 +        when(migAnswerMock.getResult()).thenReturn(true);
 +        when(_agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock);
 +
 +        MigrateWithStorageReceiveAnswer migRecAnswerMock = mock(MigrateWithStorageReceiveAnswer.class);
 +        when(migRecAnswerMock.getResult()).thenReturn(true);
 +        when(_agentMgr.send(anyLong(), isA(MigrateWithStorageReceiveCommand.class))).thenReturn(migRecAnswerMock);
 +
 +        MigrateWithStorageSendAnswer migSendAnswerMock = mock(MigrateWithStorageSendAnswer.class);
 +        when(migSendAnswerMock.getResult()).thenReturn(true);
 +        when(_agentMgr.send(anyLong(), isA(MigrateWithStorageSendCommand.class))).thenReturn(migSendAnswerMock);
 +
 +        MigrateWithStorageCompleteAnswer migCompleteAnswerMock = mock(MigrateWithStorageCompleteAnswer.class);
 +        when(migCompleteAnswerMock.getResult()).thenReturn(true);
 +        when(_agentMgr.send(anyLong(), isA(MigrateWithStorageCompleteCommand.class))).thenReturn(migCompleteAnswerMock);
 +
 +        CheckVirtualMachineAnswer checkVmAnswerMock = mock(CheckVirtualMachineAnswer.class);
 +        when(checkVmAnswerMock.getResult()).thenReturn(true);
 +        when(checkVmAnswerMock.getState()).thenReturn(PowerState.PowerOn);
 +        when(_agentMgr.send(anyLong(), isA(CheckVirtualMachineCommand.class))).thenReturn(checkVmAnswerMock);
 +
 +        // Mock the state transitions of vm.
 +        Pair<Long, Long> opaqueMock = new Pair<Long, Long> (_vmMock.getHostId(), _destHostMock.getId());
 +        when(_vmSnapshotMgr.hasActiveVMSnapshotTasks(anyLong())).thenReturn(false);
 +        when(_vmInstanceDao.updateState(State.Running, Event.MigrationRequested, State.Migrating, _vmMock, opaqueMock))
 +            .thenReturn(true);
 +        when(_vmInstanceDao.updateState(State.Migrating, Event.OperationSucceeded, State.Running, _vmMock, opaqueMock))
 +            .thenReturn(true);
 +    }
 +
 +    // Check migration of a vm with its volumes within a cluster.
 +    @Test
 +    public void testMigrateWithVolumeWithinCluster() throws ResourceUnavailableException, ConcurrentOperationException,
 +        ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException {
 +
 +        initializeMockConfigForMigratingVmWithVolumes();
 +        when(_srcHostMock.getClusterId()).thenReturn(3L);
 +        when(_destHostMock.getClusterId()).thenReturn(3L);
 +
 +        _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock);
 +    }
 +
 +    // Check migration of a vm with its volumes across a cluster.
 +    @Test
 +    public void testMigrateWithVolumeAcrossCluster() throws ResourceUnavailableException, ConcurrentOperationException,
 +        ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException {
 +
 +        initializeMockConfigForMigratingVmWithVolumes();
 +        when(_srcHostMock.getClusterId()).thenReturn(3L);
 +        when(_destHostMock.getClusterId()).thenReturn(4L);
 +
 +        _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock);
 +    }
 +
 +    // Check migration of a vm fails when src and destination pool are not of same type; that is, one is shared and
 +    // other is local.
 +    @Test(expected=CloudRuntimeException.class)
 +    public void testMigrateWithVolumeFail1() throws ResourceUnavailableException, ConcurrentOperationException,
 +        ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException {
 +
 +        initializeMockConfigForMigratingVmWithVolumes();
 +        when(_srcHostMock.getClusterId()).thenReturn(3L);
 +        when(_destHostMock.getClusterId()).thenReturn(3L);
 +
 +        when(_destStoragePoolMock.isLocal()).thenReturn(true);
 +        when(_diskOfferingMock.getUseLocalStorage()).thenReturn(false);
 +
 +        _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock);
 +    }
 +
 +    // Check migration of a vm fails when vm is not in Running state.
 +    @Test(expected=ConcurrentOperationException.class)
 +    public void testMigrateWithVolumeFail2() throws ResourceUnavailableException, ConcurrentOperationException,
 +        ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException {
 +
 +        initializeMockConfigForMigratingVmWithVolumes();
 +        when(_srcHostMock.getClusterId()).thenReturn(3L);
 +        when(_destHostMock.getClusterId()).thenReturn(3L);
 +
 +        when(_vmMock.getState()).thenReturn(State.Stopped);
 +
 +        _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeService.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
----------------------------------------------------------------------
diff --cc plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index 8ef2371,7b8697d..d5313b6
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@@ -36,11 -36,11 +36,17 @@@ import javax.ejb.Local
  import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
--import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
--import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
++import org.apache.log4j.Logger;
++
++import com.google.gson.Gson;
++import com.vmware.vim25.AboutInfo;
++import com.vmware.vim25.HostConnectSpec;
++import com.vmware.vim25.ManagedObjectReference;
++
  import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
  import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
--import org.apache.log4j.Logger;
++import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
++import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
  
  import com.cloud.agent.AgentManager;
  import com.cloud.agent.Listener;
@@@ -61,10 -61,10 +67,10 @@@ import com.cloud.dc.dao.ClusterDao
  import com.cloud.dc.dao.ClusterVSMMapDao;
  import com.cloud.dc.dao.DataCenterDao;
  import com.cloud.exception.DiscoveredWithErrorException;
  import com.cloud.exception.DiscoveryException;
  import com.cloud.exception.InvalidParameterValueException;
  import com.cloud.exception.ResourceInUseException;
++import com.cloud.host.Host;
  import com.cloud.host.Status;
  import com.cloud.host.dao.HostDao;
  import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@@ -113,10 -113,10 +119,6 @@@ import com.cloud.utils.exception.CloudR
  import com.cloud.utils.script.Script;
  import com.cloud.utils.ssh.SshHelper;
  import com.cloud.vm.DomainRouterVO;
--import com.google.gson.Gson;
--import com.vmware.vim25.AboutInfo;
--import com.vmware.vim25.HostConnectSpec;
--import com.vmware.vim25.ManagedObjectReference;
  
  
  @Local(value = {VmwareManager.class, VmwareDatacenterService.class})
@@@ -455,7 -455,7 +457,7 @@@ public class VmwareManagerImpl extends 
      @Override
      public String getSecondaryStorageStoreUrl(long dcId) {
  
--        DataStore secStore = this._dataStoreMgr.getImageStore(dcId);
++        DataStore secStore = _dataStoreMgr.getImageStore(dcId);
          if(secStore != null)
              return secStore.getUri();
  
@@@ -475,8 -475,8 +477,8 @@@
      @Override
      public String getManagementPortGroupByHost(HostMO hostMo) throws Exception {
          if(hostMo.getHostType() == VmwareHostType.ESXi)
--            return  this._managemetPortGroupName;
--        return this._serviceConsoleName;
++            return  _managemetPortGroupName;
++        return _serviceConsoleName;
      }
  
      @Override
@@@ -558,7 -558,7 +560,7 @@@
  
      @Override
      public String getSystemVMDefaultNicAdapterType() {
--        return this._defaultSystemVmNicAdapterType;
++        return _defaultSystemVmNicAdapterType;
      }
  
      private File getSystemVMPatchIsoFile() {
@@@ -861,7 -861,7 +863,7 @@@
  
      @Override
      public int getRouterExtraPublicNics() {
--        return this._routerExtraPublicNics;
++        return _routerExtraPublicNics;
      }
  
      @Override
@@@ -942,6 -933,36 +935,36 @@@
                      "Please provide valid VMware vCenter server's IP address or fully qualified domain name.");
          }
  
+         if (zoneId == null) {
+             throw new InvalidParameterValueException("Missing or invalid parameter name. " +
+                     "Please provide valid zone id.");
+         }
+ 
+         // Zone validation
+         validateZone(zoneId);
+ 
+         VmwareDatacenterZoneMapVO vmwareDcZoneMap = _vmwareDcZoneMapDao.findByZoneId(zoneId);
+         // Check if zone is associated with VMware DC
+         if (vmwareDcZoneMap != null) {
+             // Check if the associated VMware DC matches the one specified in API params
+             // This check would yield success as the association exists between same entities (zone and VMware DC)
+             // This scenario would result in if the API addVmwareDc is called more than once with same parameters.
+             Long associatedVmwareDcId = vmwareDcZoneMap.getVmwareDcId();
+             VmwareDatacenterVO associatedVmwareDc = _vmwareDcDao.findById(associatedVmwareDcId);
 -            if (associatedVmwareDc.getVcenterHost().equalsIgnoreCase(vCenterHost) &&
++            if (associatedVmwareDc.getVCenterHost().equalsIgnoreCase(vCenterHost) &&
+                     associatedVmwareDc.getVmwareDatacenterName().equalsIgnoreCase(vmwareDcName)) {
+                 s_logger.info("Ignoring API call addVmwareDc, because VMware DC " + vCenterHost + "/" + vmwareDcName +
+                               " is already associated with specified zone with id " + zoneId);
+                 return associatedVmwareDc;
+             } else {
+                 throw new CloudRuntimeException("Zone " + zoneId + " is already associated with a VMware datacenter. " +
+                                                 "Only 1 VMware DC can be associated with a zone.");
+             }
+         }
+         // Zone validation to check if the zone already has resources.
+         // Association of VMware DC to zone is not allowed if zone already has resources added.
+         validateZoneWithResources(zoneId, "add VMware datacenter to zone");
+ 
          // Check if DC is already part of zone
          // In that case vmware_data_center table should have the DC
          vmwareDc = _vmwareDcDao.getVmwareDatacenterByGuid(vmwareDcName + "@" + vCenterHost);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/ApiDBUtils.java
index 5068abe,552539d..f16686c
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@@ -38,8 -53,8 +38,8 @@@ import org.apache.cloudstack.api.respon
  import org.apache.cloudstack.api.response.EventResponse;
  import org.apache.cloudstack.api.response.HostForMigrationResponse;
  import org.apache.cloudstack.api.response.HostResponse;
--import org.apache.cloudstack.api.response.InstanceGroupResponse;
  import org.apache.cloudstack.api.response.ImageStoreResponse;
++import org.apache.cloudstack.api.response.InstanceGroupResponse;
  import org.apache.cloudstack.api.response.ProjectAccountResponse;
  import org.apache.cloudstack.api.response.ProjectInvitationResponse;
  import org.apache.cloudstack.api.response.ProjectResponse;
@@@ -231,13 -234,13 +231,11 @@@ import com.cloud.storage.StorageManager
  import com.cloud.storage.StoragePool;
  import com.cloud.storage.StorageStats;
  import com.cloud.storage.UploadVO;
--import com.cloud.storage.VMTemplateHostVO;
  import com.cloud.storage.VMTemplateS3VO;
  import com.cloud.storage.VMTemplateSwiftVO;
  import com.cloud.storage.VMTemplateVO;
  import com.cloud.storage.Volume;
  import com.cloud.storage.Volume.Type;
--import com.cloud.storage.VolumeHostVO;
  import com.cloud.storage.VolumeManager;
  import com.cloud.storage.VolumeVO;
  import com.cloud.storage.dao.DiskOfferingDao;
@@@ -248,11 -251,11 +246,9 @@@ import com.cloud.storage.dao.SnapshotPo
  import com.cloud.storage.dao.UploadDao;
  import com.cloud.storage.dao.VMTemplateDao;
  import com.cloud.storage.dao.VMTemplateDetailsDao;
  import com.cloud.storage.dao.VMTemplateS3Dao;
  import com.cloud.storage.dao.VMTemplateSwiftDao;
  import com.cloud.storage.dao.VolumeDao;
--import com.cloud.storage.dao.VolumeHostDao;
  import com.cloud.storage.snapshot.SnapshotPolicy;
  import com.cloud.template.TemplateManager;
  import com.cloud.template.VirtualMachineTemplate;
@@@ -1283,108 -1288,108 +1279,108 @@@ public class ApiDBUtils 
              if (volume != null) {
                  jobInstanceId = volume.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.Template || jobInstanceType == jobInstanceType.Iso) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.Template || job.getInstanceType() == ApiCommandJobType.Iso) {
++        } else if (jobInstanceType == ApiCommandJobType.Template || jobInstanceType == ApiCommandJobType.Iso) {
              VMTemplateVO template = ApiDBUtils.findTemplateById(job.getInstanceId());
              if (template != null) {
                  jobInstanceId = template.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.VirtualMachine || jobInstanceType == jobInstanceType.ConsoleProxy
-                 || jobInstanceType == jobInstanceType.SystemVm || jobInstanceType == jobInstanceType.DomainRouter) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.VirtualMachine || job.getInstanceType() == ApiCommandJobType.ConsoleProxy
 -                || job.getInstanceType() == ApiCommandJobType.SystemVm || job.getInstanceType() == ApiCommandJobType.DomainRouter) {
++        } else if (jobInstanceType == ApiCommandJobType.VirtualMachine || jobInstanceType == ApiCommandJobType.ConsoleProxy
++                || jobInstanceType == ApiCommandJobType.SystemVm || jobInstanceType == ApiCommandJobType.DomainRouter) {
              VMInstanceVO vm = ApiDBUtils.findVMInstanceById(job.getInstanceId());
              if (vm != null) {
                  jobInstanceId = vm.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.Snapshot) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.Snapshot) {
++        } else if (jobInstanceType == ApiCommandJobType.Snapshot) {
              Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId());
              if (snapshot != null) {
                  jobInstanceId = snapshot.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.Host) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.Host) {
++        } else if (jobInstanceType == ApiCommandJobType.Host) {
              Host host = ApiDBUtils.findHostById(job.getInstanceId());
              if (host != null) {
                  jobInstanceId = host.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.StoragePool) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.StoragePool) {
++        } else if (jobInstanceType == ApiCommandJobType.StoragePool) {
              StoragePoolVO spool = ApiDBUtils.findStoragePoolById(job.getInstanceId());
              if (spool != null) {
                  jobInstanceId = spool.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.IpAddress) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.IpAddress) {
++        } else if (jobInstanceType == ApiCommandJobType.IpAddress) {
              IPAddressVO ip = ApiDBUtils.findIpAddressById(job.getInstanceId());
              if (ip != null) {
                  jobInstanceId = ip.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.SecurityGroup) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.SecurityGroup) {
++        } else if (jobInstanceType == ApiCommandJobType.SecurityGroup) {
              SecurityGroup sg = ApiDBUtils.findSecurityGroupById(job.getInstanceId());
              if (sg != null) {
                  jobInstanceId = sg.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.PhysicalNetwork) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.PhysicalNetwork) {
++        } else if (jobInstanceType == ApiCommandJobType.PhysicalNetwork) {
              PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(job.getInstanceId());
              if (pnet != null) {
                  jobInstanceId = pnet.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.TrafficType) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.TrafficType) {
++        } else if (jobInstanceType == ApiCommandJobType.TrafficType) {
              PhysicalNetworkTrafficTypeVO trafficType = ApiDBUtils.findPhysicalNetworkTrafficTypeById(job.getInstanceId());
              if (trafficType != null) {
                  jobInstanceId = trafficType.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.PhysicalNetworkServiceProvider) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.PhysicalNetworkServiceProvider) {
++        } else if (jobInstanceType == ApiCommandJobType.PhysicalNetworkServiceProvider) {
              PhysicalNetworkServiceProvider sp = ApiDBUtils.findPhysicalNetworkServiceProviderById(job.getInstanceId());
              if (sp != null) {
                  jobInstanceId = sp.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.FirewallRule) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.FirewallRule) {
++        } else if (jobInstanceType == ApiCommandJobType.FirewallRule) {
              FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(job.getInstanceId());
              if (fw != null) {
                  jobInstanceId = fw.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.Account) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.Account) {
++        } else if (jobInstanceType == ApiCommandJobType.Account) {
              Account acct = ApiDBUtils.findAccountById(job.getInstanceId());
              if (acct != null) {
                  jobInstanceId = acct.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.User) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.User) {
++        } else if (jobInstanceType == ApiCommandJobType.User) {
              User usr = ApiDBUtils.findUserById(job.getInstanceId());
              if (usr != null) {
                  jobInstanceId = usr.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.StaticRoute) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.StaticRoute) {
++        } else if (jobInstanceType == ApiCommandJobType.StaticRoute) {
              StaticRouteVO route = ApiDBUtils.findStaticRouteById(job.getInstanceId());
              if (route != null) {
                  jobInstanceId = route.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.PrivateGateway) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.PrivateGateway) {
++        } else if (jobInstanceType == ApiCommandJobType.PrivateGateway) {
              VpcGatewayVO gateway = ApiDBUtils.findVpcGatewayById(job.getInstanceId());
              if (gateway != null) {
                  jobInstanceId = gateway.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.Counter) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.Counter) {
++        } else if (jobInstanceType == ApiCommandJobType.Counter) {
              CounterVO counter = ApiDBUtils.getCounter(job.getInstanceId());
              if (counter != null) {
                  jobInstanceId = counter.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.Condition) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.Condition) {
++        } else if (jobInstanceType == ApiCommandJobType.Condition) {
              ConditionVO condition = ApiDBUtils.findConditionById(job.getInstanceId());
              if (condition != null) {
                  jobInstanceId = condition.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.AutoScalePolicy) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.AutoScalePolicy) {
++        } else if (jobInstanceType == ApiCommandJobType.AutoScalePolicy) {
              AutoScalePolicyVO policy = ApiDBUtils.findAutoScalePolicyById(job.getInstanceId());
              if (policy != null) {
                  jobInstanceId = policy.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.AutoScaleVmProfile) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.AutoScaleVmProfile) {
++        } else if (jobInstanceType == ApiCommandJobType.AutoScaleVmProfile) {
              AutoScaleVmProfileVO profile = ApiDBUtils.findAutoScaleVmProfileById(job.getInstanceId());
              if (profile != null) {
                  jobInstanceId = profile.getUuid();
              }
-         } else if (jobInstanceType == jobInstanceType.AutoScaleVmGroup) {
 -        } else if (job.getInstanceType() == ApiCommandJobType.AutoScaleVmGroup) {
++        } else if (jobInstanceType == ApiCommandJobType.AutoScaleVmGroup) {
              AutoScaleVmGroupVO group = ApiDBUtils.findAutoScaleVmGroupById(job.getInstanceId());
              if (group != null) {
                  jobInstanceId = group.getUuid();
              }
-         } else if (jobInstanceType != jobInstanceType.None) {
 -        } else if (job.getInstanceType() != ApiCommandJobType.None) {
++        } else if (jobInstanceType != ApiCommandJobType.None) {
              // TODO : when we hit here, we need to add instanceType -> UUID
              // entity table mapping
              assert (false);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/query/QueryManagerImpl.java
index a7217ce,90a3b6f..730b316
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@@ -2464,9 -2465,10 +2464,10 @@@ public class QueryManagerImpl extends M
          Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(), cmd.getPageSizeVal());
          SearchCriteria<DataCenterJoinVO> sc = _dcJoinDao.createSearchCriteria();
  
-         if (networkType != null)
+         if (networkType != null) {
 -            sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType);
 +          sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType);
+         }
 -
 +        
          if (id != null) {
              sc.addAnd("id", SearchCriteria.Op.EQ, id);
          } else if (name != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
index ea42550,f5b7218..4da9235
--- a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
@@@ -24,15 -24,12 +24,14 @@@ import java.util.Map
  import javax.ejb.Local;
  import javax.inject.Inject;
  
 +import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
 +
  import org.apache.cloudstack.api.BaseCmd;
  import org.apache.cloudstack.api.response.TemplateResponse;
- import org.apache.cloudstack.api.response.TemplateZoneResponse;
 +import org.apache.cloudstack.context.CallContext;
  import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
  import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
 -import org.apache.log4j.Logger;
 -import org.springframework.stereotype.Component;
  
  import com.cloud.api.ApiDBUtils;
  import com.cloud.api.ApiResponseHelper;
@@@ -92,7 -90,7 +91,7 @@@ public class TemplateJoinDaoImpl extend
          activeTmpltSearch.done();
  
          // select distinct pair (template_id, zone_id)
-         _count = "select count(distinct id) from template_view WHERE ";
 -        this._count = "select count(distinct temp_zone_pair) from template_view WHERE ";
++        _count = "select count(distinct temp_zone_pair) from template_view WHERE ";
      }
  
  
@@@ -170,9 -168,14 +169,14 @@@
          // If the user is an Admin, add the template download status
          String templateStatus = getTemplateStatus(template);
          if ( templateStatus != null ){
 -            templateResponse.setStatus(templateStatus);
 +                templateResponse.setStatus(templateStatus);
          }
  
+         if ( template.getDataCenterId() > 0 ){
+             templateResponse.setZoneId(template.getDataCenterUuid());
+             templateResponse.setZoneName(template.getDataCenterName());
+         }
+ 
          Long templateSize = template.getSize();
          if (templateSize > 0) {
              templateResponse.setSize(templateSize);
@@@ -355,17 -314,8 +315,8 @@@
          isoResponse.setDomainId(iso.getDomainUuid());
          isoResponse.setDomainName(iso.getDomainName());
  
-         // set template zone information
-         if (iso.getDataCenterId() > 0 ){
-             TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(iso.getDataCenterUuid(), iso.getDataCenterName());
-             isoResponse.addZone(tmplZoneResp);
-             // set the first found associated zone directly in TemplateResponse
-             isoResponse.setZoneId(iso.getDataCenterUuid());
-             isoResponse.setZoneName(iso.getDataCenterName());
-         }
- 
  
 -        Account caller = UserContext.current().getCaller();
 +        Account caller = CallContext.current().getCallingAccount();
          boolean isAdmin = false;
          if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
              isAdmin = true;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d21f49e/server/src/com/cloud/api/query/vo/AsyncJobJoinVO.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/query/vo/AsyncJobJoinVO.java
index 83066c7,c45be1c..3d064e3
--- a/server/src/com/cloud/api/query/vo/AsyncJobJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/AsyncJobJoinVO.java
@@@ -17,15 -17,19 +17,20 @@@
  package com.cloud.api.query.vo;
  
  import java.util.Date;
++
  import javax.persistence.Column;
  import javax.persistence.Entity;
+ import javax.persistence.EnumType;
+ import javax.persistence.Enumerated;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
--import com.cloud.utils.db.GenericDao;
 -
+ import org.apache.cloudstack.api.ApiCommandJobType;
  import org.apache.cloudstack.api.Identity;
  import org.apache.cloudstack.api.InternalIdentity;
  
++import com.cloud.utils.db.GenericDao;
++
  @Entity
  @Table(name="async_job_view")
  public class AsyncJobJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@@@ -88,8 -94,9 +93,9 @@@
      @Column(name=GenericDao.REMOVED_COLUMN)
      private Date removed;
  
 -    @Enumerated(value=EnumType.STRING)
      @Column(name="instance_type", length=64)
-     private String instanceType;
++    @Enumerated(value = EnumType.STRING)
+     private ApiCommandJobType instanceType;
  
      @Column(name="instance_id", length=64)
      private Long instanceId;