You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sh...@apache.org on 2024/02/19 08:47:43 UTC

(cloudstack) branch main updated: api,server,ui: granular resource limit management (#8362)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 592038a3042 api,server,ui: granular resource limit management (#8362)
592038a3042 is described below

commit 592038a30424713a731ede43000a169762b074dd
Author: Abhishek Kumar <ab...@gmail.com>
AuthorDate: Mon Feb 19 14:17:34 2024 +0530

    api,server,ui: granular resource limit management (#8362)
    
    Feature spec: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Granular+Resource+Limit+Management
    
    Introduces the concept of tagged resource limits for granular resource limit management. Limits can be enforced on accounts and domains for the deployment of entities for a tagged resource. Current tagged resource limits can be used for the following resource types,
    
    Host limits
    - user_vm
    - cpu
    - memory
    
    Storage limits
    - volume
    - primary_storage
    
    Following global settings can used to specify tags for which limit needs to be enforced,
    
    Host: `resource.limit.host.tags`
    Storage: `resource.limit.storage.tags`
    
    Option for specifying tagged resource limits and viewing tagged resource usage are made available in the UI.
    
    Enhances the use of templatetag for VM deployment and template creation
    
    Adds option to list service/compute offerings that can be used with a given template. A new parameter named templateid has been added.
    
    Adds option to list disk offering with suitability flag for a virtual machine. A new parameter named virtualmachineid has been added to the listDiskOfferings API which when passed returns suitableforvirtualmachine param in the response.
---
 .github/workflows/ci.yml                           |    3 +-
 api/src/main/java/com/cloud/capacity/Capacity.java |    9 +
 .../java/com/cloud/configuration/Resource.java     |    1 +
 api/src/main/java/com/cloud/storage/Volume.java    |    2 +
 .../java/com/cloud/user/ResourceLimitService.java  |   76 +-
 .../org/apache/cloudstack/api/ApiConstants.java    |    7 +-
 .../api/command/admin/domain/ListDomainsCmd.java   |   30 +-
 .../command/admin/resource/ListCapacityCmd.java    |    7 +
 .../api/command/user/account/ListAccountsCmd.java  |   23 +-
 .../user/offering/ListDiskOfferingsCmd.java        |   23 +-
 .../user/offering/ListServiceOfferingsCmd.java     |   18 +-
 .../user/resource/ListResourceLimitsCmd.java       |   14 +-
 .../user/resource/UpdateResourceCountCmd.java      |   10 +-
 .../user/resource/UpdateResourceLimitCmd.java      |    9 +-
 .../command/user/template/UpdateTemplateCmd.java   |    8 +-
 .../cloudstack/api/response/AccountResponse.java   |    9 +
 .../cloudstack/api/response/CapacityResponse.java  |   11 +-
 .../api/response/DiskOfferingResponse.java         |    8 +
 .../cloudstack/api/response/DomainResponse.java    |   10 +
 .../cloudstack/api/response/ProjectResponse.java   |    9 +
 .../api/response/ResourceCountResponse.java        |   16 +-
 .../response/ResourceLimitAndCountResponse.java    |    4 +
 .../api/response/ResourceLimitResponse.java        |   13 +-
 .../TaggedResourceLimitAndCountResponse.java       |   86 ++
 .../cloudstack/user/ResourceReservation.java       |    5 +-
 .../command/admin/domain/ListDomainsCmdTest.java   |   77 ++
 .../admin/resource/ListCapacityCmdTest.java}       |   31 +-
 .../command/user/account/ListAccountsCmdTest.java  |   76 ++
 .../user/offering/ListDiskOfferingsCmdTest.java    |   40 +-
 .../user/offering/ListServiceOfferingsCmdTest.java |   42 +-
 .../user/resource/ListResourceLimitsCmdTest.java}  |   34 +-
 .../user/resource/UpdateResourceCountCmdTest.java} |   34 +-
 .../user/resource/UpdateResourceLimitCmdTest.java} |   34 +-
 .../user/template/UpdateTemplateCmdTest.java       |   49 +
 .../java/com/cloud/vm/VirtualMachineManager.java   |    2 +
 .../java/com/cloud/storage/StorageManager.java     |    7 +
 .../com/cloud/vm/VirtualMachineManagerImpl.java    |   65 +-
 .../engine/orchestration/VolumeOrchestrator.java   |   17 +-
 .../cloud/vm/VirtualMachineManagerImplTest.java    |   83 +-
 .../main/java/com/cloud/capacity/CapacityVO.java   |   12 +
 .../java/com/cloud/capacity/dao/CapacityDao.java   |    5 +-
 .../com/cloud/capacity/dao/CapacityDaoImpl.java    |   68 +-
 .../com/cloud/configuration/ResourceCountVO.java   |   23 +-
 .../com/cloud/configuration/ResourceLimitVO.java   |   18 +-
 .../cloud/configuration/dao/ResourceCountDao.java  |   20 +-
 .../configuration/dao/ResourceCountDaoImpl.java    |  103 +-
 .../cloud/configuration/dao/ResourceLimitDao.java  |    4 +-
 .../configuration/dao/ResourceLimitDaoImpl.java    |   61 +-
 .../src/main/java/com/cloud/host/HostVO.java       |   39 +-
 .../src/main/java/com/cloud/host/dao/HostDao.java  |    2 +-
 .../main/java/com/cloud/host/dao/HostDaoImpl.java  |    6 +-
 .../com/cloud/service/dao/ServiceOfferingDao.java  |    2 +
 .../cloud/service/dao/ServiceOfferingDaoImpl.java  |   18 +
 .../com/cloud/storage/dao/DiskOfferingDao.java     |    1 +
 .../com/cloud/storage/dao/DiskOfferingDaoImpl.java |   18 +
 .../com/cloud/storage/dao/StoragePoolTagsDao.java  |    1 +
 .../cloud/storage/dao/StoragePoolTagsDaoImpl.java  |   18 +-
 .../java/com/cloud/storage/dao/VMTemplateDao.java  |    3 +
 .../com/cloud/storage/dao/VMTemplateDaoImpl.java   |   10 +
 .../main/java/com/cloud/storage/dao/VolumeDao.java |    3 +
 .../java/com/cloud/storage/dao/VolumeDaoImpl.java  |   24 +
 .../cloudstack/reservation/ReservationVO.java      |   28 +-
 .../cloudstack/reservation/dao/ReservationDao.java |    7 +-
 .../reservation/dao/ReservationDaoImpl.java        |   40 +-
 .../resources/META-INF/db/schema-41900to42000.sql  |   10 +
 .../META-INF/db/views/cloud.account_view.sql       |  164 +++
 .../META-INF/db/views/cloud.domain_view.sql        |  134 +++
 .../src/test/java/com/cloud/host/HostVOTest.java   |  210 ++--
 .../allocator/AbstractStoragePoolAllocator.java    |   24 +-
 .../storage/volume/VolumeServiceImpl.java          |    6 +-
 .../manager/allocator/impl/RandomAllocator.java    |   48 +-
 .../allocator/impl/RandomAllocatorTest.java        |   80 ++
 .../cloud/agent/manager/MockStorageManager.java    |    3 +
 .../agent/manager/MockStorageManagerImpl.java      |   30 +
 .../cloud/agent/manager/SimulatorManagerImpl.java  |    3 +
 .../cloudstack/metrics/PrometheusExporterImpl.java |   26 +-
 server/src/main/java/com/cloud/api/ApiDBUtils.java |   43 +-
 .../main/java/com/cloud/api/ApiResponseHelper.java |   28 +-
 .../java/com/cloud/api/query/QueryManagerImpl.java |   74 +-
 .../com/cloud/api/query/ViewResponseHelper.java    |    8 +-
 .../com/cloud/api/query/dao/UserVmJoinDao.java     |    5 +-
 .../com/cloud/api/query/dao/UserVmJoinDaoImpl.java |   27 +
 .../deploy/DeploymentPlanningManagerImpl.java      |    8 +-
 .../cloud/resourcelimit/CheckedReservation.java    |   94 +-
 .../resourcelimit/ResourceLimitManagerImpl.java    | 1025 +++++++++++++++----
 .../com/cloud/server/ManagementServerImpl.java     |  312 +++---
 .../java/com/cloud/storage/StorageManagerImpl.java |  145 ++-
 .../com/cloud/storage/VolumeApiServiceImpl.java    |   66 +-
 .../storage/snapshot/SnapshotManagerImpl.java      |    4 +-
 .../cloud/template/HypervisorTemplateAdapter.java  |    3 +-
 .../com/cloud/template/TemplateManagerImpl.java    |    6 +
 .../java/com/cloud/user/DomainManagerImpl.java     |   48 +-
 .../main/java/com/cloud/vm/UserVmManagerImpl.java  |  220 ++--
 .../cloudstack/vm/UnmanagedVMsManagerImpl.java     |   72 +-
 .../java/com/cloud/api/ApiResponseHelperTest.java  |   29 +
 .../com/cloud/api/query/QueryManagerImplTest.java  |   54 +
 .../resourcelimit/CheckedReservationTest.java      |   66 +-
 .../ResourceLimitManagerImplTest.java              | 1051 +++++++++++++++++++-
 .../com/cloud/storage/StorageManagerImplTest.java  |  271 ++++-
 .../cloud/storage/VolumeApiServiceImplTest.java    |   13 +-
 .../AccountManagerImplVolumeDeleteEventTest.java   |    2 -
 .../java/com/cloud/vm/UserVmManagerImplTest.java   |  156 ++-
 .../cloud/vpc/MockResourceLimitManagerImpl.java    |  165 ++-
 .../cloudstack/vm/UnmanagedVMsManagerImplTest.java |  183 ++--
 .../component/test_resource_limit_tags.py          |  648 ++++++++++++
 ui/public/locales/en.json                          |   12 +-
 ui/src/components/view/ResourceCountUsage.vue      |  140 ++-
 ui/src/components/view/ResourceLimitTab.vue        |   94 +-
 ui/src/components/view/TreeView.vue                |    6 +-
 ui/src/config/section/image.js                     |    2 +-
 ui/src/utils/plugins.js                            |   30 +-
 ui/src/views/compute/DeployVM.vue                  |   32 +-
 ui/src/views/image/RegisterOrUploadTemplate.vue    |    9 +
 ui/src/views/image/UpdateTemplate.vue              |   14 +
 ui/src/views/infra/Resources.vue                   |   93 +-
 ui/src/views/storage/CreateVolume.vue              |   11 +-
 116 files changed, 6334 insertions(+), 1209 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1cc286dd60e..c4d79843d3d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -179,7 +179,8 @@ jobs:
                 "component/test_project_usage
                   component/test_protocol_number_security_group
                   component/test_public_ip
-                  component/test_resource_limits",
+                  component/test_resource_limits
+                  component/test_resource_limit_tags",
                 "component/test_regions_accounts
                   component/test_routers
                   component/test_snapshots
diff --git a/api/src/main/java/com/cloud/capacity/Capacity.java b/api/src/main/java/com/cloud/capacity/Capacity.java
index 684490a605c..a4e2c2a7f05 100644
--- a/api/src/main/java/com/cloud/capacity/Capacity.java
+++ b/api/src/main/java/com/cloud/capacity/Capacity.java
@@ -16,6 +16,8 @@
 // under the License.
 package com.cloud.capacity;
 
+import java.util.List;
+
 import org.apache.cloudstack.api.Identity;
 import org.apache.cloudstack.api.InternalIdentity;
 
@@ -35,6 +37,11 @@ public interface Capacity extends InternalIdentity, Identity {
 
     public static final short CAPACITY_TYPE_CPU_CORE = 90;
 
+    public static final List<Short> STORAGE_CAPACITY_TYPES = List.of(CAPACITY_TYPE_STORAGE,
+            CAPACITY_TYPE_STORAGE_ALLOCATED,
+            CAPACITY_TYPE_SECONDARY_STORAGE,
+            CAPACITY_TYPE_LOCAL_STORAGE);
+
     public Long getHostOrPoolId();
 
     public Long getDataCenterId();
@@ -54,4 +61,6 @@ public interface Capacity extends InternalIdentity, Identity {
     public Float getUsedPercentage();
 
     public Long getAllocatedCapacity();
+
+    public String getTag();
 }
diff --git a/api/src/main/java/com/cloud/configuration/Resource.java b/api/src/main/java/com/cloud/configuration/Resource.java
index 32db2fcafea..bf8fca9d905 100644
--- a/api/src/main/java/com/cloud/configuration/Resource.java
+++ b/api/src/main/java/com/cloud/configuration/Resource.java
@@ -85,5 +85,6 @@ public interface Resource {
     long getOwnerId();
 
     ResourceOwnerType getResourceOwnerType();
+    String getTag();
 
 }
diff --git a/api/src/main/java/com/cloud/storage/Volume.java b/api/src/main/java/com/cloud/storage/Volume.java
index 308ed2544ed..40c5660b2df 100644
--- a/api/src/main/java/com/cloud/storage/Volume.java
+++ b/api/src/main/java/com/cloud/storage/Volume.java
@@ -30,6 +30,8 @@ import com.cloud.utils.fsm.StateObject;
 
 public interface Volume extends ControlledEntity, Identity, InternalIdentity, BasedOn, StateObject<Volume.State>, Displayable {
 
+    static final long DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID = -1;
+
     // Managed storage volume parameters (specified in the compute/disk offering for PowerFlex)
     String BANDWIDTH_LIMIT_IN_MBPS = "bandwidthLimitInMbps";
     String IOPS_LIMIT = "iopsLimit";
diff --git a/api/src/main/java/com/cloud/user/ResourceLimitService.java b/api/src/main/java/com/cloud/user/ResourceLimitService.java
index f2d87a4390d..0a64cbb7440 100644
--- a/api/src/main/java/com/cloud/user/ResourceLimitService.java
+++ b/api/src/main/java/com/cloud/user/ResourceLimitService.java
@@ -18,13 +18,18 @@ package com.cloud.user;
 
 import java.util.List;
 
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.framework.config.ConfigKey;
+
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.configuration.ResourceCount;
 import com.cloud.configuration.ResourceLimit;
 import com.cloud.domain.Domain;
 import com.cloud.exception.ResourceAllocationException;
-import org.apache.cloudstack.framework.config.ConfigKey;
-import org.apache.cloudstack.user.ResourceReservation;
+import com.cloud.offering.DiskOffering;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.template.VirtualMachineTemplate;
 
 public interface ResourceLimitService {
 
@@ -34,6 +39,13 @@ public interface ResourceLimitService {
             "The default maximum secondary storage space (in GiB) that can be used for a project", false);
     static final ConfigKey<Long> ResourceCountCheckInterval = new ConfigKey<>("Advanced", Long.class, "resourcecount.check.interval", "300",
             "Time (in seconds) to wait before running resource recalculation and fixing task. Default is 300 seconds, Setting this to 0 disables execution of the task", false);
+    static final ConfigKey<String> ResourceLimitHostTags = new ConfigKey<>("Advanced", String.class, "resource.limit.host.tags", "",
+            "A comma-separated list of tags for host resource limits", true);
+    static final ConfigKey<String> ResourceLimitStorageTags = new ConfigKey<>("Advanced", String.class, "resource.limit.storage.tags", "",
+            "A comma-separated list of tags for storage resource limits", true);
+
+    static final List<ResourceType> HostTagsSupportingTypes = List.of(ResourceType.user_vm, ResourceType.cpu, ResourceType.memory);
+    static final List<ResourceType> StorageTagsSupportingTypes = List.of(ResourceType.volume, ResourceType.primary_storage);
 
     /**
      * Updates an existing resource limit with the specified details. If a limit doesn't exist, will create one.
@@ -46,22 +58,27 @@ public interface ResourceLimitService {
      *            TODO
      * @param max
      *            TODO
+     * @param tag
+     *            tag for the resource type
      *
      * @return the updated/created resource limit
      */
-    ResourceLimit updateResourceLimit(Long accountId, Long domainId, Integer resourceType, Long max);
+    ResourceLimit updateResourceLimit(Long accountId, Long domainId, Integer resourceType, Long max, String tag);
 
     /**
      * Updates an existing resource count details for the account/domain
      *
      * @param accountId
-     *            TODO
+     *            Id of the account for which resource recalculation to be done
      * @param domainId
-     *            TODO
+     *            Id of the domain for which resource recalculation to be doneDO
      * @param typeId
-     *            TODO
+     *            type of the resource for which recalculation to be done
+     * @param tag
+     *            tag for the resource type for which recalculation to be done
      * @return the updated/created resource counts
      */
+    List<? extends ResourceCount> recalculateResourceCount(Long accountId, Long domainId, Integer typeId, String tag);
     List<? extends ResourceCount> recalculateResourceCount(Long accountId, Long domainId, Integer typeId);
 
     /**
@@ -77,7 +94,7 @@ public interface ResourceLimitService {
      *            TODO
      * @return a list of limits that match the criteria
      */
-    public List<? extends ResourceLimit> searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, Long startIndex, Long pageSizeVal);
+    public List<? extends ResourceLimit> searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, String tag, Long startIndex, Long pageSizeVal);
 
     /**
      * Finds the resource limit for a specified account and type. If the account has an infinite limit, will check
@@ -85,9 +102,10 @@ public interface ResourceLimitService {
      *
      * @param account
      * @param type
+     * @param tag
      * @return resource limit
      */
-    public long findCorrectResourceLimitForAccount(Account account, ResourceType type);
+    public long findCorrectResourceLimitForAccount(Account account, ResourceType type, String tag);
 
     /**
      * This call should be used when we have already queried resource limit for an account. This is to handle
@@ -105,9 +123,10 @@ public interface ResourceLimitService {
      *
      * @param domain
      * @param type
+     * @param tag
      * @return resource limit
      */
-    public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type);
+    public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type, String tag);
 
     /**
      * Finds the default resource limit for a specified type.
@@ -122,9 +141,10 @@ public interface ResourceLimitService {
      *
      * @param domain
      * @param type
+     * @param tag
      * @return resource limit
      */
-    public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type);
+    public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type, String tag);
 
     /**
      * Increments the resource count
@@ -134,6 +154,7 @@ public interface ResourceLimitService {
      * @param delta
      */
     public void incrementResourceCount(long accountId, ResourceType type, Long... delta);
+    public void incrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta);
 
     /**
      * Decrements the resource count
@@ -143,6 +164,7 @@ public interface ResourceLimitService {
      * @param delta
      */
     public void decrementResourceCount(long accountId, ResourceType type, Long... delta);
+    public void decrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta);
 
     /**
      * Checks if a limit has been exceeded for an account
@@ -155,15 +177,17 @@ public interface ResourceLimitService {
      * @throws ResourceAllocationException
      */
     public void checkResourceLimit(Account account, ResourceCount.ResourceType type, long... count) throws ResourceAllocationException;
+    public void checkResourceLimitWithTag(Account account, ResourceCount.ResourceType type, String tag, long... count) throws ResourceAllocationException;
 
     /**
      * Gets the count of resources for a resource type and account
      *
      * @param account
      * @param type
+     * @param tag
      * @return count of resources
      */
-    public long getResourceCount(Account account, ResourceType type);
+    public long getResourceCount(Account account, ResourceType type, String tag);
 
     /**
      * Checks if a limit has been exceeded for an account if displayResource flag is on
@@ -208,15 +232,25 @@ public interface ResourceLimitService {
      */
     void decrementResourceCount(long accountId, ResourceType type, Boolean displayResource, Long... delta);
 
-    /**
-     * Adds a reservation that will be counted in subsequent calls to {count}getResourceCount{code} until {code}this[code}
-     * is closed. It will create a reservation record that will be counted when resource limits are checked.
-     * @param account The account for which the reservation is.
-     * @param displayResource whether this resource is shown to users at all (if not it is not counted to limits)
-     * @param type resource type
-     * @param delta amount to reserve (will not be <+ 0)
-     * @return a {code}AutoClosable{Code} object representing the resource the user needs
-     */
-    ResourceReservation getReservation(Account account, Boolean displayResource, ResourceType type, Long delta) throws ResourceAllocationException;
+    List<String> getResourceLimitHostTags();
+    List<String> getResourceLimitHostTags(ServiceOffering serviceOffering, VirtualMachineTemplate template);
+    List<String> getResourceLimitStorageTags();
+    List<String> getResourceLimitStorageTags(DiskOffering diskOffering);
+    void updateTaggedResourceLimitsAndCountsForAccounts(List<AccountResponse> responses, String tag);
+    void updateTaggedResourceLimitsAndCountsForDomains(List<DomainResponse> responses, String tag);
+    void checkVolumeResourceLimit(Account owner, Boolean display, Long size, DiskOffering diskOffering) throws ResourceAllocationException;
+    void incrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering);
+    void decrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering);
+    void incrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering);
+    void decrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering);
+    void checkVmResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template) throws ResourceAllocationException;
+    void incrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template);
+    void decrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template);
+    void checkVmCpuResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu) throws ResourceAllocationException;
+    void incrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu);
+    void decrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu);
+    void checkVmMemoryResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory) throws ResourceAllocationException;
+    void incrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory);
+    void decrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory);
 
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
index db0c5ce494c..9f959db9262 100644
--- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
@@ -285,6 +285,7 @@ public class ApiConstants {
     public static final String LAST_SERVER_STOP = "lastserverstop";
     public static final String LEVEL = "level";
     public static final String LENGTH = "length";
+    public static final String LIMIT = "limit";
     public static final String LIMIT_CPU_USE = "limitcpuuse";
     public static final String LIST_HOSTS = "listhosts";
     public static final String LOCK = "lock";
@@ -380,6 +381,7 @@ public class ApiConstants {
     public static final String RECONNECT = "reconnect";
     public static final String RECOVER = "recover";
     public static final String REQUIRES_HVM = "requireshvm";
+    public static final String RESOURCE_COUNT = "resourcecount";
     public static final String RESOURCE_NAME = "resourcename";
     public static final String RESOURCE_TYPE = "resourcetype";
     public static final String RESOURCE_TYPE_NAME = "resourcetypename";
@@ -420,8 +422,9 @@ public class ApiConstants {
     public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid";
     public static final String SNAPSHOT_TYPE = "snapshottype";
     public static final String SNAPSHOT_QUIESCEVM = "quiescevm";
-    public static final String SUPPORTS_STORAGE_SNAPSHOT = "supportsstoragesnapshot";
     public static final String SOURCE_ZONE_ID = "sourcezoneid";
+    public static final String SUITABLE_FOR_VM = "suitableforvirtualmachine";
+    public static final String SUPPORTS_STORAGE_SNAPSHOT = "supportsstoragesnapshot";
     public static final String START_DATE = "startdate";
     public static final String START_ID = "startid";
     public static final String START_IP = "startip";
@@ -449,6 +452,7 @@ public class ApiConstants {
     public static final String TIMEOUT = "timeout";
     public static final String TIMEZONE = "timezone";
     public static final String TIMEZONEOFFSET = "timezoneoffset";
+    public static final String TOTAL = "total";
     public static final String TOTAL_SUBNETS = "totalsubnets";
     public static final String TYPE = "type";
     public static final String TRUST_STORE = "truststore";
@@ -719,6 +723,7 @@ public class ApiConstants {
     public static final String POLICY_UUID = "policyuuid";
     public static final String RULE_UUID = "ruleuuid";
     public static final String DIRECTION = "direction";
+    public static final String TAGGED_RESOURCES = "taggedresources";
     public static final String TAG_UUID = "taguuid";
     public static final String TAG_TYPE = "tagtype";
     public static final String TAG_VALUE = "tagvalue";
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java
index 2098389a169..b91e56dcaef 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java
@@ -20,10 +20,6 @@ import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
 
-import com.cloud.server.ResourceIcon;
-import com.cloud.server.ResourceTag;
-import org.apache.cloudstack.api.response.ResourceIconResponse;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiConstants.DomainDetails;
@@ -33,9 +29,13 @@ import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.ResourceIconResponse;
+import org.apache.commons.collections.CollectionUtils;
 
 import com.cloud.domain.Domain;
 import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.server.ResourceIcon;
+import com.cloud.server.ResourceTag;
 
 @APICommand(name = "listDomains", description = "Lists domains and provides detailed information for listed domains", responseObject = DomainResponse.class, responseView = ResponseView.Restricted, entityType = {Domain.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -71,6 +71,9 @@ public class ListDomainsCmd extends BaseListCmd implements UserCmd {
             description = "flag to display the resource icon for domains")
     private Boolean showIcon;
 
+    @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for resource type to return usage", since = "4.20.0")
+    private String tag;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -110,10 +113,14 @@ public class ListDomainsCmd extends BaseListCmd implements UserCmd {
         return dv;
     }
 
-    public Boolean getShowIcon() {
+    public boolean getShowIcon() {
         return showIcon != null ? showIcon : false;
     }
 
+    public String getTag() {
+        return tag;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -128,12 +135,17 @@ public class ListDomainsCmd extends BaseListCmd implements UserCmd {
         ListResponse<DomainResponse> response = _queryService.searchForDomains(this);
         response.setResponseName(getCommandName());
         this.setResponseObject(response);
-        if (response != null && response.getCount() > 0 && getShowIcon()) {
-            updateDomainResponse(response.getResponses());
-        }
+        updateDomainResponse(response.getResponses());
     }
 
-    private void updateDomainResponse(List<DomainResponse> response) {
+    protected void updateDomainResponse(List<DomainResponse> response) {
+        if (CollectionUtils.isEmpty(response)) {
+            return;
+        }
+        _resourceLimitService.updateTaggedResourceLimitsAndCountsForDomains(response, getTag());
+        if (!getShowIcon()) {
+            return;
+        }
         for (DomainResponse domainResponse : response) {
             ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Domain, domainResponse.getId());
             if (resourceIcon == null) {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java
index 17a648f3a39..6b31c4cc43c 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java
@@ -71,6 +71,9 @@ public class ListCapacityCmd extends BaseListCmd {
     @Parameter(name = ApiConstants.SORT_BY, type = CommandType.STRING, since = "3.0.0", description = "Sort the results. Available values: Usage")
     private String sortBy;
 
+    @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0")
+    private String tag;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -107,6 +110,10 @@ public class ListCapacityCmd extends BaseListCmd {
         return null;
     }
 
+    public String getTag() {
+        return tag;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
index 11c4d863c47..0a962b19e4f 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java
@@ -31,6 +31,7 @@ import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.AccountResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.ResourceIconResponse;
+import org.apache.commons.collections.CollectionUtils;
 
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.server.ResourceIcon;
@@ -73,6 +74,9 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC
             description = "flag to display the resource icon for accounts")
     private Boolean showIcon;
 
+    @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for resource type to return usage", since = "4.20.0")
+    private String tag;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -116,10 +120,14 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC
         return dv;
     }
 
-    public Boolean getShowIcon() {
+    public boolean getShowIcon() {
         return showIcon != null ? showIcon : false;
     }
 
+    public String getTag() {
+        return tag;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -134,12 +142,17 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC
         ListResponse<AccountResponse> response = _queryService.searchForAccounts(this);
         response.setResponseName(getCommandName());
         setResponseObject(response);
-        if (response != null && response.getCount() > 0 && getShowIcon()) {
-            updateAccountResponse(response.getResponses());
-        }
+        updateAccountResponse(response.getResponses());
     }
 
-    private void updateAccountResponse(List<AccountResponse> response) {
+    protected void updateAccountResponse(List<AccountResponse> response) {
+        if (CollectionUtils.isEmpty(response)) {
+            return;
+        }
+        _resourceLimitService.updateTaggedResourceLimitsAndCountsForAccounts(response, getTag());
+        if (!getShowIcon()) {
+            return;
+        }
         for (AccountResponse accountResponse : response) {
             ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Account, accountResponse.getObjectId());
             if (resourceIcon == null) {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java
index 7545c3e09f4..132fcc017d9 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java
@@ -16,17 +16,16 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.offering;
 
-import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
-import org.apache.cloudstack.api.response.StoragePoolResponse;
-import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.api.response.ZoneResponse;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.BaseCmd.CommandType;
 import org.apache.cloudstack.api.response.DiskOfferingResponse;
 import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.StoragePoolResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VolumeResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
 
 @APICommand(name = "listDiskOfferings", description = "Lists all available disk offerings.", responseObject = DiskOfferingResponse.class,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -65,6 +64,13 @@ public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd
             since = "4.19")
     private String storageType;
 
+    @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
+            type = CommandType.UUID,
+            entityType = UserVmResponse.class,
+            description = "The ID of a virtual machine. Pass this in if you want to see the suitable disk offering that can be used to create and add a disk to the virtual machine. Suitability is returned with suitableforvirtualmachine flag in the response",
+            since = "4.20.0")
+    private Long virtualMachineId;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -93,13 +99,16 @@ public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd
         return storageType;
     }
 
+    public Long getVirtualMachineId() {
+        return virtualMachineId;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
 
     @Override
     public void execute() {
-
         ListResponse<DiskOfferingResponse> response = _queryService.searchForDiskOfferings(this);
         response.setResponseName(getCommandName());
         this.setResponseObject(response);
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
index e07d75a7d08..9dd946d97ab 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
@@ -16,15 +16,15 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.offering;
 
-import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
-import org.apache.cloudstack.api.response.ZoneResponse;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.ServiceOfferingResponse;
+import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
 
 @APICommand(name = "listServiceOfferings", description = "Lists all available service offerings.", responseObject = ServiceOfferingResponse.class,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -92,6 +92,14 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC
             since = "4.19")
     private String storageType;
 
+    @Parameter(name = ApiConstants.TEMPLATE_ID,
+            type = CommandType.UUID,
+            entityType = TemplateResponse.class,
+            description = "The ID of the template that listed offerings must support",
+            since = "4.20.0")
+    private Long templateId;
+
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -138,6 +146,10 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC
         return storageType;
     }
 
+    public Long getTemplateId() {
+        return templateId;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java
index d40d3663451..71b886ed12b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java
@@ -19,8 +19,6 @@ package org.apache.cloudstack.api.command.user.resource;
 import java.util.ArrayList;
 import java.util.List;
 
-import com.cloud.configuration.Resource;
-import com.cloud.exception.InvalidParameterValueException;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
@@ -28,7 +26,9 @@ import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.ResourceLimitResponse;
 
+import com.cloud.configuration.Resource;
 import com.cloud.configuration.ResourceLimit;
+import com.cloud.exception.InvalidParameterValueException;
 
 @APICommand(name = "listResourceLimits", description = "Lists resource limits.", responseObject = ResourceLimitResponse.class,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -72,6 +72,10 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd
             + "secondary_storage - SecondaryStorage. Total secondary storage space (in GiB) a user can use. ")
     private String resourceTypeName;
 
+    @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0")
+    private String tag;
+
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -88,6 +92,10 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd
         return resourceTypeName;
     }
 
+    public String getTag() {
+        return tag;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -96,7 +104,7 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd
     public void execute() {
         List<? extends ResourceLimit> result =
                 _resourceLimitService.searchForLimits(id, _accountService.finalyzeAccountId(this.getAccountName(), this.getDomainId(), this.getProjectId(), false), this.getDomainId(),
-                        getResourceTypeEnum(), this.getStartIndex(), this.getPageSizeVal());
+                        getResourceTypeEnum(), getTag(), this.getStartIndex(), this.getPageSizeVal());
         ListResponse<ResourceLimitResponse> response = new ListResponse<ResourceLimitResponse>();
         List<ResourceLimitResponse> limitResponses = new ArrayList<ResourceLimitResponse>();
         for (ResourceLimit limit : result) {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java
index ae518829539..0ea22b38a37 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java
@@ -75,6 +75,9 @@ public class UpdateResourceCountCmd extends BaseCmd {
     @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Update resource limits for project")
     private Long projectId;
 
+    @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0")
+    private String tag;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -91,6 +94,10 @@ public class UpdateResourceCountCmd extends BaseCmd {
         return resourceType;
     }
 
+    public String getTag() {
+        return tag;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -117,7 +124,7 @@ public class UpdateResourceCountCmd extends BaseCmd {
     @Override
     public void execute() {
         List<? extends ResourceCount> result =
-                _resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType());
+                _resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType(), getTag());
 
         if ((result != null) && (result.size() > 0)) {
             ListResponse<ResourceCountResponse> response = new ListResponse<ResourceCountResponse>();
@@ -125,7 +132,6 @@ public class UpdateResourceCountCmd extends BaseCmd {
 
             for (ResourceCount count : result) {
                 ResourceCountResponse resourceCountResponse = _responseGenerator.createResourceCountResponse(count);
-                resourceCountResponse.setObjectName("resourcecount");
                 countResponses.add(resourceCountResponse);
             }
 
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java
index 32b3b17527e..52afd2b1760 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java
@@ -70,6 +70,9 @@ public class UpdateResourceLimitCmd extends BaseCmd {
                    + "11 - SecondaryStorage. Total secondary storage space (in GiB) a user can use. ")
     private Integer resourceType;
 
+    @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0")
+    private String tag;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -82,6 +85,10 @@ public class UpdateResourceLimitCmd extends BaseCmd {
         return domainId;
     }
 
+    public String getTag() {
+        return tag;
+    }
+
     public Integer getResourceType() {
         return resourceType;
     }
@@ -102,7 +109,7 @@ public class UpdateResourceLimitCmd extends BaseCmd {
 
     @Override
     public void execute() {
-        ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max);
+        ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max, getTag());
         if (result != null || (result == null && max != null && max.longValue() == -1L)) {
             ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result);
             response.setResponseName(getCommandName());
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
index 3f11f3860b0..dbbd771293a 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
@@ -16,7 +16,6 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.template;
 
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiCommandResourceType;
 import org.apache.cloudstack.api.ApiConstants;
@@ -44,6 +43,9 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements Use
             description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).")
     private String templateType;
 
+    @Parameter(name = ApiConstants.TEMPLATE_TAG, type = CommandType.STRING, description = "the tag for this template.", since = "4.20.0")
+    private String templateTag;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -57,6 +59,10 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements Use
         return templateType;
     }
 
+    public String getTemplateTag() {
+        return templateTag;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java
index 7ffe7d095e4..7a84e85a4a6 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java
@@ -267,6 +267,10 @@ public class AccountResponse extends BaseResponse implements ResourceLimitAndCou
     @Param(description = "Base64 string representation of the resource icon", since = "4.16.0.0")
     ResourceIconResponse icon;
 
+    @SerializedName(ApiConstants.TAGGED_RESOURCES)
+    @Param(description = "The tagged resource limit and count for the account", since = "4.20.0")
+    List<TaggedResourceLimitAndCountResponse> taggedResources;
+
     @Override
     public String getObjectId() {
         return id;
@@ -545,4 +549,9 @@ public class AccountResponse extends BaseResponse implements ResourceLimitAndCou
     public void setResourceIconResponse(ResourceIconResponse icon) {
         this.icon = icon;
     }
+
+    @Override
+    public void setTaggedResourceLimitsAndCounts(List<TaggedResourceLimitAndCountResponse> taggedResourceLimitsAndCounts) {
+        this.taggedResources = taggedResourceLimitsAndCounts;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java
index e9724497c38..2d0e2158651 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java
@@ -16,12 +16,11 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
-import com.google.gson.annotations.SerializedName;
-
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
 
 import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
 
 public class CapacityResponse extends BaseResponse {
     @SerializedName(ApiConstants.TYPE)
@@ -72,6 +71,10 @@ public class CapacityResponse extends BaseResponse {
     @Param(description = "the percentage of capacity currently in use")
     private String percentUsed;
 
+    @SerializedName(ApiConstants.TAG)
+    @Param(description = "The tag for the capacity type", since = "4.20.0")
+    private String tag;
+
     public Short getCapacityType() {
         return capacityType;
     }
@@ -167,4 +170,8 @@ public class CapacityResponse extends BaseResponse {
     public void setPercentUsed(String percentUsed) {
         this.percentUsed = percentUsed;
     }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java
index b8244aebc60..4a453a46b64 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java
@@ -169,6 +169,10 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations {
     @Param(description = "additional key/value details tied with this disk offering", since = "4.17")
     private Map<String, String> details;
 
+    @SerializedName(ApiConstants.SUITABLE_FOR_VM)
+    @Param(description = "Returns true if the disk offering is suitable for the given virtual machine for disk creation otherwise false", since = "4.20.0")
+    private Boolean suitableForVm;
+
     public Boolean getDisplayOffering() {
         return displayOffering;
     }
@@ -391,4 +395,8 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations {
     public void setDetails(Map<String, String> details) {
         this.details = details;
     }
+
+    public void setSuitableForVm(Boolean suitableForVm) {
+        this.suitableForVm = suitableForVm;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java
index e4e409a40ee..7c6ad3a91c3 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java
@@ -26,6 +26,7 @@ import com.cloud.domain.Domain;
 import com.cloud.serializer.Param;
 
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 @EntityReference(value = Domain.class)
@@ -184,6 +185,10 @@ public class DomainResponse extends BaseResponseWithAnnotations implements Resou
     @Param(description = "details for the domain")
     private Map<String, String> details;
 
+    @SerializedName(ApiConstants.TAGGED_RESOURCES)
+    @Param(description = "The tagged resource limit and count for the domain", since = "4.20.0")
+    List<TaggedResourceLimitAndCountResponse> taggedResources;
+
     public String getId() {
         return this.id;
     }
@@ -447,4 +452,9 @@ public class DomainResponse extends BaseResponseWithAnnotations implements Resou
     public void setDetails(Map<String, String> details) {
         this.details = details;
     }
+
+    @Override
+    public void setTaggedResourceLimitsAndCounts(List<TaggedResourceLimitAndCountResponse> taggedResourceLimitsAndCounts) {
+        this.taggedResources = taggedResourceLimitsAndCounts;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java
index c43dd09b127..1c63697559b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java
@@ -216,6 +216,10 @@ public class ProjectResponse extends BaseResponse implements ResourceLimitAndCou
     @Param(description = "the date this project was created", since = "4.16.0")
     private Date created;
 
+    @SerializedName(ApiConstants.TAGGED_RESOURCES)
+    @Param(description = "The tagged resource limit and count for the project", since = "4.20.0")
+    List<TaggedResourceLimitAndCountResponse> taggedResources;
+
     public void setId(String id) {
         this.id = id;
     }
@@ -447,4 +451,9 @@ public class ProjectResponse extends BaseResponse implements ResourceLimitAndCou
     public void setCreated(Date created) {
         this.created = created;
     }
+
+    @Override
+    public void setTaggedResourceLimitsAndCounts(List<TaggedResourceLimitAndCountResponse> taggedResourceLimitsAndCounts) {
+        this.taggedResources = taggedResourceLimitsAndCounts;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java
index d0a4982f872..3a698618585 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java
@@ -16,13 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
-import com.cloud.configuration.Resource;
-import com.google.gson.annotations.SerializedName;
-
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
 
+import com.cloud.configuration.Resource;
 import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
 public class ResourceCountResponse extends BaseResponse implements ControlledEntityResponse {
@@ -54,10 +53,14 @@ public class ResourceCountResponse extends BaseResponse implements ControlledEnt
     @Param(description = "resource type name. Values include user_vm, public_ip, volume, snapshot, template, project, network, vpc, cpu, memory, primary_storage, secondary_storage.")
     private String resourceTypeName;
 
-    @SerializedName("resourcecount")
-    @Param(description = "resource count")
+    @SerializedName(ApiConstants.RESOURCE_COUNT)
+    @Param(description = "The resource count")
     private long resourceCount;
 
+    @SerializedName(ApiConstants.TAG)
+    @Param(description = "Tag for the resource", since = "4.20.0")
+    private String tag;
+
     @Override
     public void setAccountName(String accountName) {
         this.accountName = accountName;
@@ -92,4 +95,7 @@ public class ResourceCountResponse extends BaseResponse implements ControlledEnt
         this.projectName = projectName;
     }
 
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java
index f247be834cb..f9e6df3a038 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java
@@ -20,6 +20,8 @@ have limits and resource count **/
 
 package org.apache.cloudstack.api.response;
 
+import java.util.List;
+
 public interface ResourceLimitAndCountResponse {
 
     public void setNetworkLimit(String networkLimit);
@@ -92,4 +94,6 @@ public interface ResourceLimitAndCountResponse {
 
     public void setVmRunning(Integer vmRunning);
 
+    public void setTaggedResourceLimitsAndCounts(List<TaggedResourceLimitAndCountResponse> taggedResourceLimitsAndCounts);
+
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java
index 13e1198177d..72c1c66f5e8 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java
@@ -16,15 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
-import com.cloud.configuration.Resource;
-import com.google.gson.annotations.SerializedName;
-
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
 import org.apache.cloudstack.api.EntityReference;
 
+import com.cloud.configuration.Resource;
 import com.cloud.configuration.ResourceLimit;
 import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
 
 @EntityReference(value = ResourceLimit.class)
 @SuppressWarnings("unused")
@@ -61,6 +60,10 @@ public class ResourceLimitResponse extends BaseResponse implements ControlledEnt
     @Param(description = "the project name of the resource limit")
     private String projectName;
 
+    @SerializedName(ApiConstants.TAG)
+    @Param(description = "The tag for the resource limit", since = "4.20.0")
+    private String tag;
+
     @Override
     public void setAccountName(String accountName) {
         this.accountName = accountName;
@@ -94,4 +97,8 @@ public class ResourceLimitResponse extends BaseResponse implements ControlledEnt
     public void setProjectId(String projectId) {
         this.projectId = projectId;
     }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java
new file mode 100644
index 00000000000..bfb03b7667c
--- /dev/null
+++ b/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java
@@ -0,0 +1,86 @@
+// 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.api.response;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+
+import com.cloud.configuration.Resource;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class TaggedResourceLimitAndCountResponse extends BaseResponse {
+
+    @SerializedName(ApiConstants.RESOURCE_TYPE)
+    @Param(description = "Numerical value for the type of the resource. See the ResourceType for more information on these values.")
+    private Integer resourceType;
+
+    @SerializedName(ApiConstants.RESOURCE_TYPE_NAME)
+    @Param(description = "Name for the type of the resource")
+    private String resourceTypeName;
+
+    @SerializedName(ApiConstants.TAG)
+    @Param(description = "The tag for the resource type")
+    private String tag;
+
+    @SerializedName(ApiConstants.LIMIT)
+    @Param(description = "The limit for the resource count for the type and tag for the owner")
+    private Long limit;
+
+    @SerializedName(ApiConstants.TOTAL)
+    @Param(description = "The total amount of the resource for the type and tag that is used by the owner")
+    private Long total;
+
+    @SerializedName(ApiConstants.AVAILABLE)
+    @Param(description = "The available amount of the resource for the type and tag that is available for the owner")
+    private Long available;
+
+
+    public void setResourceType(Resource.ResourceType resourceType) {
+        this.resourceType = resourceType.getOrdinal();
+        this.resourceTypeName = resourceType.getName();
+    }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+
+    public void setLimit(Long limit) {
+        this.limit = limit;
+    }
+
+    public void setTotal(Long total) {
+        this.total = total;
+    }
+
+    public void setAvailable(Long available) {
+        this.available = available;
+    }
+
+    public Long getLimit() {
+        return limit;
+    }
+
+    public Long getTotal() {
+        return total;
+    }
+
+    public Long getAvailable() {
+        return available;
+    }
+}
diff --git a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java b/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
index 170193570cf..9f3a661f485 100644
--- a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
+++ b/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
@@ -18,9 +18,10 @@
 //
 package org.apache.cloudstack.user;
 
-import com.cloud.configuration.Resource;
 import org.apache.cloudstack.api.InternalIdentity;
 
+import com.cloud.configuration.Resource;
+
 /**
  * an interface defining an {code}AutoClosable{code} reservation object
  */
@@ -33,5 +34,7 @@ ResourceReservation extends InternalIdentity {
 
     Resource.ResourceType getResourceType();
 
+    String getTag();
+
     Long getReservedAmount();
 }
diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java
new file mode 100644
index 00000000000..3c9d4cb67ae
--- /dev/null
+++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java
@@ -0,0 +1,77 @@
+// 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.api.command.admin.domain;
+
+import java.util.List;
+
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import com.cloud.user.ResourceLimitService;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ListDomainsCmdTest {
+
+    @Mock
+    ResourceLimitService resourceLimitService;
+
+
+    @Test
+    public void testGetShowIcon() {
+        ListDomainsCmd cmd = new ListDomainsCmd();
+        ReflectionTestUtils.setField(cmd, "showIcon", null);
+        Assert.assertFalse(cmd.getShowIcon());
+        ReflectionTestUtils.setField(cmd, "showIcon", false);
+        Assert.assertFalse(cmd.getShowIcon());
+        ReflectionTestUtils.setField(cmd, "showIcon", true);
+        Assert.assertTrue(cmd.getShowIcon());
+    }
+
+    @Test
+    public void testGetTag() {
+        ListDomainsCmd cmd = new ListDomainsCmd();
+        ReflectionTestUtils.setField(cmd, "tag", null);
+        Assert.assertNull(cmd.getTag());
+        String tag = "ABC";
+        ReflectionTestUtils.setField(cmd, "tag", tag);
+        Assert.assertEquals(tag, cmd.getTag());
+    }
+
+    @Test
+    public void testUpdateDomainResponseNoDomains() {
+        ListDomainsCmd cmd = new ListDomainsCmd();
+        cmd._resourceLimitService = resourceLimitService;
+        cmd.updateDomainResponse(null);
+        Mockito.verify(resourceLimitService, Mockito.never()).updateTaggedResourceLimitsAndCountsForDomains(Mockito.anyList(), Mockito.anyString());
+    }
+
+    @Test
+    public void testUpdateDomainResponseWithDomains() {
+        ListDomainsCmd cmd = new ListDomainsCmd();
+        cmd._resourceLimitService = resourceLimitService;
+        ReflectionTestUtils.setField(cmd, "tag", "abc");
+        cmd.updateDomainResponse(List.of(Mockito.mock(DomainResponse.class)));
+        Mockito.verify(resourceLimitService, Mockito.times(1)).updateTaggedResourceLimitsAndCountsForDomains(Mockito.any(), Mockito.any());
+    }
+
+}
diff --git a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java
similarity index 60%
copy from api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
copy to api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java
index 170193570cf..fc0e6face52 100644
--- a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java
@@ -1,4 +1,3 @@
-//
 // 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
@@ -15,23 +14,21 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-//
-package org.apache.cloudstack.user;
-
-import com.cloud.configuration.Resource;
-import org.apache.cloudstack.api.InternalIdentity;
-
-/**
- * an interface defining an {code}AutoClosable{code} reservation object
- */
-public interface
-ResourceReservation extends InternalIdentity {
-
-    Long getAccountId();
+package org.apache.cloudstack.api.command.admin.resource;
 
-    Long getDomainId();
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.test.util.ReflectionTestUtils;
 
-    Resource.ResourceType getResourceType();
+public class ListCapacityCmdTest {
 
-    Long getReservedAmount();
+    @Test
+    public void testGetTag() {
+        ListCapacityCmd cmd = new ListCapacityCmd();
+        ReflectionTestUtils.setField(cmd, "tag", null);
+        Assert.assertNull(cmd.getTag());
+        String tag = "ABC";
+        ReflectionTestUtils.setField(cmd, "tag", tag);
+        Assert.assertEquals(tag, cmd.getTag());
+    }
 }
diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java
new file mode 100644
index 00000000000..896a7a6c826
--- /dev/null
+++ b/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java
@@ -0,0 +1,76 @@
+// 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.api.command.user.account;
+
+import java.util.List;
+
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import com.cloud.user.ResourceLimitService;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ListAccountsCmdTest {
+
+    @Mock
+    ResourceLimitService resourceLimitService;
+
+
+    @Test
+    public void testGetShowIcon() {
+        ListAccountsCmd cmd = new ListAccountsCmd();
+        ReflectionTestUtils.setField(cmd, "showIcon", null);
+        Assert.assertFalse(cmd.getShowIcon());
+        ReflectionTestUtils.setField(cmd, "showIcon", false);
+        Assert.assertFalse(cmd.getShowIcon());
+        ReflectionTestUtils.setField(cmd, "showIcon", true);
+        Assert.assertTrue(cmd.getShowIcon());
+    }
+
+    @Test
+    public void testGetTag() {
+        ListAccountsCmd cmd = new ListAccountsCmd();
+        ReflectionTestUtils.setField(cmd, "tag", null);
+        Assert.assertNull(cmd.getTag());
+        String tag = "ABC";
+        ReflectionTestUtils.setField(cmd, "tag", tag);
+        Assert.assertEquals(tag, cmd.getTag());
+    }
+
+    @Test
+    public void testUpdateDomainResponseNoDomains() {
+        ListAccountsCmd cmd = new ListAccountsCmd();
+        cmd._resourceLimitService = resourceLimitService;
+        cmd.updateAccountResponse(null);
+        Mockito.verify(resourceLimitService, Mockito.never()).updateTaggedResourceLimitsAndCountsForAccounts(Mockito.anyList(), Mockito.anyString());
+    }
+
+    @Test
+    public void testUpdateDomainResponseWithDomains() {
+        ListAccountsCmd cmd = new ListAccountsCmd();
+        cmd._resourceLimitService = resourceLimitService;
+        ReflectionTestUtils.setField(cmd, "tag", "abc");
+        cmd.updateAccountResponse(List.of(Mockito.mock(AccountResponse.class)));
+        Mockito.verify(resourceLimitService, Mockito.times(1)).updateTaggedResourceLimitsAndCountsForAccounts(Mockito.any(), Mockito.any());
+    }
+}
diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java
similarity index 53%
copy from engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java
copy to api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java
index e47b38340c2..598fdd8ac4f 100644
--- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java
@@ -14,24 +14,24 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-package com.cloud.configuration.dao;
-
-import java.util.List;
-
-import com.cloud.configuration.Resource.ResourceOwnerType;
-import com.cloud.configuration.ResourceCount;
-import com.cloud.configuration.ResourceLimitVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface ResourceLimitDao extends GenericDao<ResourceLimitVO, Long> {
-
-    List<ResourceLimitVO> listByOwner(Long ownerId, ResourceOwnerType ownerType);
-
-    boolean update(Long id, Long max);
-
-    ResourceCount.ResourceType getLimitType(String type);
-
-    ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type);
-
-    long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType);
+package org.apache.cloudstack.api.command.user.offering;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ListDiskOfferingsCmdTest {
+
+    @Test
+    public void testGetVirtualMachineId() {
+        ListDiskOfferingsCmd cmd = new ListDiskOfferingsCmd();
+        ReflectionTestUtils.setField(cmd, "virtualMachineId", null);
+        Assert.assertNull(cmd.getVirtualMachineId());
+        Long id = 100L;
+        ReflectionTestUtils.setField(cmd, "virtualMachineId", id);
+        Assert.assertEquals(id, cmd.getVirtualMachineId());
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java
old mode 100755
new mode 100644
similarity index 53%
copy from engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java
copy to api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java
index 9352ee21858..f408132e5fc
--- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java
@@ -14,25 +14,25 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-package com.cloud.storage.dao;
-
-import java.util.List;
-
-import org.apache.cloudstack.api.response.StorageTagResponse;
-
-import com.cloud.storage.StoragePoolTagVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface StoragePoolTagsDao extends GenericDao<StoragePoolTagVO, Long> {
-
-    void persist(long poolId, List<String> storagePoolTags, Boolean isTagARule);
-
-    void persist(List<StoragePoolTagVO> storagePoolTags);
-    List<String> getStoragePoolTags(long poolId);
-    void deleteTags(long poolId);
-    List<StoragePoolTagVO> searchByIds(Long... stIds);
-    StorageTagResponse newStorageTagResponse(StoragePoolTagVO tag);
-
-    List<StoragePoolTagVO> findStoragePoolTags(long poolId);
-
+package org.apache.cloudstack.api.command.user.offering;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class ListServiceOfferingsCmdTest {
+
+    @Test
+    public void testGetTemplateId() {
+        ListServiceOfferingsCmd cmd = new ListServiceOfferingsCmd();
+        ReflectionTestUtils.setField(cmd, "templateId", null);
+        Assert.assertNull(cmd.getTemplateId());
+        Long id = 100L;
+        ReflectionTestUtils.setField(cmd, "templateId", id);
+        Assert.assertEquals(id, cmd.getTemplateId());
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java
similarity index 55%
copy from api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
copy to api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java
index 170193570cf..3e999be2cfd 100644
--- a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java
@@ -1,4 +1,3 @@
-//
 // 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
@@ -15,23 +14,24 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-//
-package org.apache.cloudstack.user;
-
-import com.cloud.configuration.Resource;
-import org.apache.cloudstack.api.InternalIdentity;
-
-/**
- * an interface defining an {code}AutoClosable{code} reservation object
- */
-public interface
-ResourceReservation extends InternalIdentity {
-
-    Long getAccountId();
+package org.apache.cloudstack.api.command.user.resource;
 
-    Long getDomainId();
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
 
-    Resource.ResourceType getResourceType();
+@RunWith(MockitoJUnitRunner.class)
+public class ListResourceLimitsCmdTest {
 
-    Long getReservedAmount();
+    @Test
+    public void testGetTag() {
+        ListResourceLimitsCmd cmd = new ListResourceLimitsCmd();
+        ReflectionTestUtils.setField(cmd, "tag", null);
+        Assert.assertNull(cmd.getTag());
+        String tag = "ABC";
+        ReflectionTestUtils.setField(cmd, "tag", tag);
+        Assert.assertEquals(tag, cmd.getTag());
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java
similarity index 54%
copy from api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
copy to api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java
index 170193570cf..ab7d3253ab5 100644
--- a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java
@@ -1,4 +1,3 @@
-//
 // 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
@@ -15,23 +14,24 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-//
-package org.apache.cloudstack.user;
-
-import com.cloud.configuration.Resource;
-import org.apache.cloudstack.api.InternalIdentity;
-
-/**
- * an interface defining an {code}AutoClosable{code} reservation object
- */
-public interface
-ResourceReservation extends InternalIdentity {
-
-    Long getAccountId();
+package org.apache.cloudstack.api.command.user.resource;
 
-    Long getDomainId();
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
 
-    Resource.ResourceType getResourceType();
+@RunWith(MockitoJUnitRunner.class)
+public class UpdateResourceCountCmdTest {
 
-    Long getReservedAmount();
+    @Test
+    public void testGetTag() {
+        UpdateResourceCountCmd cmd = new UpdateResourceCountCmd();
+        ReflectionTestUtils.setField(cmd, "tag", null);
+        Assert.assertNull(cmd.getTag());
+        String tag = "ABC";
+        ReflectionTestUtils.setField(cmd, "tag", tag);
+        Assert.assertEquals(tag, cmd.getTag());
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java
similarity index 54%
copy from api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
copy to api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java
index 170193570cf..dff27a20044 100644
--- a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java
@@ -1,4 +1,3 @@
-//
 // 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
@@ -15,23 +14,24 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-//
-package org.apache.cloudstack.user;
-
-import com.cloud.configuration.Resource;
-import org.apache.cloudstack.api.InternalIdentity;
-
-/**
- * an interface defining an {code}AutoClosable{code} reservation object
- */
-public interface
-ResourceReservation extends InternalIdentity {
-
-    Long getAccountId();
+package org.apache.cloudstack.api.command.user.resource;
 
-    Long getDomainId();
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
 
-    Resource.ResourceType getResourceType();
+@RunWith(MockitoJUnitRunner.class)
+public class UpdateResourceLimitCmdTest {
 
-    Long getReservedAmount();
+    @Test
+    public void testGetTag() {
+        UpdateResourceLimitCmd cmd = new UpdateResourceLimitCmd();
+        ReflectionTestUtils.setField(cmd, "tag", null);
+        Assert.assertNull(cmd.getTag());
+        String tag = "ABC";
+        ReflectionTestUtils.setField(cmd, "tag", tag);
+        Assert.assertEquals(tag, cmd.getTag());
+    }
 }
diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java
new file mode 100644
index 00000000000..03e558b58a8
--- /dev/null
+++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java
@@ -0,0 +1,49 @@
+// 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.api.command.user.template;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import com.cloud.storage.Storage;
+
+@RunWith(MockitoJUnitRunner.class)
+public class UpdateTemplateCmdTest {
+
+    @Test
+    public void testGetTemplateType() {
+        UpdateTemplateCmd cmd = new UpdateTemplateCmd();
+        ReflectionTestUtils.setField(cmd, "templateType", null);
+        Assert.assertNull(cmd.getTemplateType());
+        String type = Storage.TemplateType.ROUTING.toString();
+        ReflectionTestUtils.setField(cmd, "templateTag", type);
+        Assert.assertEquals(type, cmd.getTemplateTag());
+    }
+
+    @Test
+    public void testGetTemplateTag() {
+        UpdateTemplateCmd cmd = new UpdateTemplateCmd();
+        ReflectionTestUtils.setField(cmd, "templateTag", null);
+        Assert.assertNull(cmd.getTemplateTag());
+        String tag = "ABC";
+        ReflectionTestUtils.setField(cmd, "templateTag", tag);
+        Assert.assertEquals(tag, cmd.getTemplateTag());
+    }
+}
diff --git a/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java b/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java
index 8cd67f25331..3f3bdefb6a0 100644
--- a/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java
+++ b/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java
@@ -290,4 +290,6 @@ public interface VirtualMachineManager extends Manager {
 
     HashMap<Long, List<? extends VmNetworkStats>> getVmNetworkStatistics(long hostId, String hostName, Map<Long, ? extends VirtualMachine> vmMap);
 
+    Map<Long, Boolean> getDiskOfferingSuitabilityForVm(long vmId, List<Long> diskOfferingIds);
+
 }
diff --git a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java
index f5cf443211c..427a58669e6 100644
--- a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java
+++ b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java
@@ -277,6 +277,8 @@ public interface StorageManager extends StorageService {
 
     CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId);
 
+    CapacityVO getStoragePoolUsedStats(Long zoneId, Long podId, Long clusterId, List<Long> poolIds);
+
     List<StoragePoolVO> ListByDataCenterHypervisor(long datacenterId, HypervisorType type);
 
     List<VMInstanceVO> listByStoragePool(long storagePoolId);
@@ -303,6 +305,9 @@ public interface StorageManager extends StorageService {
 
     boolean storagePoolHasEnoughIops(List<Pair<Volume, DiskProfile>> volumeDiskProfilePairs, StoragePool pool);
 
+    boolean storagePoolHasEnoughIops(Long requestedIops, StoragePool pool);
+    boolean storagePoolHasEnoughSpace(Long size, StoragePool pool);
+
     boolean storagePoolHasEnoughSpace(List<Pair<Volume, DiskProfile>> volumeDiskProfilePairs, StoragePool pool);
 
     /**
@@ -335,6 +340,8 @@ public interface StorageManager extends StorageService {
 
     boolean isStoragePoolCompliantWithStoragePolicy(List<Pair<Volume, DiskProfile>> volumes, StoragePool pool) throws StorageUnavailableException;
 
+    boolean isStoragePoolCompliantWithStoragePolicy(long diskOfferingId, StoragePool pool) throws StorageUnavailableException;
+
     boolean registerHostListener(String providerUuid, HypervisorHostListener listener);
 
     boolean connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException;
diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
index 5e7be6d448a..b5fc2e7c3a9 100755
--- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -19,6 +19,7 @@ package com.cloud.vm;
 
 import static com.cloud.configuration.ConfigurationManagerImpl.MIGRATE_VM_ACROSS_CLUSTERS;
 
+import java.lang.reflect.Field;
 import java.net.URI;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -148,7 +149,6 @@ import com.cloud.api.query.dao.UserVmJoinDao;
 import com.cloud.api.query.vo.DomainRouterJoinVO;
 import com.cloud.api.query.vo.UserVmJoinVO;
 import com.cloud.capacity.CapacityManager;
-import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.dc.ClusterDetailsDao;
 import com.cloud.dc.ClusterDetailsVO;
 import com.cloud.dc.ClusterVO;
@@ -1130,7 +1130,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         // check resource count if ResourceCountRunningVMsonly.value() = true
         final Account owner = _entityMgr.findById(Account.class, vm.getAccountId());
         if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) {
-            resourceCountIncrement(owner.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize()));
+            _resourceLimitMgr.incrementVmResourceCount(owner.getAccountId(), vm.isDisplay(), offering, template);
         }
 
         boolean canRetry = true;
@@ -1438,7 +1438,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         } finally {
             if (startedVm == null) {
                 if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) {
-                    resourceCountDecrement(owner.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize()));
+                    _resourceLimitMgr.decrementVmResourceCount(owner.getAccountId(), vm.isDisplay(), offering, template);
                 }
                 if (canRetry) {
                     try {
@@ -2208,7 +2208,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
             if (result) {
                 if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) {
                     ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
-                    resourceCountDecrement(vm.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize()));
+                    VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
+                    _resourceLimitMgr.decrementVmResourceCount(vm.getAccountId(), vm.isDisplay(), offering, template);
                 }
             } else {
                 throw new CloudRuntimeException("unable to stop " + vm);
@@ -5605,18 +5606,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         return workJob;
     }
 
-    protected void resourceCountIncrement (long accountId, Long cpu, Long memory) {
-        _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.user_vm);
-        _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.cpu, cpu);
-        _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.memory, memory);
-    }
-
-    protected void resourceCountDecrement (long accountId, Long cpu, Long memory) {
-        _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.user_vm);
-        _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.cpu, cpu);
-        _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.memory, memory);
-    }
-
     @Override
     public UserVm restoreVirtualMachine(final long vmId, final Long newTemplateId) throws ResourceUnavailableException, InsufficientCapacityException {
         final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
@@ -6044,4 +6033,48 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         }
         return vmNetworkStatsById;
     }
+
+    protected boolean isDiskOfferingSuitableForVm(VMInstanceVO vm, VirtualMachineProfile profile, long podId, long clusterId, long hostId, long diskOfferingId) {
+
+        DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
+        VolumeVO dummyVolume = new VolumeVO("Data", vm.getDataCenterId(), podId, vm.getAccountId(),
+                vm.getDomainId(), vm.getId(), null, null, diskOffering.getProvisioningType(), diskOffering.getDiskSize(), Type.DATADISK);
+        try {
+            Field idField = dummyVolume.getClass().getDeclaredField("id");
+            idField.setAccessible(true);
+            idField.set(dummyVolume, Volume.DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID);
+        } catch (NoSuchFieldException | IllegalAccessException ignored) {
+            return false;
+        }
+        dummyVolume.setDiskOfferingId(diskOfferingId);
+        DiskProfile diskProfile = new DiskProfile(dummyVolume, diskOffering, profile.getHypervisorType());
+        diskProfile.setMinIops(diskOffering.getMinIops());
+        diskProfile.setMaxIops(diskOffering.getMaxIops());
+        ExcludeList avoid = new ExcludeList();
+        DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), podId, clusterId, hostId, null, null);
+        for (StoragePoolAllocator allocator : _storagePoolAllocators) {
+            List<StoragePool> poolListFromAllocator = allocator.allocateToPool(diskProfile, profile, plan, avoid, 1);
+            if (CollectionUtils.isNotEmpty(poolListFromAllocator)) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug(String.format("Found a suitable pool: %s for disk offering: %s", poolListFromAllocator.get(0).getName(), diskOffering.getName()));
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Map<Long, Boolean> getDiskOfferingSuitabilityForVm(long vmId, List<Long> diskOfferingIds) {
+        VMInstanceVO vm = _vmDao.findById(vmId);
+        VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
+        Pair<Long, Long> clusterAndHost = findClusterAndHostIdForVm(vm, false);
+        Long clusterId = clusterAndHost.first();
+        Cluster cluster = _clusterDao.findById(clusterId);
+        Map<Long, Boolean> result = new HashMap<>();
+        for (Long diskOfferingId : diskOfferingIds) {
+            result.put(diskOfferingId, isDiskOfferingSuitableForVm(vm, profile, cluster.getPodId(), clusterId, clusterAndHost.second(), diskOfferingId));
+        }
+        return result;
+    }
 }
diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
index 52fd962ba0a..3985fae7f5e 100644
--- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
+++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
@@ -130,6 +130,7 @@ import com.cloud.storage.Volume.Type;
 import com.cloud.storage.VolumeApiService;
 import com.cloud.storage.VolumeDetailVO;
 import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.StoragePoolHostDao;
 import com.cloud.storage.dao.VMTemplateDetailsDao;
@@ -245,6 +246,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
     PassphraseDao passphraseDao;
     @Inject
     StoragePoolHostDao storagePoolHostDao;
+    @Inject
+    DiskOfferingDao diskOfferingDao;
 
     @Inject
     protected SnapshotHelper snapshotHelper;
@@ -878,9 +881,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
         if (vm.getType() == VirtualMachine.Type.User) {
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null, size,
                     Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
-
-            _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, vol.isDisplayVolume());
-            _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, vol.isDisplayVolume(), new Long(vol.getSize()));
+            _resourceLimitMgr.incrementVolumeResourceCount(vm.getAccountId(), vol.isDisplayVolume(), vol.getSize(), offering);
         }
         DiskProfile diskProfile = toDiskProfile(vol, offering);
 
@@ -962,8 +963,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offeringId, vol.getTemplateId(), size,
                     Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
 
-            _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, vol.isDisplayVolume());
-            _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, vol.isDisplayVolume(), new Long(vol.getSize()));
+            _resourceLimitMgr.incrementVolumeResourceCount(vm.getAccountId(), vol.isDisplayVolume(), vol.getSize(), offering);
         }
         return toDiskProfile(vol, offering);
     }
@@ -1142,6 +1142,10 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
                 // Moving of Volume is successful, decrement the volume resource count from secondary for an account and increment it into primary storage under same account.
                 _resourceLimitMgr.decrementResourceCount(volumeInfo.getAccountId(), ResourceType.secondary_storage, volumeInfo.getSize());
                 _resourceLimitMgr.incrementResourceCount(volumeInfo.getAccountId(), ResourceType.primary_storage, volumeInfo.getSize());
+                List<String> tags = _resourceLimitMgr.getResourceLimitStorageTags(diskVO);
+                for (String tag : tags) {
+                    _resourceLimitMgr.incrementResourceCountWithTag(volumeInfo.getAccountId(), ResourceType.primary_storage, tag,  volumeInfo.getSize());
+                }
             }
         }
 
@@ -2102,8 +2106,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
             if (volume.getState() == Volume.State.Allocated) {
                 _volsDao.remove(volume.getId());
                 stateTransitTo(volume, Volume.Event.DestroyRequested);
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplay());
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplay(), new Long(volume.getSize()));
+                _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), volume.isDisplay(), volume.getSize(), diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()));
             } else {
                 destroyVolumeInContext(volume);
             }
diff --git a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java
index 97bd1f5f1b0..82ddce10958 100644
--- a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java
+++ b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -38,27 +39,12 @@ import java.util.Map;
 import java.util.Random;
 import java.util.stream.Collectors;
 
-import com.cloud.dc.ClusterDetailsDao;
-import com.cloud.dc.ClusterDetailsVO;
-import com.cloud.dc.Pod;
-import com.cloud.deploy.DeployDestination;
-import com.cloud.deploy.DeploymentPlanningManager;
-import com.cloud.hypervisor.HypervisorGuruManager;
-import com.cloud.org.Cluster;
-import com.cloud.template.VirtualMachineTemplate;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.utils.Journal;
-import com.cloud.utils.Pair;
-import com.cloud.utils.Ternary;
-import com.cloud.utils.db.EntityManager;
-import com.cloud.utils.fsm.StateMachine2;
-import com.cloud.vm.dao.UserVmDetailsDao;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.commons.collections.MapUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -71,6 +57,7 @@ import org.mockito.Mockito;
 import org.mockito.Spy;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
+import org.springframework.test.util.ReflectionTestUtils;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Command;
@@ -78,16 +65,25 @@ import com.cloud.agent.api.StopAnswer;
 import com.cloud.agent.api.StopCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.api.query.dao.UserVmJoinDao;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterDetailsVO;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.Pod;
+import com.cloud.dc.dao.ClusterDao;
 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.InvalidParameterValueException;
 import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.hypervisor.HypervisorGuruManager;
 import com.cloud.offering.ServiceOffering;
+import com.cloud.org.Cluster;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.DiskOfferingVO;
@@ -105,11 +101,19 @@ import com.cloud.storage.dao.StoragePoolHostDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VMTemplateZoneDao;
 import com.cloud.storage.dao.VolumeDao;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.utils.Journal;
+import com.cloud.utils.Pair;
+import com.cloud.utils.Ternary;
+import com.cloud.utils.db.EntityManager;
 import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.fsm.StateMachine2;
 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 org.springframework.test.util.ReflectionTestUtils;
 
 @RunWith(MockitoJUnitRunner.class)
 public class VirtualMachineManagerImplTest {
@@ -184,6 +188,8 @@ public class VirtualMachineManagerImplTest {
     @Mock
     private HypervisorGuruManager _hvGuruMgr;
     @Mock
+    private ClusterDao clusterDao;
+    @Mock
     private ClusterDetailsDao _clusterDetailsDao;
     @Mock
     private UserVmDetailsDao userVmDetailsDao;
@@ -1117,4 +1123,47 @@ public class VirtualMachineManagerImplTest {
 
         assertNull(vmInstance.getPodIdToDeployIn());
     }
+
+    @Test
+    public void testIsDiskOfferingSuitableForVmSuccess() {
+        Mockito.doReturn(Mockito.mock(DiskOfferingVO.class)).when(diskOfferingDaoMock).findById(anyLong());
+        List<StoragePool> poolListMock = new ArrayList<>();
+        poolListMock.add(storagePoolVoMock);
+        Mockito.doReturn(poolListMock).when(storagePoolAllocatorMock).allocateToPool(any(DiskProfile.class), any(VirtualMachineProfile.class), any(DeploymentPlan.class),
+                any(ExcludeList.class), Mockito.eq(1));
+        boolean result = virtualMachineManagerImpl.isDiskOfferingSuitableForVm(vmInstanceMock, virtualMachineProfileMock, 1L, 1L,1L, 1L);
+        assertTrue(result);
+    }
+
+    @Test
+    public void testIsDiskOfferingSuitableForVmNegative() {
+        Mockito.doReturn(Mockito.mock(DiskOfferingVO.class)).when(diskOfferingDaoMock).findById(anyLong());
+        Mockito.doReturn(new ArrayList<>()).when(storagePoolAllocatorMock).allocateToPool(any(DiskProfile.class), any(VirtualMachineProfile.class), any(DeploymentPlan.class),
+                any(ExcludeList.class), Mockito.eq(1));
+        boolean result = virtualMachineManagerImpl.isDiskOfferingSuitableForVm(vmInstanceMock, virtualMachineProfileMock, 1L, 1L,1L, 1L);
+        assertFalse(result);
+    }
+
+    @Test
+    public void testGetDiskOfferingSuitabilityForVm() {
+        Mockito.doReturn(vmInstanceMock).when(vmInstanceDaoMock).findById(1L);
+        Mockito.when(vmInstanceMock.getHostId()).thenReturn(1L);
+        Mockito.doReturn(hostMock).when(hostDaoMock).findById(1L);
+        Mockito.when(hostMock.getClusterId()).thenReturn(1L);
+        ClusterVO cluster = Mockito.mock(ClusterVO.class);
+        Mockito.when(cluster.getPodId()).thenReturn(1L);
+        Mockito.doReturn(cluster).when(clusterDao).findById(1L);
+        List<Long> diskOfferingIds = List.of(1L, 2L);
+        Mockito.doReturn(false).when(virtualMachineManagerImpl)
+                .isDiskOfferingSuitableForVm(eq(vmInstanceMock), any(VirtualMachineProfile.class),
+                        eq(1L), eq(1L), eq(1L), eq(1L));
+        Mockito.doReturn(true).when(virtualMachineManagerImpl)
+                .isDiskOfferingSuitableForVm(eq(vmInstanceMock), any(VirtualMachineProfile.class),
+                        eq(1L), eq(1L), eq(1L), eq(2L));
+        Map<Long, Boolean> result = virtualMachineManagerImpl.getDiskOfferingSuitabilityForVm(1L, diskOfferingIds);
+        assertTrue(MapUtils.isNotEmpty(result));
+        assertEquals(2, result.keySet().size());
+        assertFalse(result.get(1L));
+        assertTrue(result.get(2L));
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java b/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java
index 50c40134a91..132fd3fe5a2 100644
--- a/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java
+++ b/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java
@@ -80,6 +80,9 @@ public class CapacityVO implements Capacity {
     @Transient
     private Long allocatedCapacity;
 
+    @Transient
+    private String tag;
+
     public CapacityVO() {
     }
 
@@ -221,6 +224,15 @@ public class CapacityVO implements Capacity {
         this.allocatedCapacity = allocatedCapacity;
     }
 
+    @Override
+    public String getTag() {
+        return tag;
+    }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
+
     @Override
     public String getUuid() {
         return null;  //To change body of implemented methods use File | Settings | File Templates.
diff --git a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java
index 459a63a7ba1..9616f31d0c5 100644
--- a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java
+++ b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java
@@ -44,6 +44,8 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
 
     List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId);
 
+    List<SummedCapacity> findFilteredCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, List<Long> hostIds, List<Long> poolIds);
+
     List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType);
 
     Pair<List<Long>, Map<Long, Double>> orderPodsByAggregateCapacity(long zoneId, short capacityType);
@@ -51,7 +53,8 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
     List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId,
         Long podId, Long clusterId, String resourceState);
 
-    List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit);
+    List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId,
+         Long clusterId, int level, List<Long> hostIds, List<Long> poolIds, Long limit);
 
     void updateCapacityState(Long dcId, Long podId, Long clusterId, Long hostId, String capacityState, short[] capacityType);
 
diff --git a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
index 67d037319d5..3acae985af4 100644
--- a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
@@ -26,11 +26,11 @@ import java.util.Map;
 
 import javax.inject.Inject;
 
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Component;
 
 import com.cloud.capacity.Capacity;
 import com.cloud.capacity.CapacityVO;
@@ -339,7 +339,8 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
     }
 
     @Override
-    public List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit) {
+    public List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId,
+        Long clusterId, int level, List<Long> hostIds, List<Long> poolIds, Long limit) {
 
         StringBuilder finalQuery = new StringBuilder();
         TransactionLegacy txn = TransactionLegacy.currentTxn();
@@ -378,6 +379,18 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             finalQuery.append(" AND capacity_type = ?");
             resourceIdList.add(capacityType.longValue());
         }
+        if (CollectionUtils.isNotEmpty(hostIds)) {
+            finalQuery.append(String.format(" AND capacity.host_id IN (%s)", StringUtils.join(hostIds, ",")));
+            if (capacityType == null) {
+                finalQuery.append(String.format(" AND capacity_type NOT IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ",")));
+            }
+        }
+        if (CollectionUtils.isNotEmpty(poolIds)) {
+            finalQuery.append(String.format(" AND capacity.host_id IN (%s)", StringUtils.join(poolIds, ",")));
+            if (capacityType == null) {
+                finalQuery.append(String.format(" AND capacity_type IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ",")));
+            }
+        }
 
         switch (level) {
         case 1: // List all the capacities grouped by zone, capacity Type
@@ -461,8 +474,37 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
         }
     }
 
+    protected String getHostAndPoolConditionForFilteredCapacity(Integer capacityType, List<Long> hostIds, List<Long> poolIds) {
+        StringBuilder sql = new StringBuilder();
+        if (CollectionUtils.isEmpty(hostIds) && CollectionUtils.isEmpty(poolIds)) {
+            return "";
+        }
+        sql.append(" AND (");
+        boolean hostConditionAdded = false;
+        if (CollectionUtils.isNotEmpty(hostIds) && (capacityType == null || !Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue()))) {
+            sql.append(String.format("(capacity.host_id IN (%s)", StringUtils.join(hostIds, ",")));
+            if (capacityType == null) {
+                sql.append(String.format(" AND capacity_type NOT IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ",")));
+            }
+            sql.append(")");
+            hostConditionAdded = true;
+        }
+        if (CollectionUtils.isNotEmpty(poolIds) && (capacityType == null || Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue()))) {
+            if (hostConditionAdded) {
+                sql.append(" OR ");
+            }
+            sql.append(String.format("(capacity.host_id IN (%s)", StringUtils.join(poolIds, ",")));
+            if (capacityType == null || Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue())) {
+                sql.append(String.format(" AND capacity_type IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ",")));
+            }
+            sql.append(")");
+        }
+        sql.append(")");
+        return sql.toString();
+    }
+
     @Override
-    public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId) {
+    public List<SummedCapacity> findFilteredCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, List<Long> hostIds, List<Long> poolIds) {
 
         TransactionLegacy txn = TransactionLegacy.currentTxn();
         PreparedStatement pstmt = null;
@@ -516,6 +558,8 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
             resourceIdList.add(capacityType.longValue());
         }
 
+        sql.append(getHostAndPoolConditionForFilteredCapacity(capacityType, hostIds, poolIds));
+
         if (podId == null && clusterId == null) {
             sql.append(" GROUP BY capacity_type, data_center_id");
         } else {
@@ -591,6 +635,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
         }
     }
 
+    @Override
+    public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId) {
+        return findFilteredCapacityBy(capacityType, zoneId, podId, clusterId, null, null);
+    }
+
     public void updateAllocated(Long hostId, long allocatedAmount, short capacityType, boolean add) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();
         PreparedStatement pstmt = null;
@@ -702,6 +751,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
         public Long clusterId;
         public Long podId;
         public Long dcId;
+        public String tag;
 
         public SummedCapacity() {
         }
@@ -790,6 +840,14 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
         public void setAllocatedCapacity(Long sumAllocated) {
             this.sumAllocated = sumAllocated;
         }
+
+        public String getTag() {
+            return tag;
+        }
+
+        public void setTag(String tag) {
+            this.tag = tag;
+        }
     }
 
     @Override
diff --git a/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java b/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java
index ae8f3822704..9e39a608f9e 100644
--- a/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java
+++ b/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java
@@ -47,10 +47,13 @@ public class ResourceCountVO implements ResourceCount {
     @Column(name = "count")
     private long count;
 
+    @Column(name = "tag")
+    private String tag;
+
     public ResourceCountVO() {
     }
 
-    public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType) {
+    public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType, String tag) {
         this.type = type;
         this.count = count;
 
@@ -59,6 +62,11 @@ public class ResourceCountVO implements ResourceCount {
         } else if (ownerType == ResourceOwnerType.Domain) {
             this.domainId = ownerId;
         }
+        this.tag = tag;
+    }
+
+    public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType) {
+        this(type, count, ownerId, ownerType, null);
     }
 
     @Override
@@ -99,7 +107,7 @@ public class ResourceCountVO implements ResourceCount {
 
     @Override
     public String toString() {
-        return new StringBuilder("REsourceCount[").append("-")
+        return new StringBuilder("ResourceCount[").append("-")
             .append(id)
             .append("-")
             .append(type)
@@ -107,6 +115,8 @@ public class ResourceCountVO implements ResourceCount {
             .append(accountId)
             .append("-")
             .append(domainId)
+            .append("-")
+            .append(tag)
             .append("]")
             .toString();
     }
@@ -136,4 +146,13 @@ public class ResourceCountVO implements ResourceCount {
     public void setAccountId(Long accountId) {
         this.accountId = accountId;
     }
+
+    @Override
+    public String getTag() {
+        return tag;
+    }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java b/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java
index 39217091975..1619537ae74 100644
--- a/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java
+++ b/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java
@@ -47,10 +47,13 @@ public class ResourceLimitVO implements ResourceLimit {
     @Column(name = "max")
     private Long max;
 
+    @Column(name = "tag")
+    private String tag;
+
     public ResourceLimitVO() {
     }
 
-    public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType) {
+    public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType, String tag) {
         this.type = type;
         this.max = max;
 
@@ -59,6 +62,11 @@ public class ResourceLimitVO implements ResourceLimit {
         } else if (ownerType == ResourceOwnerType.Domain) {
             this.domainId = ownerId;
         }
+        this.tag = tag;
+    }
+
+    public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType) {
+        this(type, max, ownerId, ownerType, null);
     }
 
     @Override
@@ -123,4 +131,12 @@ public class ResourceLimitVO implements ResourceLimit {
         this.accountId = accountId;
     }
 
+    @Override
+    public String getTag() {
+        return tag;
+    }
+
+    public void setTag(String tag) {
+        this.tag = tag;
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java
index 28f2a536071..59e64dac880 100644
--- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java
+++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java
@@ -26,18 +26,20 @@ import com.cloud.utils.db.GenericDao;
 
 public interface ResourceCountDao extends GenericDao<ResourceCountVO, Long> {
     /**
-     * @param domainId the id of the domain to get the resource count
+     * @param ownerId the id of the owner to get the resource count
      * @param type the type of resource (e.g. user_vm, public_ip, volume)
+     * @param tag for the type of resource
      * @return the count of resources in use for the given type and domain
      */
-    long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type);
+    long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag);
 
     /**
-     * @param domainId the id of the domain to set the resource count
+     * @param ownerId the id of the owner to set the resource count
      * @param type the type of resource (e.g. user_vm, public_ip, volume)
-     * @param the count of resources in use for the given type and domain
+     * @param tag the tag for the type of resource
+     * @param count the count of resources in use for the given type and domain
      */
-    void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count);
+    void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag, long count);
 
     boolean updateById(long id, boolean increment, long delta);
 
@@ -45,13 +47,13 @@ public interface ResourceCountDao extends GenericDao<ResourceCountVO, Long> {
 
     List<ResourceCountVO> listByOwnerId(long ownerId, ResourceOwnerType ownerType);
 
-    ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type);
+    ResourceCountVO findByOwnerAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag);
 
     List<ResourceCountVO> listResourceCountByOwnerType(ResourceOwnerType ownerType);
 
-    Set<Long> listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type);
+    Set<Long> listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag);
 
-    Set<Long> listRowsToUpdateForDomain(long domainId, ResourceType type);
+    Set<Long> listRowsToUpdateForDomain(long domainId, ResourceType type, String tag);
 
     long removeEntriesByOwner(long ownerId, ResourceOwnerType ownerType);
 
@@ -68,4 +70,6 @@ public interface ResourceCountDao extends GenericDao<ResourceCountVO, Long> {
      * Side note: This method is not using the "resource_count" table. It is executing the actual count instead.
      */
     long countMemoryAllocatedToAccount(long accountId);
+
+    void removeResourceCountsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List<ResourceType> types, List<String> tags);
 }
diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java
index ca6f13d2d64..c90422377b8 100644
--- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java
@@ -20,6 +20,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -27,6 +28,9 @@ import java.util.Set;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
 import com.cloud.configuration.Resource;
@@ -37,6 +41,7 @@ import com.cloud.configuration.ResourceLimit;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.user.AccountVO;
+import com.cloud.user.ResourceLimitService;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
@@ -49,6 +54,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
 @Component
 public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long> implements ResourceCountDao {
     private final SearchBuilder<ResourceCountVO> TypeSearch;
+    private final SearchBuilder<ResourceCountVO> TypeNullTagSearch;
+    private final SearchBuilder<ResourceCountVO> NonMatchingTagsSearch;
 
     private final SearchBuilder<ResourceCountVO> AccountSearch;
     private final SearchBuilder<ResourceCountVO> DomainSearch;
@@ -63,8 +70,24 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
         TypeSearch.and("type", TypeSearch.entity().getType(), SearchCriteria.Op.EQ);
         TypeSearch.and("accountId", TypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         TypeSearch.and("domainId", TypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        TypeSearch.and("tag", TypeSearch.entity().getTag(), SearchCriteria.Op.EQ);
         TypeSearch.done();
 
+        TypeNullTagSearch = createSearchBuilder();
+        TypeNullTagSearch.and("type", TypeNullTagSearch.entity().getType(), SearchCriteria.Op.EQ);
+        TypeNullTagSearch.and("accountId", TypeNullTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        TypeNullTagSearch.and("domainId", TypeNullTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        TypeNullTagSearch.and("tag", TypeNullTagSearch.entity().getTag(), SearchCriteria.Op.NULL);
+        TypeNullTagSearch.done();
+
+        NonMatchingTagsSearch = createSearchBuilder();
+        NonMatchingTagsSearch.and("accountId", NonMatchingTagsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        NonMatchingTagsSearch.and("domainId", NonMatchingTagsSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        NonMatchingTagsSearch.and("types", NonMatchingTagsSearch.entity().getType(), SearchCriteria.Op.IN);
+        NonMatchingTagsSearch.and("tagNotNull", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NNULL);
+        NonMatchingTagsSearch.and("tags", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NIN);
+        NonMatchingTagsSearch.done();
+
         AccountSearch = createSearchBuilder();
         DomainSearch = createSearchBuilder();
     }
@@ -85,9 +108,12 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
     }
 
     @Override
-    public ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
-        SearchCriteria<ResourceCountVO> sc = TypeSearch.create();
+    public ResourceCountVO findByOwnerAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) {
+        SearchCriteria<ResourceCountVO> sc = tag != null ? TypeSearch.create() : TypeNullTagSearch.create();
         sc.setParameters("type", type);
+        if (tag != null) {
+            sc.setParameters("tag", tag);
+        }
 
         if (ownerType == ResourceOwnerType.Account) {
             sc.setParameters("accountId", ownerId);
@@ -101,8 +127,8 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
     }
 
     @Override
-    public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
-        ResourceCountVO vo = findByOwnerAndType(ownerId, ownerType, type);
+    public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) {
+        ResourceCountVO vo = findByOwnerAndTypeAndTag(ownerId, ownerType, type, tag);
         if (vo != null) {
             return vo.getCount();
         } else {
@@ -111,8 +137,8 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
     }
 
     @Override
-    public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count) {
-        ResourceCountVO resourceCountVO = findByOwnerAndType(ownerId, ownerType, type);
+    public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag, long count) {
+        ResourceCountVO resourceCountVO = findByOwnerAndTypeAndTag(ownerId, ownerType, type, tag);
         if (resourceCountVO != null && count != resourceCountVO.getCount()) {
             resourceCountVO.setCount(count);
             update(resourceCountVO.getId(), resourceCountVO);
@@ -129,38 +155,59 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
     }
 
     @Override
-    public Set<Long> listRowsToUpdateForDomain(long domainId, ResourceType type) {
+    public Set<Long> listRowsToUpdateForDomain(long domainId, ResourceType type, String tag) {
         Set<Long> rowIds = new HashSet<Long>();
         Set<Long> domainIdsToUpdate = _domainDao.getDomainParentIds(domainId);
         for (Long domainIdToUpdate : domainIdsToUpdate) {
-            ResourceCountVO domainCountRecord = findByOwnerAndType(domainIdToUpdate, ResourceOwnerType.Domain, type);
+            ResourceCountVO domainCountRecord = findByOwnerAndTypeAndTag(domainIdToUpdate, ResourceOwnerType.Domain, type, tag);
             if (domainCountRecord != null) {
                 rowIds.add(domainCountRecord.getId());
+            } else {
+                if (StringUtils.isNotEmpty(tag)) {
+                    ResourceCountVO resourceCountVO = createTaggedResourceCount(domainIdToUpdate, ResourceOwnerType.Domain, type, tag);
+                    rowIds.add(resourceCountVO.getId());
+                }
             }
         }
         return rowIds;
     }
 
     @Override
-    public Set<Long> listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
+    public Set<Long> listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) {
         Set<Long> rowIds = new HashSet<Long>();
 
         if (ownerType == ResourceOwnerType.Account) {
             //get records for account
-            ResourceCountVO accountCountRecord = findByOwnerAndType(ownerId, ResourceOwnerType.Account, type);
+            ResourceCountVO accountCountRecord = findByOwnerAndTypeAndTag(ownerId, ResourceOwnerType.Account, type, tag);
             if (accountCountRecord != null) {
                 rowIds.add(accountCountRecord.getId());
+            } else {
+                if (StringUtils.isNotEmpty(tag)) {
+                    ResourceCountVO resourceCountVO = createTaggedResourceCount(ownerId, ownerType, type, tag);
+                    rowIds.add(resourceCountVO.getId());
+                }
             }
 
             //get records for account's domain and all its parent domains
-            rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(), type));
+            rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(), type, tag));
         } else if (ownerType == ResourceOwnerType.Domain) {
-            return listRowsToUpdateForDomain(ownerId, type);
+            rowIds = listRowsToUpdateForDomain(ownerId, type, tag);
         }
 
         return rowIds;
     }
 
+    protected ResourceCountVO createTaggedResourceCount(long ownerId, ResourceLimit.ResourceOwnerType ownerType, ResourceType resourceType, String tag) {
+        ResourceCountVO taggedResourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType, tag);
+        return persist(taggedResourceCountVO);
+    }
+
+    protected void createTaggedResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType, ResourceType resourceType, List<String> tags) {
+        for (String tag : tags) {
+            createTaggedResourceCount(ownerId, ownerType, resourceType, tag);
+        }
+    }
+
     @Override
     @DB
     public void createResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType) {
@@ -169,9 +216,23 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
         txn.start();
 
         ResourceType[] resourceTypes = Resource.ResourceType.values();
+        List<String> hostTags = new ArrayList<>();
+        if (StringUtils.isNotEmpty(ResourceLimitService.ResourceLimitHostTags.value())) {
+            hostTags = Arrays.asList(ResourceLimitService.ResourceLimitHostTags.value().split(","));
+        }
+        List<String> storageTags = new ArrayList<>();
+        if (StringUtils.isNotEmpty(ResourceLimitService.ResourceLimitStorageTags.value())) {
+            storageTags = Arrays.asList(ResourceLimitService.ResourceLimitStorageTags.value().split(","));
+        }
         for (ResourceType resourceType : resourceTypes) {
             ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType);
             persist(resourceCountVO);
+            if (ResourceLimitService.HostTagsSupportingTypes.contains(resourceType)) {
+                createTaggedResourceCounts(ownerId, ownerType, resourceType, hostTags);
+            }
+            if (ResourceLimitService.StorageTagsSupportingTypes.contains(resourceType)) {
+                createTaggedResourceCounts(ownerId, ownerType, resourceType, storageTags);
+            }
         }
 
         txn.commit();
@@ -266,4 +327,22 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
         }
     }
 
+    @Override
+    public void removeResourceCountsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List<ResourceType> types, List<String> tags) {
+        SearchCriteria<ResourceCountVO> sc = NonMatchingTagsSearch.create();
+        if (ObjectUtils.allNotNull(ownerId, ownerType)) {
+            if (ResourceOwnerType.Account.equals(ownerType)) {
+                sc.setParameters("accountId", ownerId);
+            } else {
+                sc.setParameters("domainId", ownerId);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(types)) {
+            sc.setParameters("types", types.stream().map(ResourceType::getName).toArray());
+        }
+        if (CollectionUtils.isNotEmpty(tags)) {
+            sc.setParameters("tags", tags.toArray());
+        }
+        remove(sc);
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java
index e47b38340c2..7cdc2aacc3b 100644
--- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java
+++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java
@@ -18,6 +18,7 @@ package com.cloud.configuration.dao;
 
 import java.util.List;
 
+import com.cloud.configuration.Resource;
 import com.cloud.configuration.Resource.ResourceOwnerType;
 import com.cloud.configuration.ResourceCount;
 import com.cloud.configuration.ResourceLimitVO;
@@ -31,7 +32,8 @@ public interface ResourceLimitDao extends GenericDao<ResourceLimitVO, Long> {
 
     ResourceCount.ResourceType getLimitType(String type);
 
-    ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type);
+    ResourceLimitVO findByOwnerIdAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type, String tag);
 
     long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType);
+    void removeResourceLimitsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List<Resource.ResourceType> types, List<String> tags);
 }
diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java
index 03c2d2a4624..96523ba9bea 100644
--- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.List;
 
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.stereotype.Component;
 
 import com.cloud.configuration.Resource;
@@ -33,19 +35,36 @@ import com.cloud.utils.db.SearchCriteria;
 
 @Component
 public class ResourceLimitDaoImpl extends GenericDaoBase<ResourceLimitVO, Long> implements ResourceLimitDao {
-    private SearchBuilder<ResourceLimitVO> IdTypeSearch;
+    private SearchBuilder<ResourceLimitVO> IdTypeTagSearch;
+    private SearchBuilder<ResourceLimitVO> IdTypeNullTagSearch;
+    private SearchBuilder<ResourceLimitVO> NonMatchingTagsSearch;
 
     public ResourceLimitDaoImpl() {
-        IdTypeSearch = createSearchBuilder();
-        IdTypeSearch.and("type", IdTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
-        IdTypeSearch.and("domainId", IdTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
-        IdTypeSearch.and("accountId", IdTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
-        IdTypeSearch.done();
+        IdTypeTagSearch = createSearchBuilder();
+        IdTypeTagSearch.and("type", IdTypeTagSearch.entity().getType(), SearchCriteria.Op.EQ);
+        IdTypeTagSearch.and("domainId", IdTypeTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        IdTypeTagSearch.and("accountId", IdTypeTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        IdTypeTagSearch.and("tag", IdTypeTagSearch.entity().getTag(), SearchCriteria.Op.EQ);
+
+        IdTypeNullTagSearch = createSearchBuilder();
+        IdTypeNullTagSearch.and("type", IdTypeNullTagSearch.entity().getType(), SearchCriteria.Op.EQ);
+        IdTypeNullTagSearch.and("domainId", IdTypeNullTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        IdTypeNullTagSearch.and("accountId", IdTypeNullTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        IdTypeNullTagSearch.and("tag", IdTypeNullTagSearch.entity().getTag(), SearchCriteria.Op.NULL);
+        IdTypeNullTagSearch.done();
+
+        NonMatchingTagsSearch = createSearchBuilder();
+        NonMatchingTagsSearch.and("accountId", NonMatchingTagsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        NonMatchingTagsSearch.and("domainId", NonMatchingTagsSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+        NonMatchingTagsSearch.and("types", NonMatchingTagsSearch.entity().getType(), SearchCriteria.Op.IN);
+        NonMatchingTagsSearch.and("tagNotNull", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NNULL);
+        NonMatchingTagsSearch.and("tags", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NIN);
+        NonMatchingTagsSearch.done();
     }
 
     @Override
     public List<ResourceLimitVO> listByOwner(Long ownerId, ResourceOwnerType ownerType) {
-        SearchCriteria<ResourceLimitVO> sc = IdTypeSearch.create();
+        SearchCriteria<ResourceLimitVO> sc = IdTypeTagSearch.create();
 
         if (ownerType == ResourceOwnerType.Account) {
             sc.setParameters("accountId", ownerId);
@@ -81,9 +100,12 @@ public class ResourceLimitDaoImpl extends GenericDaoBase<ResourceLimitVO, Long>
     }
 
     @Override
-    public ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type) {
-        SearchCriteria<ResourceLimitVO> sc = IdTypeSearch.create();
+    public ResourceLimitVO findByOwnerIdAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type, String tag) {
+        SearchCriteria<ResourceLimitVO> sc = tag != null ? IdTypeTagSearch.create() : IdTypeNullTagSearch.create();
         sc.setParameters("type", type);
+        if (tag != null) {
+            sc.setParameters("tag", tag);
+        }
 
         if (ownerType == ResourceOwnerType.Account) {
             sc.setParameters("accountId", ownerId);
@@ -98,7 +120,7 @@ public class ResourceLimitDaoImpl extends GenericDaoBase<ResourceLimitVO, Long>
 
     @Override
     public long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType) {
-        SearchCriteria<ResourceLimitVO> sc = IdTypeSearch.create();
+        SearchCriteria<ResourceLimitVO> sc = IdTypeTagSearch.create();
 
         if (ownerType == ResourceOwnerType.Account) {
             sc.setParameters("accountId", ownerId);
@@ -109,4 +131,23 @@ public class ResourceLimitDaoImpl extends GenericDaoBase<ResourceLimitVO, Long>
         }
         return 0;
     }
+
+    @Override
+    public void removeResourceLimitsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List<ResourceType> types, List<String> tags) {
+        SearchCriteria<ResourceLimitVO> sc = NonMatchingTagsSearch.create();
+        if (ObjectUtils.allNotNull(ownerId, ownerType)) {
+            if (ResourceOwnerType.Account.equals(ownerType)) {
+                sc.setParameters("accountId", ownerId);
+            } else {
+                sc.setParameters("domainId", ownerId);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(types)) {
+            sc.setParameters("types", types.stream().map(ResourceType::getName).toArray());
+        }
+        if (CollectionUtils.isNotEmpty(tags)) {
+            sc.setParameters("tags", tags.toArray());
+        }
+        remove(sc);
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/host/HostVO.java b/engine/schema/src/main/java/com/cloud/host/HostVO.java
index b7cac8ff8cb..ab3d2ecc009 100644
--- a/engine/schema/src/main/java/com/cloud/host/HostVO.java
+++ b/engine/schema/src/main/java/com/cloud/host/HostVO.java
@@ -16,8 +16,11 @@
 // under the License.
 package com.cloud.host;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -39,21 +42,21 @@ import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 
+import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper;
+import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+
 import com.cloud.agent.api.VgpuTypesInfo;
 import com.cloud.host.dao.HostTagsDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.offering.ServiceOffering;
 import com.cloud.resource.ResourceState;
 import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.util.StoragePoolTypeConverter;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.db.GenericDao;
-import java.util.Arrays;
-
-import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper;
-import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
-import org.apache.commons.lang.BooleanUtils;
-import org.apache.commons.lang3.StringUtils;
 
 @Entity
 @Table(name = "host")
@@ -764,7 +767,28 @@ public class HostVO implements Host {
         this.uuid = uuid;
     }
 
-    public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering){
+    public boolean checkHostServiceOfferingAndTemplateTags(ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        if (serviceOffering == null || template == null) {
+            return false;
+        }
+        if (StringUtils.isEmpty(serviceOffering.getHostTag()) && StringUtils.isEmpty(template.getTemplateTag())) {
+            return true;
+        }
+        if (getHostTags() == null) {
+            return false;
+        }
+        HashSet<String> hostTagsSet = new HashSet<>(getHostTags());
+        List<String> tags = new ArrayList<>();
+        if (StringUtils.isNotEmpty(serviceOffering.getHostTag())) {
+            tags.addAll(Arrays.asList(serviceOffering.getHostTag().split(",")));
+        }
+        if (StringUtils.isNotEmpty(template.getTemplateTag()) && !tags.contains(template.getTemplateTag())) {
+            tags.add(template.getTemplateTag());
+        }
+        return hostTagsSet.containsAll(tags);
+    }
+
+    public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering) {
         if (serviceOffering == null) {
             return false;
         }
@@ -776,7 +800,6 @@ public class HostVO implements Host {
         if (StringUtils.isEmpty(serviceOffering.getHostTag())) {
             return true;
         }
-
         List<String> serviceOfferingTags = Arrays.asList(serviceOffering.getHostTag().split(","));
         return this.getHostTags() != null && this.getHostTags().containsAll(serviceOfferingTags);
     }
diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
index fe30722feb1..ca180e2323f 100644
--- a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
+++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
@@ -63,7 +63,7 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
 
     void loadHostTags(HostVO host);
 
-    List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag);
+    List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag);
 
     List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId);
 
diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
index 9eadab76b2c..5faa877b458 100644
--- a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java
@@ -780,7 +780,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
     }
 
     @Override
-    public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) {
+    public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag) {
         SearchBuilder<HostVO> hostSearch = createSearchBuilder();
         HostVO entity = hostSearch.entity();
         hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ);
@@ -798,7 +798,9 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
         if (clusterId != null) {
             sc.setParameters("cluster", clusterId);
         }
-        sc.setParameters("dc", dcId);
+        if (dcId != null) {
+            sc.setParameters("dc", dcId);
+        }
         sc.setParameters("status", Status.Up.toString());
         sc.setParameters("resourceState", ResourceState.Enabled.toString());
 
diff --git a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java
index e2fc5b49ae8..d086ad1dac1 100644
--- a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java
+++ b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java
@@ -55,4 +55,6 @@ public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long>
     List<ServiceOfferingVO> listPublicByCpuAndMemory(Integer cpus, Integer memory);
 
     ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskOfferingId);
+
+    List<ServiceOfferingVO> listByHostTag(String tag);
 }
diff --git a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java
index f83ab7f98a4..34ac7c47521 100644
--- a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java
@@ -291,4 +291,22 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
         }
         return vos.get(0);
     }
+
+    @Override
+    public List<ServiceOfferingVO> listByHostTag(String tag) {
+        SearchBuilder<ServiceOfferingVO> sb = createSearchBuilder();
+        sb.and("tagNotNull", sb.entity().getHostTag(), SearchCriteria.Op.NNULL);
+        sb.and().op("tagEq", sb.entity().getHostTag(), SearchCriteria.Op.EQ);
+        sb.or("tagStartLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE);
+        sb.or("tagMidLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE);
+        sb.or("tagEndLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE);
+        sb.cp();
+        sb.done();
+        SearchCriteria<ServiceOfferingVO> sc = sb.create();
+        sc.setParameters("tagEq", tag);
+        sc.setParameters("tagStartLike", tag + ",%");
+        sc.setParameters("tagMidLike", "%," + tag + ",%");
+        sc.setParameters("tagEndLike",   "%," + tag);
+        return listBy(sc);
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java
index 5a49d0b5192..f726bca3c5d 100644
--- a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java
@@ -31,5 +31,6 @@ public interface DiskOfferingDao extends GenericDao<DiskOfferingVO, Long> {
     List<DiskOfferingVO> listAllBySizeAndProvisioningType(long size, Storage.ProvisioningType provisioningType);
 
     List<DiskOfferingVO> findCustomDiskOfferings();
+    List<DiskOfferingVO> listByStorageTag(String tag);
 
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java
index 78b2a542837..853a9998226 100644
--- a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java
@@ -157,4 +157,22 @@ public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> im
 
         return update(id, diskOffering);
     }
+
+    @Override
+    public List<DiskOfferingVO> listByStorageTag(String tag) {
+        SearchBuilder<DiskOfferingVO> sb = createSearchBuilder();
+        sb.and("tagNotNull", sb.entity().getTags(), SearchCriteria.Op.NNULL);
+        sb.and().op("tagEq", sb.entity().getTags(), SearchCriteria.Op.EQ);
+        sb.or("tagStartLike", sb.entity().getTags(), SearchCriteria.Op.LIKE);
+        sb.or("tagMidLike", sb.entity().getTags(), SearchCriteria.Op.LIKE);
+        sb.or("tagEndLike", sb.entity().getTags(), SearchCriteria.Op.LIKE);
+        sb.cp();
+        sb.done();
+        SearchCriteria<DiskOfferingVO> sc = sb.create();
+        sc.setParameters("tagEq", tag);
+        sc.setParameters("tagStartLike", tag + ",%");
+        sc.setParameters("tagMidLike", "%," + tag + ",%");
+        sc.setParameters("tagEndLike",   "%," + tag);
+        return listBy(sc);
+    }
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java
index 9352ee21858..a4b87ef025f 100755
--- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java
@@ -34,5 +34,6 @@ public interface StoragePoolTagsDao extends GenericDao<StoragePoolTagVO, Long> {
     StorageTagResponse newStorageTagResponse(StoragePoolTagVO tag);
 
     List<StoragePoolTagVO> findStoragePoolTags(long poolId);
+    List<Long> listPoolIdsByTag(String tag);
 
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java
index c01c66763af..c4d7ed88607 100755
--- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java
@@ -18,12 +18,10 @@ package com.cloud.storage.dao;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
-import com.cloud.utils.db.Transaction;
-import com.cloud.utils.db.TransactionCallbackNoReturn;
-import com.cloud.utils.db.TransactionStatus;
 import org.apache.cloudstack.api.response.StorageTagResponse;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 
@@ -31,7 +29,10 @@ import com.cloud.storage.StoragePoolTagVO;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
 import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.utils.db.TransactionStatus;
 
 public class StoragePoolTagsDaoImpl extends GenericDaoBase<StoragePoolTagVO, Long> implements StoragePoolTagsDao {
 
@@ -178,4 +179,15 @@ public class StoragePoolTagsDaoImpl extends GenericDaoBase<StoragePoolTagVO, Lon
         return search(sc, null);
     }
 
+    @Override
+    public List<Long> listPoolIdsByTag(String tag) {
+        SearchBuilder<StoragePoolTagVO> sb = createSearchBuilder();
+        sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ);
+        sb.done();
+        SearchCriteria<StoragePoolTagVO> sc = sb.create();
+        sc.setParameters("tag", tag);
+        List<StoragePoolTagVO> poolRefs = search(sc, null);
+        return poolRefs.stream().map(StoragePoolTagVO::getPoolId).collect(Collectors.toList());
+    }
+
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java
index 708a77a8f9e..1c5a2cb4256 100644
--- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java
@@ -90,4 +90,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
     List<VMTemplateVO> findTemplatesLinkedToUserdata(long userdataId);
 
     List<VMTemplateVO> listByIds(List<Long> ids);
+
+    List<VMTemplateVO> listByTemplateTag(String tag);
+
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java
index 03678732d1c..4665f660251 100644
--- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java
@@ -686,6 +686,16 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
         return result;
     }
 
+    @Override
+    public List<VMTemplateVO> listByTemplateTag(String tag) {
+        SearchBuilder<VMTemplateVO> sb = createSearchBuilder();
+        sb.and("tag", sb.entity().getTemplateTag(), SearchCriteria.Op.EQ);
+        sb.done();
+        SearchCriteria<VMTemplateVO> sc = sb.create();
+        sc.setParameters("tag", tag);
+        return listIncludingRemovedBy(sc);
+    }
+
     @Override
     public boolean updateState(
             com.cloud.template.VirtualMachineTemplate.State currentState,
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java
index be6588e3189..4e9c63699ca 100644
--- a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java
@@ -155,4 +155,7 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
     VolumeVO findByPoolIdAndPath(long id, String path);
 
     List<VolumeVO> listByIds(List<Long> ids);
+
+    List<VolumeVO> listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List<Long> diskOfferingIds, List<Long> vmIds);
+
 }
diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java
index 41c32883d2e..a60e8f04845 100644
--- a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java
@@ -839,4 +839,28 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
         sc.setParameters("idIN", ids.toArray());
         return listBy(sc, null);
     }
+
+    @Override
+    public List<VolumeVO> listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List<Long> diskOfferingIds, List<Long> vmIds) {
+        SearchBuilder<VolumeVO> sb = createSearchBuilder();
+        sb.and("account", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
+        sb.and("state", sb.entity().getState(), SearchCriteria.Op.NIN);
+        sb.and("diskOfferingIds", sb.entity().getDiskOfferingId(), SearchCriteria.Op.IN);
+        sb.and("displayVolume", sb.entity().isDisplayVolume(), Op.EQ);
+        if (CollectionUtils.isNotEmpty(vmIds)) {
+            sb.and().op("instanceId", sb.entity().getInstanceId(), Op.NULL);
+            sb.or("notVmIds", sb.entity().getInstanceId(), Op.NIN);
+            sb.cp();
+        }
+        sb.done();
+        SearchCriteria<VolumeVO> sc = sb.create();
+        sc.setParameters("account", accountId);
+        sc.setParameters("state", Volume.State.Destroy, Volume.State.Expunged);
+        sc.setParameters("diskOfferingIds", diskOfferingIds.toArray());
+        sc.setParameters("displayVolume", 1);
+        if (CollectionUtils.isNotEmpty(vmIds)) {
+            sc.setParameters("notVmIds", vmIds.toArray());
+        }
+        return listBy(sc);
+    }
 }
diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java
index e5636f0bfc9..9ebdfb8042b 100644
--- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java
+++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java
@@ -18,10 +18,6 @@
 //
 package org.apache.cloudstack.reservation;
 
-import com.cloud.configuration.Resource;
-import org.apache.cloudstack.user.ResourceReservation;
-import com.cloud.utils.exception.CloudRuntimeException;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
@@ -29,6 +25,11 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
+import org.apache.cloudstack.user.ResourceReservation;
+
+import com.cloud.configuration.Resource;
+import com.cloud.utils.exception.CloudRuntimeException;
+
 @Entity
 @Table(name = "resource_reservation")
 public class ReservationVO implements ResourceReservation {
@@ -47,22 +48,30 @@ public class ReservationVO implements ResourceReservation {
     @Column(name = "resource_type", nullable = false)
     Resource.ResourceType resourceType;
 
+    @Column(name = "tag")
+    String tag;
+
     @Column(name = "amount")
     long amount;
 
-    protected ReservationVO()
-    {}
+    protected ReservationVO() {
+    }
 
-    public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, Long delta) {
+    public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, String tag, Long delta) {
         if (delta == null || delta <= 0) {
             throw new CloudRuntimeException("resource reservations can not be made for no resources");
         }
         this.accountId = accountId;
         this.domainId = domainId;
         this.resourceType = resourceType;
+        this.tag = tag;
         this.amount = delta;
     }
 
+    public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, Long delta) {
+        this(accountId, domainId, resourceType, null, delta);
+    }
+
     @Override
     public long getId() {
         return this.id;
@@ -83,6 +92,11 @@ public class ReservationVO implements ResourceReservation {
         return resourceType;
     }
 
+    @Override
+    public String getTag() {
+        return tag;
+    }
+
     @Override
     public Long getReservedAmount() {
         return amount;
diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java
index eead91c7b8e..478a9087c44 100644
--- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java
+++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java
@@ -18,11 +18,12 @@
 //
 package org.apache.cloudstack.reservation.dao;
 
-import com.cloud.configuration.Resource;
 import org.apache.cloudstack.reservation.ReservationVO;
+
+import com.cloud.configuration.Resource;
 import com.cloud.utils.db.GenericDao;
 
 public interface ReservationDao extends GenericDao<ReservationVO, Long> {
-    long getAccountReservation(Long account, Resource.ResourceType resourceType);
-    long getDomainReservation(Long domain, Resource.ResourceType resourceType);
+    long getAccountReservation(Long account, Resource.ResourceType resourceType, String tag);
+    long getDomainReservation(Long domain, Resource.ResourceType resourceType, String tag);
 }
diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java
index 6703de0b13c..5239aa50ad0 100644
--- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java
+++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java
@@ -18,41 +18,63 @@
 //
 package org.apache.cloudstack.reservation.dao;
 
+import java.util.List;
+
+import org.apache.cloudstack.reservation.ReservationVO;
+
 import com.cloud.configuration.Resource;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
-import org.apache.cloudstack.reservation.ReservationVO;
-
-import java.util.List;
 
 public class ReservationDaoImpl extends GenericDaoBase<ReservationVO, Long> implements ReservationDao {
 
     private static final String RESOURCE_TYPE = "resourceType";
+    private static final String RESOURCE_TAG = "resourceTag";
     private static final String ACCOUNT_ID = "accountId";
     private static final String DOMAIN_ID = "domainId";
     private final SearchBuilder<ReservationVO> listAccountAndTypeSearch;
+    private final SearchBuilder<ReservationVO> listAccountAndTypeAndNoTagSearch;
 
     private final SearchBuilder<ReservationVO> listDomainAndTypeSearch;
+    private final SearchBuilder<ReservationVO> listDomainAndTypeAndNoTagSearch;
 
     public ReservationDaoImpl() {
         listAccountAndTypeSearch = createSearchBuilder();
         listAccountAndTypeSearch.and(ACCOUNT_ID, listAccountAndTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         listAccountAndTypeSearch.and(RESOURCE_TYPE, listAccountAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+        listAccountAndTypeSearch.and(RESOURCE_TAG, listAccountAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ);
         listAccountAndTypeSearch.done();
 
+        listAccountAndTypeAndNoTagSearch = createSearchBuilder();
+        listAccountAndTypeAndNoTagSearch.and(ACCOUNT_ID, listAccountAndTypeAndNoTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        listAccountAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listAccountAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+        listAccountAndTypeAndNoTagSearch.and(RESOURCE_TAG, listAccountAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL);
+        listAccountAndTypeAndNoTagSearch.done();
+
         listDomainAndTypeSearch = createSearchBuilder();
         listDomainAndTypeSearch.and(DOMAIN_ID, listDomainAndTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
         listDomainAndTypeSearch.and(RESOURCE_TYPE, listDomainAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+        listDomainAndTypeSearch.and(RESOURCE_TAG, listDomainAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ);
         listDomainAndTypeSearch.done();
+
+        listDomainAndTypeAndNoTagSearch = createSearchBuilder();
+        listDomainAndTypeAndNoTagSearch.and(ACCOUNT_ID, listDomainAndTypeAndNoTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+        listDomainAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listDomainAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+        listDomainAndTypeAndNoTagSearch.and(RESOURCE_TAG, listDomainAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL);
+        listDomainAndTypeAndNoTagSearch.done();
     }
 
     @Override
-    public long getAccountReservation(Long accountId, Resource.ResourceType resourceType) {
+    public long getAccountReservation(Long accountId, Resource.ResourceType resourceType, String tag) {
         long total = 0;
-        SearchCriteria<ReservationVO> sc = listAccountAndTypeSearch.create();
+        SearchCriteria<ReservationVO> sc = tag == null ?
+                listAccountAndTypeAndNoTagSearch.create() : listAccountAndTypeSearch.create();
         sc.setParameters(ACCOUNT_ID, accountId);
         sc.setParameters(RESOURCE_TYPE, resourceType);
+        if (tag != null) {
+            sc.setParameters(RESOURCE_TAG, tag);
+        }
         List<ReservationVO> reservations = listBy(sc);
         for (ReservationVO reservation : reservations) {
             total += reservation.getReservedAmount();
@@ -61,11 +83,15 @@ public class ReservationDaoImpl extends GenericDaoBase<ReservationVO, Long> impl
     }
 
     @Override
-    public long getDomainReservation(Long domainId, Resource.ResourceType resourceType) {
+    public long getDomainReservation(Long domainId, Resource.ResourceType resourceType, String tag) {
         long total = 0;
-        SearchCriteria<ReservationVO> sc = listDomainAndTypeSearch.create();
+        SearchCriteria<ReservationVO> sc = tag == null ?
+                listDomainAndTypeAndNoTagSearch.create() : listDomainAndTypeSearch.create();
         sc.setParameters(DOMAIN_ID, domainId);
         sc.setParameters(RESOURCE_TYPE, resourceType);
+        if (tag != null) {
+            sc.setParameters(RESOURCE_TAG, tag);
+        }
         List<ReservationVO> reservations = listBy(sc);
         for (ReservationVO reservation : reservations) {
             total += reservation.getReservedAmount();
diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql b/engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql
index 1c368a2fbee..33b819e4072 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql
@@ -18,3 +18,13 @@
 --;
 -- Schema upgrade from 4.19.0.0 to 4.20.0.0
 --;
+
+-- Add tag column to tables
+CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_limit', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the limit" ');
+CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_count', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the resource count" ');
+CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_reservation', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the resource reservation" ');
+ALTER TABLE `resource_count`
+DROP INDEX `i_resource_count__type_accountId`,
+DROP INDEX `i_resource_count__type_domaintId`,
+ADD UNIQUE INDEX `i_resource_count__type_tag_accountId` (`type`,`tag`,`account_id`),
+ADD UNIQUE INDEX `i_resource_count__type_tag_domaintId` (`type`,`tag`,`domain_id`);
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql
new file mode 100644
index 00000000000..87546a9d118
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql
@@ -0,0 +1,164 @@
+-- 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.
+
+-- VIEW `cloud`.`account_view`;
+
+DROP VIEW IF EXISTS `cloud`.`account_view`;
+CREATE VIEW `cloud`.`account_view` AS
+select
+    `account`.`id` AS `id`,
+    `account`.`uuid` AS `uuid`,
+    `account`.`account_name` AS `account_name`,
+    `account`.`type` AS `type`,
+    `account`.`role_id` AS `role_id`,
+    `account`.`state` AS `state`,
+    `account`.`created` AS `created`,
+    `account`.`removed` AS `removed`,
+    `account`.`cleanup_needed` AS `cleanup_needed`,
+    `account`.`network_domain` AS `network_domain` ,
+    `account`.`default` AS `default`,
+    `domain`.`id` AS `domain_id`,
+    `domain`.`uuid` AS `domain_uuid`,
+    `domain`.`name` AS `domain_name`,
+    `domain`.`path` AS `domain_path`,
+    `data_center`.`id` AS `data_center_id`,
+    `data_center`.`uuid` AS `data_center_uuid`,
+    `data_center`.`name` AS `data_center_name`,
+    `account_netstats_view`.`bytesReceived` AS `bytesReceived`,
+    `account_netstats_view`.`bytesSent` AS `bytesSent`,
+    `vmlimit`.`max` AS `vmLimit`,
+    `vmcount`.`count` AS `vmTotal`,
+    `runningvm`.`vmcount` AS `runningVms`,
+    `stoppedvm`.`vmcount` AS `stoppedVms`,
+    `iplimit`.`max` AS `ipLimit`,
+    `ipcount`.`count` AS `ipTotal`,
+    `free_ip_view`.`free_ip` AS `ipFree`,
+    `volumelimit`.`max` AS `volumeLimit`,
+    `volumecount`.`count` AS `volumeTotal`,
+    `snapshotlimit`.`max` AS `snapshotLimit`,
+    `snapshotcount`.`count` AS `snapshotTotal`,
+    `templatelimit`.`max` AS `templateLimit`,
+    `templatecount`.`count` AS `templateTotal`,
+    `vpclimit`.`max` AS `vpcLimit`,
+    `vpccount`.`count` AS `vpcTotal`,
+    `projectlimit`.`max` AS `projectLimit`,
+    `projectcount`.`count` AS `projectTotal`,
+    `networklimit`.`max` AS `networkLimit`,
+    `networkcount`.`count` AS `networkTotal`,
+    `cpulimit`.`max` AS `cpuLimit`,
+    `cpucount`.`count` AS `cpuTotal`,
+    `memorylimit`.`max` AS `memoryLimit`,
+    `memorycount`.`count` AS `memoryTotal`,
+    `primary_storage_limit`.`max` AS `primaryStorageLimit`,
+    `primary_storage_count`.`count` AS `primaryStorageTotal`,
+    `secondary_storage_limit`.`max` AS `secondaryStorageLimit`,
+    `secondary_storage_count`.`count` AS `secondaryStorageTotal`,
+    `async_job`.`id` AS `job_id`,
+    `async_job`.`uuid` AS `job_uuid`,
+    `async_job`.`job_status` AS `job_status`,
+    `async_job`.`account_id` AS `job_account_id`
+from
+    `cloud`.`free_ip_view`,
+    `cloud`.`account`
+        inner join
+    `cloud`.`domain` ON account.domain_id = domain.id
+        left join
+    `cloud`.`data_center` ON account.default_zone_id = data_center.id
+        left join
+    `cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id
+        left join
+    `cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id
+        and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` vmcount ON account.id = vmcount.account_id
+        and vmcount.type = 'user_vm' and vmcount.tag IS NULL
+        left join
+    `cloud`.`account_vmstats_view` runningvm ON account.id = runningvm.account_id
+        and runningvm.state = 'Running'
+        left join
+    `cloud`.`account_vmstats_view` stoppedvm ON account.id = stoppedvm.account_id
+        and stoppedvm.state = 'Stopped'
+        left join
+    `cloud`.`resource_limit` iplimit ON account.id = iplimit.account_id
+        and iplimit.type = 'public_ip'
+        left join
+    `cloud`.`resource_count` ipcount ON account.id = ipcount.account_id
+        and ipcount.type = 'public_ip'
+        left join
+    `cloud`.`resource_limit` volumelimit ON account.id = volumelimit.account_id
+        and volumelimit.type = 'volume' and volumelimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` volumecount ON account.id = volumecount.account_id
+        and volumecount.type = 'volume' and volumecount.tag IS NULL
+        left join
+    `cloud`.`resource_limit` snapshotlimit ON account.id = snapshotlimit.account_id
+        and snapshotlimit.type = 'snapshot'
+        left join
+    `cloud`.`resource_count` snapshotcount ON account.id = snapshotcount.account_id
+        and snapshotcount.type = 'snapshot'
+        left join
+    `cloud`.`resource_limit` templatelimit ON account.id = templatelimit.account_id
+        and templatelimit.type = 'template'
+        left join
+    `cloud`.`resource_count` templatecount ON account.id = templatecount.account_id
+        and templatecount.type = 'template'
+        left join
+    `cloud`.`resource_limit` vpclimit ON account.id = vpclimit.account_id
+        and vpclimit.type = 'vpc'
+        left join
+    `cloud`.`resource_count` vpccount ON account.id = vpccount.account_id
+        and vpccount.type = 'vpc'
+        left join
+    `cloud`.`resource_limit` projectlimit ON account.id = projectlimit.account_id
+        and projectlimit.type = 'project'
+        left join
+    `cloud`.`resource_count` projectcount ON account.id = projectcount.account_id
+        and projectcount.type = 'project'
+        left join
+    `cloud`.`resource_limit` networklimit ON account.id = networklimit.account_id
+        and networklimit.type = 'network'
+        left join
+    `cloud`.`resource_count` networkcount ON account.id = networkcount.account_id
+        and networkcount.type = 'network'
+        left join
+    `cloud`.`resource_limit` cpulimit ON account.id = cpulimit.account_id
+        and cpulimit.type = 'cpu' and cpulimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` cpucount ON account.id = cpucount.account_id
+        and cpucount.type = 'cpu' and cpucount.tag IS NULL
+        left join
+    `cloud`.`resource_limit` memorylimit ON account.id = memorylimit.account_id
+        and memorylimit.type = 'memory' and memorylimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` memorycount ON account.id = memorycount.account_id
+        and memorycount.type = 'memory' and memorycount.tag IS NULL
+        left join
+    `cloud`.`resource_limit` primary_storage_limit ON account.id = primary_storage_limit.account_id
+        and primary_storage_limit.type = 'primary_storage' and primary_storage_limit.tag IS NULL
+        left join
+    `cloud`.`resource_count` primary_storage_count ON account.id = primary_storage_count.account_id
+        and primary_storage_count.type = 'primary_storage' and primary_storage_count.tag IS NULL
+        left join
+    `cloud`.`resource_limit` secondary_storage_limit ON account.id = secondary_storage_limit.account_id
+        and secondary_storage_limit.type = 'secondary_storage'
+        left join
+    `cloud`.`resource_count` secondary_storage_count ON account.id = secondary_storage_count.account_id
+        and secondary_storage_count.type = 'secondary_storage'
+        left join
+    `cloud`.`async_job` ON async_job.instance_id = account.id
+        and async_job.instance_type = 'Account'
+        and async_job.job_status = 0;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql
new file mode 100644
index 00000000000..af885b9413f
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql
@@ -0,0 +1,134 @@
+-- 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.
+
+-- VIEW `cloud`.`domain_view`;
+
+DROP VIEW IF EXISTS `cloud`.`domain_view`;
+CREATE VIEW `cloud`.`domain_view` AS
+select
+    `domain`.`id` AS `id`,
+    `domain`.`parent` AS `parent`,
+    `domain`.`name` AS `name`,
+    `domain`.`uuid` AS `uuid`,
+    `domain`.`owner` AS `owner`,
+    `domain`.`path` AS `path`,
+    `domain`.`level` AS `level`,
+    `domain`.`child_count` AS `child_count`,
+    `domain`.`next_child_seq` AS `next_child_seq`,
+    `domain`.`created` AS `created`,
+    `domain`.`removed` AS `removed`,
+    `domain`.`state` AS `state`,
+    `domain`.`network_domain` AS `network_domain`,
+    `domain`.`type` AS `type`,
+    `vmlimit`.`max` AS `vmLimit`,
+    `vmcount`.`count` AS `vmTotal`,
+    `iplimit`.`max` AS `ipLimit`,
+    `ipcount`.`count` AS `ipTotal`,
+    `volumelimit`.`max` AS `volumeLimit`,
+    `volumecount`.`count` AS `volumeTotal`,
+    `snapshotlimit`.`max` AS `snapshotLimit`,
+    `snapshotcount`.`count` AS `snapshotTotal`,
+    `templatelimit`.`max` AS `templateLimit`,
+    `templatecount`.`count` AS `templateTotal`,
+    `vpclimit`.`max` AS `vpcLimit`,
+    `vpccount`.`count` AS `vpcTotal`,
+    `projectlimit`.`max` AS `projectLimit`,
+    `projectcount`.`count` AS `projectTotal`,
+    `networklimit`.`max` AS `networkLimit`,
+    `networkcount`.`count` AS `networkTotal`,
+    `cpulimit`.`max` AS `cpuLimit`,
+    `cpucount`.`count` AS `cpuTotal`,
+    `memorylimit`.`max` AS `memoryLimit`,
+    `memorycount`.`count` AS `memoryTotal`,
+    `primary_storage_limit`.`max` AS `primaryStorageLimit`,
+    `primary_storage_count`.`count` AS `primaryStorageTotal`,
+    `secondary_storage_limit`.`max` AS `secondaryStorageLimit`,
+    `secondary_storage_count`.`count` AS `secondaryStorageTotal`
+from
+    `cloud`.`domain`
+        left join
+    `cloud`.`resource_limit` vmlimit ON domain.id = vmlimit.domain_id
+        and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` vmcount ON domain.id = vmcount.domain_id
+        and vmcount.type = 'user_vm' and vmcount.tag IS NULL
+        left join
+    `cloud`.`resource_limit` iplimit ON domain.id = iplimit.domain_id
+        and iplimit.type = 'public_ip'
+        left join
+    `cloud`.`resource_count` ipcount ON domain.id = ipcount.domain_id
+        and ipcount.type = 'public_ip'
+        left join
+    `cloud`.`resource_limit` volumelimit ON domain.id = volumelimit.domain_id
+        and volumelimit.type = 'volume' and volumelimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` volumecount ON domain.id = volumecount.domain_id
+        and volumecount.type = 'volume' and volumecount.tag IS NULL
+        left join
+    `cloud`.`resource_limit` snapshotlimit ON domain.id = snapshotlimit.domain_id
+        and snapshotlimit.type = 'snapshot'
+        left join
+    `cloud`.`resource_count` snapshotcount ON domain.id = snapshotcount.domain_id
+        and snapshotcount.type = 'snapshot'
+        left join
+    `cloud`.`resource_limit` templatelimit ON domain.id = templatelimit.domain_id
+        and templatelimit.type = 'template'
+        left join
+    `cloud`.`resource_count` templatecount ON domain.id = templatecount.domain_id
+        and templatecount.type = 'template'
+        left join
+    `cloud`.`resource_limit` vpclimit ON domain.id = vpclimit.domain_id
+        and vpclimit.type = 'vpc'
+        left join
+    `cloud`.`resource_count` vpccount ON domain.id = vpccount.domain_id
+        and vpccount.type = 'vpc'
+        left join
+    `cloud`.`resource_limit` projectlimit ON domain.id = projectlimit.domain_id
+        and projectlimit.type = 'project'
+        left join
+    `cloud`.`resource_count` projectcount ON domain.id = projectcount.domain_id
+        and projectcount.type = 'project'
+        left join
+    `cloud`.`resource_limit` networklimit ON domain.id = networklimit.domain_id
+        and networklimit.type = 'network'
+        left join
+    `cloud`.`resource_count` networkcount ON domain.id = networkcount.domain_id
+        and networkcount.type = 'network'
+        left join
+    `cloud`.`resource_limit` cpulimit ON domain.id = cpulimit.domain_id
+        and cpulimit.type = 'cpu' and cpulimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` cpucount ON domain.id = cpucount.domain_id
+        and cpucount.type = 'cpu' and cpucount.tag IS NULL
+        left join
+    `cloud`.`resource_limit` memorylimit ON domain.id = memorylimit.domain_id
+        and memorylimit.type = 'memory' and memorylimit.tag IS NULL
+        left join
+    `cloud`.`resource_count` memorycount ON domain.id = memorycount.domain_id
+        and memorycount.type = 'memory' and memorycount.tag IS NULL
+        left join
+    `cloud`.`resource_limit` primary_storage_limit ON domain.id = primary_storage_limit.domain_id
+        and primary_storage_limit.type = 'primary_storage' and primary_storage_limit.tag IS NULL
+        left join
+    `cloud`.`resource_count` primary_storage_count ON domain.id = primary_storage_count.domain_id
+        and primary_storage_count.type = 'primary_storage' and primary_storage_count.tag IS NULL
+        left join
+    `cloud`.`resource_limit` secondary_storage_limit ON domain.id = secondary_storage_limit.domain_id
+        and secondary_storage_limit.type = 'secondary_storage'
+        left join
+    `cloud`.`resource_count` secondary_storage_count ON domain.id = secondary_storage_count.domain_id
+        and secondary_storage_count.type = 'secondary_storage';
diff --git a/engine/schema/src/test/java/com/cloud/host/HostVOTest.java b/engine/schema/src/test/java/com/cloud/host/HostVOTest.java
index 76bc5270b4f..cd9ac3cc172 100755
--- a/engine/schema/src/test/java/com/cloud/host/HostVOTest.java
+++ b/engine/schema/src/test/java/com/cloud/host/HostVOTest.java
@@ -1,84 +1,126 @@
-// 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.host;
-
-import com.cloud.service.ServiceOfferingVO;
-import com.cloud.vm.VirtualMachine;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-import org.junit.Before;
-
-public class HostVOTest {
-    HostVO host;
-    ServiceOfferingVO offering;
-
-    @Before
-    public void setUp() throws Exception {
-        host = new HostVO();
-        offering = new ServiceOfferingVO("TestSO", 0, 0, 0, 0, 0,
-                false, "TestSO", false,VirtualMachine.Type.User,false);
-    }
-
-    @Test
-    public void testNoSO() {
-        assertFalse(host.checkHostServiceOfferingTags(null));
-    }
-
-    @Test
-    public void testNoTag() {
-        assertTrue(host.checkHostServiceOfferingTags(offering));
-    }
-
-    @Test
-    public void testRightTag() {
-        host.setHostTags(Arrays.asList("tag1","tag2"), false);
-        offering.setHostTag("tag2,tag1");
-        assertTrue(host.checkHostServiceOfferingTags(offering));
-    }
-
-    @Test
-    public void testWrongTag() {
-        host.setHostTags(Arrays.asList("tag1","tag2"), false);
-        offering.setHostTag("tag2,tag4");
-        assertFalse(host.checkHostServiceOfferingTags(offering));
-    }
-
-    @Test
-    public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatMatches() {
-        host.setHostTags(List.of("tags[0] == 'A'"), true);
-        offering.setHostTag("A");
-        assertTrue(host.checkHostServiceOfferingTags(offering));
-    }
-
-    @Test
-    public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatDoesNotMatch() {
-        host.setHostTags(List.of("tags[0] == 'A'"), true);
-        offering.setHostTag("B");
-        assertFalse(host.checkHostServiceOfferingTags(offering));
-    }
-
-    @Test
-    public void checkHostServiceOfferingTagsTestRuleTagWithNullServiceTag() {
-        host.setHostTags(List.of("tags[0] == 'A'"), true);
-        offering.setHostTag(null);
-        assertFalse(host.checkHostServiceOfferingTags(offering));
-    }
-}
+// 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.host;
+
+import com.cloud.offering.ServiceOffering;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.vm.VirtualMachine;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+public class HostVOTest {
+    HostVO host;
+    ServiceOfferingVO offering;
+
+    @Before
+    public void setUp() throws Exception {
+        host = new HostVO();
+        offering = new ServiceOfferingVO("TestSO", 0, 0, 0, 0, 0,
+                false, "TestSO", false,VirtualMachine.Type.User,false);
+    }
+
+    @Test
+    public void testNoSO() {
+        assertFalse(host.checkHostServiceOfferingTags(null));
+    }
+
+    @Test
+    public void testNoTag() {
+        assertTrue(host.checkHostServiceOfferingTags(offering));
+    }
+
+    @Test
+    public void testRightTag() {
+        host.setHostTags(Arrays.asList("tag1","tag2"), false);
+        offering.setHostTag("tag2,tag1");
+        assertTrue(host.checkHostServiceOfferingTags(offering));
+    }
+
+    @Test
+    public void testWrongTag() {
+        host.setHostTags(Arrays.asList("tag1","tag2"), false);
+        offering.setHostTag("tag2,tag4");
+        assertFalse(host.checkHostServiceOfferingTags(offering));
+    }
+
+    @Test
+    public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatMatches() {
+        host.setHostTags(List.of("tags[0] == 'A'"), true);
+        offering.setHostTag("A");
+        assertTrue(host.checkHostServiceOfferingTags(offering));
+    }
+
+    @Test
+    public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatDoesNotMatch() {
+        host.setHostTags(List.of("tags[0] == 'A'"), true);
+        offering.setHostTag("B");
+        assertFalse(host.checkHostServiceOfferingTags(offering));
+    }
+
+    @Test
+    public void checkHostServiceOfferingTagsTestRuleTagWithNullServiceTag() {
+        host.setHostTags(List.of("tags[0] == 'A'"), true);
+        offering.setHostTag(null);
+        assertFalse(host.checkHostServiceOfferingTags(offering));
+    }
+
+    @Test
+    public void testEitherNoSOOrTemplate() {
+        assertFalse(host.checkHostServiceOfferingAndTemplateTags(null, Mockito.mock(VirtualMachineTemplate.class)));
+        assertFalse(host.checkHostServiceOfferingAndTemplateTags(Mockito.mock(ServiceOffering.class), null));
+    }
+
+    @Test
+    public void testNoTagOfferingTemplate() {
+        assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, Mockito.mock(VirtualMachineTemplate.class)));
+    }
+
+    @Test
+    public void testRightTagOfferingTemplate() {
+        host.setHostTags(Arrays.asList("tag1", "tag2"), false);
+        offering.setHostTag("tag2,tag1");
+        assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, Mockito.mock(VirtualMachineTemplate.class)));
+        host.setHostTags(Arrays.asList("tag1", "tag2", "tag3"), false);
+        offering.setHostTag("tag2,tag1");
+        VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
+        Mockito.when(template.getTemplateTag()).thenReturn("tag3");
+        assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, template));
+        host.setHostTags(List.of("tag3"), false);
+        offering.setHostTag(null);
+        assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, template));
+    }
+
+    @Test
+    public void testWrongOfferingTag() {
+        host.setHostTags(Arrays.asList("tag1","tag2"), false);
+        offering.setHostTag("tag2,tag4");
+        VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
+        Mockito.when(template.getTemplateTag()).thenReturn("tag1");
+        assertFalse(host.checkHostServiceOfferingAndTemplateTags(offering, template));
+        offering.setHostTag("tag1,tag2");
+        template = Mockito.mock(VirtualMachineTemplate.class);
+        Mockito.when(template.getTemplateTag()).thenReturn("tag3");
+        assertFalse(host.checkHostServiceOfferingAndTemplateTags(offering, template));
+    }
+}
diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java
index 98f6d6d8ecc..63524ccb6db 100644
--- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java
+++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java
@@ -308,10 +308,14 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
             return false;
         }
 
-        Volume volume = volumeDao.findById(dskCh.getVolumeId());
-        if(!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) {
-            logger.debug(String.format("Pool [%s] is not compatible with volume [%s], skipping it.", pool, volume));
-            return false;
+        Volume volume = null;
+        boolean isTempVolume = dskCh.getVolumeId() == Volume.DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID;
+        if (!isTempVolume) {
+            volume = volumeDao.findById(dskCh.getVolumeId());
+            if (!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) {
+                logger.debug(String.format("Pool [%s] is not compatible with volume [%s], skipping it.", pool, volume));
+                return false;
+            }
         }
 
         if (pool.isManaged() && !storageUtil.managedStoragePoolCanScale(pool, plan.getClusterId(), plan.getHostId())) {
@@ -336,8 +340,10 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
             }
 
             try {
-                boolean isStoragePoolStoragepolicyComplaince = storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool);
-                if (!isStoragePoolStoragepolicyComplaince) {
+                boolean isStoragePoolStoragePolicyCompliance = isTempVolume ?
+                        storageMgr.isStoragePoolCompliantWithStoragePolicy(dskCh.getDiskOfferingId(), pool) :
+                        storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool);
+                if (!isStoragePoolStoragePolicyCompliance) {
                     logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not compliant with the storage policy required by the volume.", pool, volume));
                     return false;
                 }
@@ -346,7 +352,11 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement
                 return false;
             }
         }
-        return storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) && storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId());
+        return isTempVolume ?
+                (storageMgr.storagePoolHasEnoughIops(dskCh.getMinIops(), pool) &&
+                        storageMgr.storagePoolHasEnoughSpace(dskCh.getSize(), pool)):
+                (storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) &&
+                        storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId()));
     }
 
     private boolean checkDiskProvisioningSupport(DiskProfile dskCh, StoragePool pool) {
diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index 2685f6d3e0c..6a630598766 100644
--- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -126,6 +126,7 @@ import com.cloud.storage.Volume;
 import com.cloud.storage.Volume.State;
 import com.cloud.storage.VolumeDetailVO;
 import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VMTemplatePoolDao;
 import com.cloud.storage.dao.VolumeDao;
@@ -206,6 +207,8 @@ public class VolumeServiceImpl implements VolumeService {
     private SnapshotApiService snapshotApiService;
     @Inject
     private PassphraseDao passphraseDao;
+    @Inject
+    private DiskOfferingDao diskOfferingDao;
 
     public VolumeServiceImpl() {
     }
@@ -1610,8 +1613,7 @@ public class VolumeServiceImpl implements VolumeService {
 
         if (vol.getAttachedVM() == null || vol.getAttachedVM().getType() == VirtualMachine.Type.User) {
             // Decrement the resource count for volumes and primary storage belonging user VM's only
-            _resourceLimitMgr.decrementResourceCount(vol.getAccountId(), ResourceType.volume, vol.isDisplay());
-            _resourceLimitMgr.decrementResourceCount(vol.getAccountId(), ResourceType.primary_storage, vol.isDisplay(), new Long(vol.getSize()));
+            _resourceLimitMgr.decrementVolumeResourceCount(vol.getAccountId(), vol.isDisplay(), vol.getSize(), diskOfferingDao.findById(vol.getDiskOfferingId()));
         }
     }
 
diff --git a/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
index ffdbfcbc5c3..f15f3f20001 100644
--- a/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
+++ b/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
@@ -22,9 +22,10 @@ import java.util.List;
 
 import javax.inject.Inject;
 
-import com.cloud.utils.exception.CloudRuntimeException;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.ListUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
 import com.cloud.agent.manager.allocator.HostAllocator;
@@ -39,8 +40,10 @@ import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.offering.ServiceOffering;
 import com.cloud.resource.ResourceManager;
+import com.cloud.storage.VMTemplateVO;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 
@@ -57,6 +60,27 @@ public class RandomAllocator extends AdapterBase implements HostAllocator {
     @Inject
     private CapacityManager capacityManager;
 
+    protected List<HostVO> listHostsByTags(Host.Type type, long dcId, Long podId, Long clusterId, String offeringHostTag, String templateTag) {
+        List<HostVO> taggedHosts = new ArrayList<>();
+        if (offeringHostTag != null) {
+            taggedHosts.addAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, offeringHostTag));
+        }
+        if (templateTag != null) {
+            List<HostVO> templateTaggedHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, templateTag);
+            if (taggedHosts.isEmpty()) {
+                taggedHosts = templateTaggedHosts;
+            } else {
+                taggedHosts.retainAll(templateTaggedHosts);
+            }
+        }
+        if (logger.isDebugEnabled()) {
+            logger.debug(String.format("Found %d hosts %s with type: %s, zone ID: %d, pod ID: %d, cluster ID: %s, offering host tag(s): %s, template tag: %s",
+                    taggedHosts.size(),
+                    (taggedHosts.isEmpty() ? "" : String.format("(%s)", StringUtils.join(taggedHosts.stream().map(HostVO::getId).toArray(), ","))),
+                    type.name(), dcId, podId, clusterId, offeringHostTag, templateTag));
+        }
+        return taggedHosts;
+    }
     private List<Host> findSuitableHosts(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type,
                                          ExcludeList avoid, List<? extends Host> hosts, int returnUpTo,
                                          boolean considerReservedCapacity) {
@@ -70,30 +94,34 @@ public class RandomAllocator extends AdapterBase implements HostAllocator {
         if (type == Host.Type.Storage) {
             return suitableHosts;
         }
-        String hostTag = offering.getHostTag();
-        if (hostTag != null) {
-            logger.debug(String.format("Looking for hosts in dc [%s], pod [%s], cluster [%s] and complying with host tag [%s].", dcId, podId, clusterId, hostTag));
+        String offeringHostTag = offering.getHostTag();
+        VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
+        String templateTag = template.getTemplateTag();
+        String hostTag = null;
+        if (ObjectUtils.anyNull(offeringHostTag, templateTag)) {
+            hostTag = offeringHostTag;
+            hostTag = hostTag == null ? templateTag : String.format("%s, %s", hostTag, templateTag);
+            logger.debug(String.format("Looking for hosts in dc [%s], pod [%s], cluster [%s] and complying with host tag(s): [%s]", dcId, podId, clusterId, hostTag));
         } else {
             logger.debug("Looking for hosts in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId);
         }
         if (hosts != null) {
             // retain all computing hosts, regardless of whether they support routing...it's random after all
             hostsCopy = new ArrayList<Host>(hosts);
-            if (hostTag != null) {
-                hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag));
+            if (ObjectUtils.anyNotNull(offeringHostTag, templateTag)) {
+                hostsCopy.retainAll(listHostsByTags(type, dcId, podId, clusterId, offeringHostTag, templateTag));
             } else {
                 hostsCopy.retainAll(_hostDao.listAllHostsThatHaveNoRuleTag(type, clusterId, podId, dcId));
             }
         } else {
             // list all computing hosts, regardless of whether they support routing...it's random after all
-            hostsCopy = new ArrayList<HostVO>();
-            if (hostTag != null) {
-                hostsCopy = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag);
+            if (offeringHostTag != null) {
+                hostsCopy = listHostsByTags(type, dcId, podId, clusterId, offeringHostTag, templateTag);
             } else {
                 hostsCopy = _hostDao.listAllHostsThatHaveNoRuleTag(type, clusterId, podId, dcId);
             }
         }
-        hostsCopy = ListUtils.union(hostsCopy, _hostDao.findHostsWithTagRuleThatMatchComputeOferringTags(hostTag));
+        hostsCopy = ListUtils.union(hostsCopy, _hostDao.findHostsWithTagRuleThatMatchComputeOferringTags(offeringHostTag));
 
         if (hostsCopy.isEmpty()) {
             logger.error(String.format("No suitable host found for vm [%s] with tags [%s].", vmProfile, hostTag));
diff --git a/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java b/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java
new file mode 100644
index 00000000000..538d7157184
--- /dev/null
+++ b/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java
@@ -0,0 +1,80 @@
+// 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.agent.manager.allocator.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import com.cloud.host.Host;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RandomAllocatorTest {
+
+    @Mock
+    HostDao hostDao;
+    @InjectMocks
+    RandomAllocator randomAllocator;
+
+    @Test
+    public void testListHostsByTags() {
+        Host.Type type = Host.Type.Routing;
+        Long id = 1L;
+        String templateTag = "tag1";
+        String offeringTag = "tag2";
+        HostVO host1 = Mockito.mock(HostVO.class);
+        HostVO host2 = Mockito.mock(HostVO.class);
+        Mockito.when(hostDao.listByHostTag(type, id, id, id, offeringTag)).thenReturn(List.of(host1, host2));
+
+        // No template tagged host
+        Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(new ArrayList<>());
+        List<HostVO> result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag);
+        Assert.assertTrue(CollectionUtils.isEmpty(result));
+
+        // Different template tagged host
+        HostVO host3 = Mockito.mock(HostVO.class);
+        Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(List.of(host3));
+        result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag);
+        Assert.assertTrue(CollectionUtils.isEmpty(result));
+
+        // Matching template tagged host
+        Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(List.of(host1));
+        result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag);
+        Assert.assertFalse(CollectionUtils.isEmpty(result));
+        Assert.assertEquals(1, result.size());
+
+        // No template tag
+        result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, null);
+        Assert.assertFalse(CollectionUtils.isEmpty(result));
+        Assert.assertEquals(2, result.size());
+
+        // No offering tag
+        result = randomAllocator.listHostsByTags(type, id, id, id, null, templateTag);
+        Assert.assertFalse(CollectionUtils.isEmpty(result));
+        Assert.assertEquals(1, result.size());
+    }
+}
diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java
index 70066dcf7dd..a05d7d7ff8d 100644
--- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java
+++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java
@@ -50,6 +50,7 @@ import com.cloud.agent.api.storage.ListTemplateCommand;
 import com.cloud.agent.api.storage.ListVolumeCommand;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.ResizeVolumeCommand;
 import com.cloud.utils.component.Manager;
 
 public interface MockStorageManager extends Manager {
@@ -113,4 +114,6 @@ public interface MockStorageManager extends Manager {
     public UploadStatusAnswer getUploadStatus(UploadStatusCommand cmd);
 
     Answer handleConfigDriveIso(HandleConfigDriveIsoCommand cmd);
+
+    Answer handleResizeVolume(ResizeVolumeCommand cmd);
 }
diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java
index f313968c15f..461347f47cd 100644
--- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java
@@ -78,6 +78,8 @@ import com.cloud.agent.api.storage.ListVolumeAnswer;
 import com.cloud.agent.api.storage.ListVolumeCommand;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.ResizeVolumeAnswer;
+import com.cloud.agent.api.storage.ResizeVolumeCommand;
 import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.NfsTO;
 import com.cloud.agent.api.to.StorageFilerTO;
@@ -1307,4 +1309,32 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
 
         return new Answer(cmd);
     }
+
+    @Override
+    public Answer handleResizeVolume(ResizeVolumeCommand cmd) {
+        Long currentSize = cmd.getCurrentSize();
+        Long newSize = cmd.getNewSize();
+        MockStoragePoolVO storagePool = null;
+        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
+        try {
+            txn.start();
+            storagePool = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
+            txn.commit();
+            if (storagePool == null) {
+                return new ResizeVolumeAnswer(cmd, false, "Failed to find storage pool: " + cmd.getPoolUuid());
+            }
+        } catch (Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("Error when finding storage " + cmd.getPoolUuid(), ex);
+        } finally {
+            txn.close();
+            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
+            txn.close();
+        }
+
+        if (newSize >= currentSize) {
+            return new ResizeVolumeAnswer(cmd, true, "", newSize);
+        }
+        return new ResizeVolumeAnswer(cmd, false, "Failed to resize");
+    }
 }
diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java
index cd1eeee7708..cb8d71985e3 100644
--- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -114,6 +114,7 @@ import com.cloud.agent.api.storage.DestroyCommand;
 import com.cloud.agent.api.storage.ListTemplateCommand;
 import com.cloud.agent.api.storage.ListVolumeCommand;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.storage.ResizeVolumeCommand;
 import com.cloud.api.commands.CleanupSimulatorMockCmd;
 import com.cloud.api.commands.ConfigureSimulatorCmd;
 import com.cloud.api.commands.ConfigureSimulatorHAProviderState;
@@ -440,6 +441,8 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
                     answer = _mockVmMgr.fence((FenceCommand)cmd);
                 } else if (cmd instanceof HandleConfigDriveIsoCommand) {
                     answer = _mockStorageMgr.handleConfigDriveIso((HandleConfigDriveIsoCommand)cmd);
+                } else if (cmd instanceof ResizeVolumeCommand) {
+                    answer = _mockStorageMgr.handleResizeVolume((ResizeVolumeCommand)cmd);
                 } else if (cmd instanceof GetRouterAlertsCommand
                         || cmd instanceof VpnUsersCfgCommand
                         || cmd instanceof RemoteAccessVpnCfgCommand
diff --git a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
index e02bc110217..a84b1a6e2de 100644
--- a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
+++ b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
@@ -25,15 +25,9 @@ import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
-import com.cloud.configuration.dao.ResourceCountDao;
-import com.cloud.dc.DedicatedResourceVO;
-import com.cloud.dc.dao.DedicatedResourceDao;
-import com.cloud.host.HostStats;
-import com.cloud.host.HostTagVO;
-import com.cloud.user.Account;
-import com.cloud.user.dao.AccountDao;
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
+import org.apache.commons.lang3.StringUtils;
 
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiDBUtils;
@@ -43,16 +37,21 @@ import com.cloud.api.query.vo.DomainJoinVO;
 import com.cloud.api.query.vo.StoragePoolJoinVO;
 import com.cloud.capacity.Capacity;
 import com.cloud.capacity.CapacityManager;
-import com.cloud.capacity.CapacityVO;
 import com.cloud.capacity.CapacityState;
+import com.cloud.capacity.CapacityVO;
 import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.capacity.dao.CapacityDaoImpl;
 import com.cloud.configuration.Resource;
+import com.cloud.configuration.dao.ResourceCountDao;
 import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.DedicatedResourceVO;
 import com.cloud.dc.Vlan;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.DataCenterIpAddressDao;
+import com.cloud.dc.dao.DedicatedResourceDao;
 import com.cloud.host.Host;
+import com.cloud.host.HostStats;
+import com.cloud.host.HostTagVO;
 import com.cloud.host.HostVO;
 import com.cloud.host.Status;
 import com.cloud.host.dao.HostDao;
@@ -63,7 +62,8 @@ import com.cloud.storage.StorageStats;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.VolumeDao;
-import org.apache.commons.lang3.StringUtils;
+import com.cloud.user.Account;
+import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.Ternary;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
@@ -438,13 +438,13 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
             }
 
             long memoryUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain,
-                    Resource.ResourceType.memory);
+                    Resource.ResourceType.memory, null);
             long cpuUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain,
-                    Resource.ResourceType.cpu);
+                    Resource.ResourceType.cpu, null);
             long primaryStorageUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain,
-                    Resource.ResourceType.primary_storage);
+                    Resource.ResourceType.primary_storage, null);
             long secondaryStorageUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain,
-                    Resource.ResourceType.secondary_storage);
+                    Resource.ResourceType.secondary_storage, null);
 
             metricsList.add(new ItemPerDomainResourceCount(memoryUsed, domain.getPath(), Resource.ResourceType.memory.getName()));
             metricsList.add(new ItemPerDomainResourceCount(cpuUsed, domain.getPath(), Resource.ResourceType.cpu.getName()));
diff --git a/server/src/main/java/com/cloud/api/ApiDBUtils.java b/server/src/main/java/com/cloud/api/ApiDBUtils.java
index 3cade046c74..49cf787d0b1 100644
--- a/server/src/main/java/com/cloud/api/ApiDBUtils.java
+++ b/server/src/main/java/com/cloud/api/ApiDBUtils.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -53,6 +54,7 @@ import org.apache.cloudstack.api.response.HostTagResponse;
 import org.apache.cloudstack.api.response.ImageStoreResponse;
 import org.apache.cloudstack.api.response.InstanceGroupResponse;
 import org.apache.cloudstack.api.response.NetworkOfferingResponse;
+import org.apache.cloudstack.api.response.ObjectStoreResponse;
 import org.apache.cloudstack.api.response.ProjectAccountResponse;
 import org.apache.cloudstack.api.response.ProjectInvitationResponse;
 import org.apache.cloudstack.api.response.ProjectResponse;
@@ -85,6 +87,8 @@ import org.apache.cloudstack.framework.jobs.dao.AsyncJobDao;
 import org.apache.cloudstack.resourcedetail.SnapshotPolicyDetailVO;
 import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
 import org.apache.cloudstack.resourcedetail.dao.SnapshotPolicyDetailsDao;
+import org.apache.cloudstack.storage.datastore.db.ObjectStoreDao;
+import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 
@@ -337,6 +341,7 @@ import com.cloud.vm.UserVmManager;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VmDetailConstants;
 import com.cloud.vm.VmStats;
 import com.cloud.vm.dao.ConsoleProxyDao;
@@ -350,10 +355,6 @@ import com.cloud.vm.dao.VMInstanceDao;
 import com.cloud.vm.snapshot.VMSnapshot;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
 
-import org.apache.cloudstack.api.response.ObjectStoreResponse;
-import org.apache.cloudstack.storage.datastore.db.ObjectStoreDao;
-import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO;
-
 public class ApiDBUtils {
     private static ManagementServer s_ms;
     static AsyncJobManager s_asyncMgr;
@@ -489,6 +490,7 @@ public class ApiDBUtils {
     static ObjectStoreDao s_objectStoreDao;
 
     static BucketDao s_bucketDao;
+    static VirtualMachineManager s_virtualMachineManager;
 
     @Inject
     private ManagementServer ms;
@@ -752,6 +754,8 @@ public class ApiDBUtils {
     private ObjectStoreDao objectStoreDao;
     @Inject
     private BucketDao bucketDao;
+    @Inject
+    private VirtualMachineManager virtualMachineManager;
 
     @PostConstruct
     void init() {
@@ -886,6 +890,7 @@ public class ApiDBUtils {
         s_resourceManagerUtil = resourceManagerUtil;
         s_objectStoreDao = objectStoreDao;
         s_bucketDao = bucketDao;
+        s_virtualMachineManager = virtualMachineManager;
     }
 
     // ///////////////////////////////////////////////////////////
@@ -937,7 +942,7 @@ public class ApiDBUtils {
             return -1;
         }
 
-        return s_resourceLimitMgr.findCorrectResourceLimitForDomain(domain, type);
+        return s_resourceLimitMgr.findCorrectResourceLimitForDomain(domain, type, null);
     }
 
     public static long findCorrectResourceLimitForDomain(Long limit, boolean isRootDomain, ResourceType type, long domainId) {
@@ -954,16 +959,6 @@ public class ApiDBUtils {
         }
     }
 
-    public static long findCorrectResourceLimit(ResourceType type, long accountId) {
-        AccountVO account = s_accountDao.findById(accountId);
-
-        if (account == null) {
-            return -1;
-        }
-
-        return s_resourceLimitMgr.findCorrectResourceLimitForAccount(account, type);
-    }
-
     public static long findCorrectResourceLimit(Long limit, long accountId, ResourceType type) {
         return s_resourceLimitMgr.findCorrectResourceLimitForAccount(accountId, limit, type);
     }
@@ -984,7 +979,7 @@ public class ApiDBUtils {
             return -1;
         }
 
-        return s_resourceLimitMgr.getResourceCount(account, type);
+        return s_resourceLimitMgr.getResourceCount(account, type, null);
     }
 
     public static String getSecurityGroupsNamesForVm(long vmId) {
@@ -2098,6 +2093,22 @@ public class ApiDBUtils {
         return s_jobJoinDao.newAsyncJobView(e);
     }
 
+    public static List<DiskOfferingResponse> newDiskOfferingResponses(Long vmId, List<DiskOfferingJoinVO> offerings) {
+        List<DiskOfferingResponse> list = new ArrayList<>();
+        Map<Long, Boolean> suitability = null;
+        if (vmId != null) {
+            suitability = s_virtualMachineManager.getDiskOfferingSuitabilityForVm(vmId, offerings.stream().map(DiskOfferingJoinVO::getId).collect(Collectors.toList()));
+        }
+        for (DiskOfferingJoinVO offering : offerings) {
+            DiskOfferingResponse response = s_diskOfferingJoinDao.newDiskOfferingResponse(offering);
+            if (vmId != null) {
+                response.setSuitableForVm(suitability.get(offering.getId()));
+            }
+            list.add(response);
+        }
+        return list;
+    }
+
     public static DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering) {
         return s_diskOfferingJoinDao.newDiskOfferingResponse(offering);
     }
diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
index 2d2960af3f7..a0dc0d17c71 100644
--- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
@@ -559,6 +559,7 @@ public class ApiResponseHelper implements ResponseGenerator {
         } else {
             resourceLimitResponse.setMax(limit.getMax());
         }
+        resourceLimitResponse.setTag(limit.getTag());
         resourceLimitResponse.setObjectName("resourcelimit");
 
         return resourceLimitResponse;
@@ -580,7 +581,10 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         resourceCountResponse.setResourceType(resourceCount.getType());
         resourceCountResponse.setResourceCount(resourceCount.getCount());
-        resourceCountResponse.setObjectName("resourcecount");
+        resourceCountResponse.setObjectName(ApiConstants.RESOURCE_COUNT);
+        if (StringUtils.isNotEmpty(resourceCount.getTag())) {
+            resourceCountResponse.setTag(resourceCount.getTag());
+        }
         return resourceCountResponse;
     }
 
@@ -2007,6 +2011,21 @@ public class ApiResponseHelper implements ResponseGenerator {
         return ApiDBUtils.newEventResponse(vEvent);
     }
 
+    protected boolean capacityListingForSingleTag(List<? extends Capacity> capacities) {
+        String tag = capacities.get(0).getTag();
+        if (tag == null) {
+            return false;
+        }
+        List<? extends Capacity> taggedCapacities = capacities.stream().filter(x -> tag.equals(x.getTag())).collect(Collectors.toList());
+        return taggedCapacities.size() == capacities.size();
+    }
+
+    protected boolean capacityListingForSingleNonGpuType(List<? extends Capacity> capacities) {
+        short type = capacities.get(0).getCapacityType();
+        List<? extends Capacity> typeCapacities = capacities.stream().filter(x -> x.getCapacityType() == type).collect(Collectors.toList());
+        return typeCapacities.size() == capacities.size();
+    }
+
     @Override
     public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format) {
         List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
@@ -2052,13 +2071,18 @@ public class ApiResponseHelper implements ResponseGenerator {
             } else {
                 capacityResponse.setPercentUsed(format.format(0L));
             }
+            capacityResponse.setTag(summedCapacity.getTag());
 
             capacityResponse.setObjectName("capacity");
             capacityResponses.add(capacityResponse);
         }
 
         List<VgpuTypesInfo> gpuCapacities;
-        if (result.size() > 1 && (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
+        if (result.size() > 1 &&
+                !capacityListingForSingleTag(result) &&
+                !capacityListingForSingleNonGpuType(result) &&
+                (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(),
+                        result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
             HashMap<String, Long> vgpuVMs = ApiDBUtils.getVgpuVmsCount(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId());
 
             float capacityUsed = 0;
diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
index 8aa28849b4e..494723f5ff2 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -281,6 +281,7 @@ import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.Storage;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.TemplateType;
+import com.cloud.storage.StorageManager;
 import com.cloud.storage.StoragePoolStatus;
 import com.cloud.storage.StoragePoolTagVO;
 import com.cloud.storage.VMTemplateVO;
@@ -521,6 +522,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
 
     @Inject
     private ResourceIconDao resourceIconDao;
+    @Inject
+    StorageManager storageManager;
 
     @Inject
     private ManagementServerHostDao msHostDao;
@@ -3153,8 +3156,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
     @Override
     public ListResponse<DiskOfferingResponse> searchForDiskOfferings(ListDiskOfferingsCmd cmd) {
         Pair<List<DiskOfferingJoinVO>, Integer> result = searchForDiskOfferingsInternal(cmd);
-        ListResponse<DiskOfferingResponse> response = new ListResponse<DiskOfferingResponse>();
-        List<DiskOfferingResponse> offeringResponses = ViewResponseHelper.createDiskOfferingResponse(result.first().toArray(new DiskOfferingJoinVO[result.first().size()]));
+        ListResponse<DiskOfferingResponse> response = new ListResponse<>();
+        List<DiskOfferingResponse> offeringResponses = ViewResponseHelper.createDiskOfferingResponses(cmd.getVirtualMachineId(), result.first());
         response.setResponses(offeringResponses, result.second());
         return response;
     }
@@ -3189,6 +3192,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
         Long storagePoolId = cmd.getStoragePoolId();
         Boolean encrypt = cmd.getEncrypt();
         String storageType = cmd.getStorageType();
+        final Long vmId = cmd.getVirtualMachineId();
 
         // Keeping this logic consistent with domain specific zones
         // if a domainId is provided, we just return the disk offering
@@ -3296,6 +3300,16 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
             sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
         }
 
+        if (vmId != null) {
+            UserVmVO vm = userVmDao.findById(vmId);
+            if (vm == null) {
+                throw new InvalidParameterValueException("Unable to find the VM instance with the specified ID");
+            }
+            if (!isRootAdmin) {
+                accountMgr.checkAccess(account, null, false, vm);
+            }
+        }
+
         Pair<List<DiskOfferingJoinVO>, Integer> result = _diskOfferingJoinDao.searchAndCount(sc, searchFilter);
         String[] requiredTagsArray = new String[0];
         if (CollectionUtils.isNotEmpty(result.first()) && VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.valueIn(zoneId)) {
@@ -3354,6 +3368,24 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
         return response;
     }
 
+    protected List<String> getHostTagsFromTemplateForServiceOfferingsListing(Account caller, Long templateId) {
+        List<String> hostTags = new ArrayList<>();
+        if (templateId == null) {
+            return hostTags;
+        }
+        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(templateId);
+        if (template == null) {
+            throw new InvalidParameterValueException("Unable to find template with the specified ID");
+        }
+        if (caller.getType() != Account.Type.ADMIN) {
+            accountMgr.checkAccess(caller, null, false, template);
+        }
+        if (StringUtils.isNotEmpty(template.getTemplateTag())) {
+            hostTags.add(template.getTemplateTag());
+        }
+        return hostTags;
+    }
+
     private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInternal(ListServiceOfferingsCmd cmd) {
         // Note
         // The filteredOfferings method for offerings is being modified in accordance with
@@ -3385,6 +3417,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
         Integer cpuSpeed = cmd.getCpuSpeed();
         Boolean encryptRoot = cmd.getEncryptRoot();
         String storageType = cmd.getStorageType();
+        final Long templateId = cmd.getTemplateId();
 
         final Account owner = accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
         SearchCriteria<ServiceOfferingJoinVO> sc = _srvOfferingJoinDao.createSearchCriteria();
@@ -3579,6 +3612,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
             sc.addAnd("domainId", SearchCriteria.Op.SC, scc);
         }
 
+        List<String> hostTags = getHostTagsFromTemplateForServiceOfferingsListing(caller, templateId);
+
         if (currentVmOffering != null) {
             DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(currentVmOffering.getDiskOfferingId());
             List<String> storageTags = com.cloud.utils.StringUtils.csvTagsToList(diskOffering.getTags());
@@ -3596,25 +3631,28 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
                 sc.addAnd("storageTags", SearchCriteria.Op.SC, scc);
             }
 
-            List<String> hostTags = com.cloud.utils.StringUtils.csvTagsToList(currentVmOffering.getHostTag());
-            if (!hostTags.isEmpty()) {
-                SearchBuilder<ServiceOfferingJoinVO> hostTagsSearchBuilder = _srvOfferingJoinDao.createSearchBuilder();
-                for(String tag : hostTags) {
-                    hostTagsSearchBuilder.and(tag, hostTagsSearchBuilder.entity().getHostTag(), Op.FIND_IN_SET);
-                }
-                hostTagsSearchBuilder.done();
+            List<String> offeringHostTags = com.cloud.utils.StringUtils.csvTagsToList(currentVmOffering.getHostTag());
+            if (!offeringHostTags.isEmpty()) {
+                hostTags.addAll(offeringHostTags);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(hostTags)) {
+            SearchBuilder<ServiceOfferingJoinVO> hostTagsSearchBuilder = _srvOfferingJoinDao.createSearchBuilder();
+            for(String tag : hostTags) {
+                hostTagsSearchBuilder.and(tag, hostTagsSearchBuilder.entity().getHostTag(), Op.FIND_IN_SET);
+            }
+            hostTagsSearchBuilder.done();
 
-                SearchCriteria<ServiceOfferingJoinVO> hostTagsSearchCriteria = hostTagsSearchBuilder.create();
-                for(String tag : hostTags) {
-                    hostTagsSearchCriteria.setParameters(tag, tag);
-                }
+            SearchCriteria<ServiceOfferingJoinVO> hostTagsSearchCriteria = hostTagsSearchBuilder.create();
+            for(String tag : hostTags) {
+                hostTagsSearchCriteria.setParameters(tag, tag);
+            }
 
-                SearchCriteria<ServiceOfferingJoinVO> finalHostTagsSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
-                finalHostTagsSearchCriteria.addOr("hostTag", Op.NULL);
-                finalHostTagsSearchCriteria.addOr("hostTag", Op.SC, hostTagsSearchCriteria);
+            SearchCriteria<ServiceOfferingJoinVO> finalHostTagsSearchCriteria = _srvOfferingJoinDao.createSearchCriteria();
+            finalHostTagsSearchCriteria.addOr("hostTag", Op.NULL);
+            finalHostTagsSearchCriteria.addOr("hostTag", Op.SC, hostTagsSearchCriteria);
 
-                sc.addAnd("hostTagsConstraint", SearchCriteria.Op.SC, finalHostTagsSearchCriteria);
-            }
+            sc.addAnd("hostTagsConstraint", SearchCriteria.Op.SC, finalHostTagsSearchCriteria);
         }
 
         return _srvOfferingJoinDao.searchAndCount(sc, searchFilter);
diff --git a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java
index ebeab0b0773..ad518a0e197 100644
--- a/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java
+++ b/server/src/main/java/com/cloud/api/query/ViewResponseHelper.java
@@ -557,12 +557,8 @@ public class ViewResponseHelper {
         return respList;
     }
 
-    public static List<DiskOfferingResponse> createDiskOfferingResponse(DiskOfferingJoinVO... offerings) {
-        List<DiskOfferingResponse> respList = new ArrayList<DiskOfferingResponse>();
-        for (DiskOfferingJoinVO vt : offerings) {
-            respList.add(ApiDBUtils.newDiskOfferingResponse(vt));
-        }
-        return respList;
+    public static List<DiskOfferingResponse> createDiskOfferingResponses(Long vmId, List<DiskOfferingJoinVO> offerings) {
+        return ApiDBUtils.newDiskOfferingResponses(vmId, offerings);
     }
 
     public static List<ServiceOfferingResponse> createServiceOfferingResponse(ServiceOfferingJoinVO... offerings) {
diff --git a/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDao.java b/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDao.java
index 6356addcb4f..b4427a6315a 100644
--- a/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDao.java
+++ b/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDao.java
@@ -19,7 +19,6 @@ package com.cloud.api.query.dao;
 import java.util.List;
 import java.util.Set;
 
-import com.cloud.vm.VirtualMachine;
 import org.apache.cloudstack.api.ApiConstants.VMDetails;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.response.UserVmResponse;
@@ -28,6 +27,7 @@ import com.cloud.api.query.vo.UserVmJoinVO;
 import com.cloud.user.Account;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.db.GenericDao;
+import com.cloud.vm.VirtualMachine;
 
 public interface UserVmJoinDao extends GenericDao<UserVmJoinVO, Long> {
 
@@ -43,4 +43,7 @@ public interface UserVmJoinDao extends GenericDao<UserVmJoinVO, Long> {
     List<UserVmJoinVO> searchByIds(Long... ids);
 
     List<UserVmJoinVO> listActiveByIsoId(Long isoId);
+
+    List<UserVmJoinVO> listByAccountServiceOfferingTemplateAndNotInState(long accountId, List<VirtualMachine.State> states,
+            List<Long> offeringIds, List<Long> templateIds);
 }
diff --git a/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java b/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
index c331e913090..5d8c32fc664 100644
--- a/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
+++ b/server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java
@@ -43,6 +43,7 @@ import org.apache.cloudstack.api.response.VnfNicResponse;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.query.QueryService;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
@@ -679,4 +680,30 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
         return searchByIds(vmIdSet.toArray(new Long[vmIdSet.size()]));
     }
 
+    @Override
+    public List<UserVmJoinVO> listByAccountServiceOfferingTemplateAndNotInState(long accountId, List<State> states,
+            List<Long> offeringIds, List<Long> templateIds) {
+        SearchBuilder<UserVmJoinVO> userVmSearch = createSearchBuilder();
+        userVmSearch.and("accountId", userVmSearch.entity().getAccountId(), Op.EQ);
+        userVmSearch.and("serviceOfferingId", userVmSearch.entity().getServiceOfferingId(), Op.IN);
+        userVmSearch.and("templateId", userVmSearch.entity().getTemplateId(), Op.IN);
+        userVmSearch.and("state", userVmSearch.entity().getState(), SearchCriteria.Op.NIN);
+        userVmSearch.and("displayVm", userVmSearch.entity().isDisplayVm(), Op.EQ);
+        userVmSearch.groupBy(userVmSearch.entity().getId()); // select distinct
+        userVmSearch.done();
+
+        SearchCriteria<UserVmJoinVO> sc = userVmSearch.create();
+        sc.setParameters("accountId", accountId);
+        if (CollectionUtils.isNotEmpty(offeringIds)) {
+            sc.setParameters("serviceOfferingId", offeringIds.toArray());
+        }
+        if (CollectionUtils.isNotEmpty(templateIds)) {
+            sc.setParameters("templateId", templateIds.toArray());
+        }
+        if (CollectionUtils.isNotEmpty(states)) {
+            sc.setParameters("state", states.toArray());
+        }
+        sc.setParameters("displayVm", 1);
+        return listBy(sc);
+    }
 }
diff --git a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
index 75b47c357bd..41a51bc7af5 100644
--- a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@ -125,6 +125,7 @@ import com.cloud.storage.dao.GuestOSCategoryDao;
 import com.cloud.storage.dao.GuestOSDao;
 import com.cloud.storage.dao.StoragePoolHostDao;
 import com.cloud.storage.dao.VolumeDao;
+import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.AccountManager;
 import com.cloud.utils.DateUtil;
 import com.cloud.utils.NumbersUtil;
@@ -730,10 +731,11 @@ StateListener<State, VirtualMachine.Event, VirtualMachine>, Configurable {
 
     protected boolean checkVmProfileAndHost(final VirtualMachineProfile vmProfile, final HostVO host) {
         ServiceOffering offering = vmProfile.getServiceOffering();
-        if (offering.getHostTag() != null) {
+        VirtualMachineTemplate template = vmProfile.getTemplate();
+        if (offering.getHostTag() != null || template.getTemplateTag() != null) {
             _hostDao.loadHostTags(host);
-            if (!host.checkHostServiceOfferingTags(offering)) {
-                logger.debug("Service Offering host tag does not match the last host of this VM");
+            if (!host.checkHostServiceOfferingAndTemplateTags(offering, template)) {
+                logger.debug("Service Offering host tag or template tag does not match the last host of this VM");
                 return false;
             }
         }
diff --git a/server/src/main/java/com/cloud/resourcelimit/CheckedReservation.java b/server/src/main/java/com/cloud/resourcelimit/CheckedReservation.java
index e52bd5632cb..a2a2ffe1929 100644
--- a/server/src/main/java/com/cloud/resourcelimit/CheckedReservation.java
+++ b/server/src/main/java/com/cloud/resourcelimit/CheckedReservation.java
@@ -18,10 +18,16 @@
 //
 package com.cloud.resourcelimit;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.reservation.ReservationVO;
 import org.apache.cloudstack.reservation.dao.ReservationDao;
 import org.apache.cloudstack.user.ResourceReservation;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.jetbrains.annotations.NotNull;
@@ -34,19 +40,33 @@ import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 
-public class CheckedReservation  implements AutoCloseable, ResourceReservation {
+public class CheckedReservation  implements AutoCloseable {
     protected Logger logger = LogManager.getLogger(getClass());
 
     private static final int TRY_TO_GET_LOCK_TIME = 120;
     private GlobalLock quotaLimitLock;
     ReservationDao reservationDao;
+
+    ResourceLimitService resourceLimitService;
     private final Account account;
     private final ResourceType resourceType;
     private Long amount;
-    private ResourceReservation reservation;
+    private List<ResourceReservation> reservations;
+    private List<String> resourceLimitTags;
 
     private String getContextParameterKey() {
-        return String.format("%s-%s", ResourceReservation.class.getSimpleName(), resourceType.getName());
+        return getResourceReservationContextParameterKey(resourceType);
+    }
+
+    public static String getResourceReservationContextParameterKey(final ResourceType type) {
+        return String.format("%s-%s", ResourceReservation.class.getSimpleName(), type.getName());
+    }
+
+    protected void checkLimitAndPersistReservation(Account account, ResourceType resourceType, String tag, Long amount) throws ResourceAllocationException {
+        resourceLimitService.checkResourceLimitWithTag(account, resourceType, tag, amount);
+        ReservationVO reservationVO = new ReservationVO(account.getAccountId(), account.getDomainId(), resourceType, tag, amount);
+        ResourceReservation reservation = reservationDao.persist(reservationVO);
+        this.reservations.add(reservation);
     }
 
     /**
@@ -57,13 +77,16 @@ public class CheckedReservation  implements AutoCloseable, ResourceReservation {
      * @param amount positive number of the resource type to reserve
      * @throws ResourceAllocationException
      */
-    public CheckedReservation(Account account, ResourceType resourceType, Long amount, ReservationDao reservationDao, ResourceLimitService resourceLimitService) throws ResourceAllocationException {
+    public CheckedReservation(Account account, ResourceType resourceType, List<String> resourceLimitTags, Long amount,
+          ReservationDao reservationDao, ResourceLimitService resourceLimitService) throws ResourceAllocationException {
         this.reservationDao = reservationDao;
+        this.resourceLimitService = resourceLimitService;
         this.account = account;
         this.resourceType = resourceType;
         this.amount = amount;
-        this.reservation = null;
-        setGlobalLock(account, resourceType);
+        this.reservations = new ArrayList<>();
+        this.resourceLimitTags = resourceLimitTags;
+        setGlobalLock();
         if (this.amount != null && this.amount <= 0) {
             if(logger.isDebugEnabled()){
                 logger.debug(String.format("not reserving no amount of resources for %s in domain %d, type: %s, %s ", account.getAccountName(), account.getDomainId(), resourceType, amount));
@@ -74,10 +97,13 @@ public class CheckedReservation  implements AutoCloseable, ResourceReservation {
         if (this.amount != null) {
             if(quotaLimitLock.lock(TRY_TO_GET_LOCK_TIME)) {
                 try {
-                    resourceLimitService.checkResourceLimit(account,resourceType,amount);
-                    ReservationVO reservationVO = new ReservationVO(account.getAccountId(), account.getDomainId(), resourceType, amount);
-                    this.reservation = reservationDao.persist(reservationVO);
-                    CallContext.current().putContextParameter(getContextParameterKey(), reservation.getId());
+                    checkLimitAndPersistReservation(account, resourceType, null, amount);
+                    if (CollectionUtils.isNotEmpty(resourceLimitTags)) {
+                        for (String tag: resourceLimitTags) {
+                            checkLimitAndPersistReservation(account, resourceType, tag, amount);
+                        }
+                    }
+                    CallContext.current().putContextParameter(getContextParameterKey(), getIds());
                 } catch (NullPointerException npe) {
                     throw new CloudRuntimeException("not enough means to check limits", npe);
                 } finally {
@@ -87,14 +113,19 @@ public class CheckedReservation  implements AutoCloseable, ResourceReservation {
                 throw new ResourceAllocationException(String.format("unable to acquire resource reservation \"%s\"", quotaLimitLock.getName()), resourceType);
             }
         } else {
-            if(logger.isDebugEnabled()){
-                logger.debug(String.format("not reserving no amount of resources for %s in domain %d, type: %s ", account.getAccountName(), account.getDomainId(), resourceType));
+            if(logger.isDebugEnabled()) {
+                logger.debug(String.format("not reserving no amount of resources for %s in domain %d, type: %s, tag: %s", account.getAccountName(), account.getDomainId(), resourceType, getResourceLimitTagsAsString()));
             }
         }
     }
 
+    public CheckedReservation(Account account, ResourceType resourceType, Long amount, ReservationDao reservationDao,
+                              ResourceLimitService resourceLimitService) throws ResourceAllocationException {
+        this(account, resourceType, null, amount, reservationDao, resourceLimitService);
+    }
+
     @NotNull
-    private void setGlobalLock(Account account, ResourceType resourceType) {
+    private void setGlobalLock() {
         String lockName = String.format("CheckedReservation-%s/%d", account.getDomainId(), resourceType.getOrdinal());
         setQuotaLimitLock(GlobalLock.getInternLock(lockName));
     }
@@ -105,39 +136,36 @@ public class CheckedReservation  implements AutoCloseable, ResourceReservation {
 
     @Override
     public void close() throws Exception {
-        if (this.reservation != null) {
-            CallContext.current().removeContextParameter(getContextParameterKey());
+        if (CollectionUtils.isEmpty(reservations)) {
+            return;
+        }
+        CallContext.current().removeContextParameter(getContextParameterKey());
+        for (ResourceReservation reservation : reservations) {
             reservationDao.remove(reservation.getId());
-            reservation = null;
         }
+        reservations = null;
     }
 
     public Account getAccount() {
         return account;
     }
 
-    @Override
-    public Long getAccountId() {
-        return account.getId();
-    }
-
-    @Override
-    public Long getDomainId() {
-        return account.getDomainId();
-    }
-
-    @Override
-    public ResourceType getResourceType() {
-        return resourceType;
+    public String getResourceLimitTagsAsString() {
+        return CollectionUtils.isNotEmpty(resourceLimitTags) ? StringUtils.join(resourceLimitTags) : null;
     }
 
-    @Override
     public Long getReservedAmount() {
         return amount;
     }
 
-    @Override
-    public long getId() {
-        return this.reservation.getId();
+    public List<ResourceReservation> getReservations() {
+        return reservations;
+    }
+
+    public List<Long> getIds() {
+        if (CollectionUtils.isEmpty(reservations)) {
+            return new ArrayList<>();
+        }
+        return reservations.stream().map(ResourceReservation::getId).collect(Collectors.toList());
     }
 }
diff --git a/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index de2b109e73e..e61d52f2f0c 100644
--- a/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -20,21 +20,25 @@ import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import com.cloud.cluster.ManagementServerHostVO;
-import com.cloud.cluster.dao.ManagementServerHostDao;
-import com.cloud.utils.db.GlobalLock;
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.ResourceLimitAndCountResponse;
+import org.apache.cloudstack.api.response.TaggedResourceLimitAndCountResponse;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.framework.config.ConfigKey;
@@ -46,14 +50,17 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
-import org.apache.cloudstack.user.ResourceReservation;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
 import com.cloud.alert.AlertManager;
 import com.cloud.api.query.dao.UserVmJoinDao;
 import com.cloud.api.query.vo.UserVmJoinVO;
+import com.cloud.cluster.ManagementServerHostVO;
+import com.cloud.cluster.dao.ManagementServerHostDao;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.Resource;
 import com.cloud.configuration.Resource.ResourceOwnerType;
@@ -75,29 +82,39 @@ import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.vpc.dao.VpcDao;
+import com.cloud.offering.DiskOffering;
+import com.cloud.offering.ServiceOffering;
 import com.cloud.projects.Project;
 import com.cloud.projects.ProjectAccount.Role;
 import com.cloud.projects.dao.ProjectAccountDao;
 import com.cloud.projects.dao.ProjectDao;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.DiskOfferingVO;
 import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
 import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.dao.VolumeDaoImpl.SumCount;
+import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
 import com.cloud.user.ResourceLimitService;
 import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.Pair;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.EntityManager;
 import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
@@ -109,6 +126,7 @@ import com.cloud.utils.db.TransactionCallbackNoReturn;
 import com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn;
 import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.dao.UserVmDao;
@@ -122,7 +140,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     @Inject
     private AlertManager _alertMgr;
     @Inject
-    private AccountDao _accountDao;
+    AccountDao _accountDao;
     @Inject
     private ConfigurationDao _configDao;
     @Inject
@@ -167,6 +185,10 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     private VlanDao _vlanDao;
     @Inject
     private ManagementServerHostDao managementServerHostDao;
+    @Inject
+    ServiceOfferingDao serviceOfferingDao;
+    @Inject
+    DiskOfferingDao diskOfferingDao;
 
     protected GenericSearchBuilder<TemplateDataStoreVO, SumCount> templateSizeSearch;
     protected GenericSearchBuilder<SnapshotDataStoreVO, SumCount> snapshotSizeSearch;
@@ -174,20 +196,24 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     protected SearchBuilder<ResourceCountVO> ResourceCountSearch;
     ScheduledExecutorService _rcExecutor;
     long _resourceCountCheckInterval = 0;
-    Map<ResourceType, Long> accountResourceLimitMap = new EnumMap<ResourceType, Long>(ResourceType.class);
-    Map<ResourceType, Long> domainResourceLimitMap = new EnumMap<ResourceType, Long>(ResourceType.class);
-    Map<ResourceType, Long> projectResourceLimitMap = new EnumMap<ResourceType, Long>(ResourceType.class);
+    Map<String, Long> accountResourceLimitMap = new HashMap<>();
+    Map<String, Long> domainResourceLimitMap = new HashMap<>();
+    Map<String, Long> projectResourceLimitMap = new HashMap<>();
 
-    protected void removeResourceReservationIfNeededAndIncrementResourceCount(final long accountId, final ResourceType type, final long numToIncrement) {
+    @SuppressWarnings("unchecked")
+    protected void removeResourceReservationIfNeededAndIncrementResourceCount(final long accountId, final ResourceType type, String tag, final long numToIncrement) {
         Transaction.execute(new TransactionCallbackWithExceptionNoReturn<CloudRuntimeException>() {
             @Override
             public void doInTransactionWithoutResult(TransactionStatus status) throws CloudRuntimeException {
 
-                Object obj = CallContext.current().getContextParameter(String.format("%s-%s", ResourceReservation.class.getSimpleName(), type.getName()));
-                if (obj instanceof Long) {
-                    reservationDao.remove((long)obj);
+                Object obj = CallContext.current().getContextParameter(CheckedReservation.getResourceReservationContextParameterKey(type));
+                if (obj instanceof List) {
+                    List<Long> reservationIds = (List<Long>)obj; // This complains an unchecked casting warning
+                    for (Long reservationId : reservationIds) {
+                        reservationDao.remove(reservationId);
+                    }
                 }
-                if (!updateResourceCountForAccount(accountId, type, true, numToIncrement)) {
+                if (!updateResourceCountForAccount(accountId, type, tag, true, numToIncrement)) {
                     // we should fail the operation (resource creation) when failed to update the resource count
                     throw new CloudRuntimeException("Failed to increment resource count of type " + type + " for account id=" + accountId);
                 }
@@ -241,41 +267,41 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
 
         try {
-            projectResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPublicIPs.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectSnapshots.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.template, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectTemplates.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.user_vm, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectUserVms.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.volume, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectVolumes.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.network, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectNetworks.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.vpc, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectVpcs.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectCpus.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectMemory.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPrimaryStorage.key())));
-            projectResourceLimitMap.put(Resource.ResourceType.secondary_storage, MaxProjectSecondaryStorage.value());
-
-            accountResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.template, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountTemplates.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.user_vm, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountUserVms.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.volume, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVolumes.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.network, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountNetworks.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.vpc, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVpcs.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountCpus.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountMemory.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPrimaryStorage.key())));
-            accountResourceLimitMap.put(Resource.ResourceType.secondary_storage, MaxAccountSecondaryStorage.value());
-
-            domainResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPublicIPs.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.template, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainTemplates.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.user_vm, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainUserVms.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.volume, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainVolumes.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.network, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainNetworks.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.vpc, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainVpcs.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainCpus.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainMemory.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPrimaryStorage.key())));
-            domainResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSecondaryStorage.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.public_ip.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPublicIPs.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.snapshot.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectSnapshots.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.template.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectTemplates.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.user_vm.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectUserVms.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.volume.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectVolumes.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.network.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectNetworks.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.vpc.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectVpcs.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.cpu.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectCpus.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.memory.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectMemory.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.primary_storage.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPrimaryStorage.key())));
+            projectResourceLimitMap.put(Resource.ResourceType.secondary_storage.name(), MaxProjectSecondaryStorage.value());
+
+            accountResourceLimitMap.put(Resource.ResourceType.public_ip.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.snapshot.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.template.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountTemplates.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.user_vm.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountUserVms.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.volume.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVolumes.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.network.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountNetworks.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.vpc.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVpcs.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.cpu.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountCpus.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.memory.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountMemory.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.primary_storage.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPrimaryStorage.key())));
+            accountResourceLimitMap.put(Resource.ResourceType.secondary_storage.name(), MaxAccountSecondaryStorage.value());
+
+            domainResourceLimitMap.put(Resource.ResourceType.public_ip.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPublicIPs.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.snapshot.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.template.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainTemplates.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.user_vm.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainUserVms.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.volume.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainVolumes.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.network.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainNetworks.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.vpc.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainVpcs.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.cpu.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainCpus.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.memory.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainMemory.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.primary_storage.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPrimaryStorage.key())));
+            domainResourceLimitMap.put(Resource.ResourceType.secondary_storage.name(), Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSecondaryStorage.key())));
         } catch (NumberFormatException e) {
             logger.error("NumberFormatException during configuration", e);
             throw new ConfigurationException("Configuration failed due to NumberFormatException, see log for the stacktrace");
@@ -285,7 +311,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     }
 
     @Override
-    public void incrementResourceCount(long accountId, ResourceType type, Long... delta) {
+    public void incrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta) {
         // don't upgrade resource count for system account
         if (accountId == Account.ACCOUNT_ID_SYSTEM) {
             logger.trace("Not incrementing resource count for system accounts, returning");
@@ -293,11 +319,16 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
 
         final long numToIncrement = (delta.length == 0) ? 1 : delta[0].longValue();
-        removeResourceReservationIfNeededAndIncrementResourceCount(accountId, type, numToIncrement);
+        removeResourceReservationIfNeededAndIncrementResourceCount(accountId, type, tag, numToIncrement);
     }
 
     @Override
-    public void decrementResourceCount(long accountId, ResourceType type, Long... delta) {
+    public void incrementResourceCount(long accountId, ResourceType type, Long... delta) {
+        incrementResourceCountWithTag(accountId, type, null, delta);
+    }
+
+    @Override
+    public void decrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta) {
         // don't upgrade resource count for system account
         if (accountId == Account.ACCOUNT_ID_SYSTEM) {
             logger.trace("Not decrementing resource count for system accounts, returning");
@@ -305,14 +336,19 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
         long numToDecrement = (delta.length == 0) ? 1 : delta[0].longValue();
 
-        if (!updateResourceCountForAccount(accountId, type, false, numToDecrement)) {
+        if (!updateResourceCountForAccount(accountId, type, tag, false, numToDecrement)) {
             _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPDATE_RESOURCE_COUNT, 0L, 0L, "Failed to decrement resource count of type " + type + " for account id=" + accountId,
                     "Failed to decrement resource count of type " + type + " for account id=" + accountId + "; use updateResourceCount API to recalculate/fix the problem");
         }
     }
 
     @Override
-    public long findCorrectResourceLimitForAccount(Account account, ResourceType type) {
+    public void decrementResourceCount(long accountId, ResourceType type, Long... delta) {
+        decrementResourceCountWithTag(accountId, type, null, delta);
+    }
+
+    @Override
+    public long findCorrectResourceLimitForAccount(Account account, ResourceType type, String tag) {
 
         long max = Resource.RESOURCE_UNLIMITED; // if resource limit is not found, then we treat it as unlimited
 
@@ -321,18 +357,22 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             return max;
         }
 
-        ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(account.getId(), ResourceOwnerType.Account, type);
+        ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndTypeAndTag(account.getId(), ResourceOwnerType.Account, type, tag);
 
         // Check if limit is configured for account
         if (limit != null) {
             max = limit.getMax().longValue();
         } else {
+            String resourceTypeName = type.name();
             // If the account has an no limit set, then return global default account limits
             Long value = null;
             if (account.getType() == Account.Type.PROJECT) {
-                value = projectResourceLimitMap.get(type);
+                value = projectResourceLimitMap.get(resourceTypeName);
             } else {
-                value = accountResourceLimitMap.get(type);
+                if (StringUtils.isNotEmpty(tag)) {
+                    return findCorrectResourceLimitForAccount(account, type, null);
+                }
+                value = accountResourceLimitMap.get(resourceTypeName);
             }
             if (value != null) {
                 if (value < 0) { // return unlimit if value is set to negative
@@ -371,9 +411,9 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             // If the account has an no limit set, then return global default account limits
             Long value = null;
             if (account.getType() == Account.Type.PROJECT) {
-                value = projectResourceLimitMap.get(type);
+                value = projectResourceLimitMap.get(type.getName());
             } else {
-                value = accountResourceLimitMap.get(type);
+                value = accountResourceLimitMap.get(type.getName());
             }
             if (value != null) {
                 if (value < 0) { // return unlimit if value is set to negative
@@ -390,7 +430,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     }
 
     @Override
-    public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type) {
+    public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type, String tag) {
         long max = Resource.RESOURCE_UNLIMITED;
 
         // no limits on ROOT domain
@@ -398,7 +438,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             return Resource.RESOURCE_UNLIMITED;
         }
         // Check account
-        ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(domain.getId(), ResourceOwnerType.Domain, type);
+        ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndTypeAndTag(domain.getId(), ResourceOwnerType.Domain, type, tag);
 
         if (limit != null) {
             max = limit.getMax().longValue();
@@ -409,7 +449,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
                 if (domainId == Domain.ROOT_DOMAIN) {
                     break;
                 }
-                limit = _resourceLimitDao.findByOwnerIdAndType(domainId, ResourceOwnerType.Domain, type);
+                limit = _resourceLimitDao.findByOwnerIdAndTypeAndTag(domainId, ResourceOwnerType.Domain, type, tag);
                 DomainVO tmpDomain = _domainDao.findById(domainId);
                 domainId = tmpDomain.getParent();
             }
@@ -417,8 +457,11 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             if (limit != null) {
                 max = limit.getMax().longValue();
             } else {
+                if (StringUtils.isNotEmpty(tag)) {
+                    return findCorrectResourceLimitForDomain(domain, type, null);
+                }
                 Long value = null;
-                value = domainResourceLimitMap.get(type);
+                value = domainResourceLimitMap.get(type.name());
                 if (value != null) {
                     if (value < 0) { // return unlimit if value is set to negative
                         return max;
@@ -434,7 +477,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         return max;
     }
 
-    private void checkDomainResourceLimit(final Account account, final Project project, final ResourceType type, long numResources) throws ResourceAllocationException {
+    protected void checkDomainResourceLimit(final Account account, final Project project, final ResourceType type, String tag, long numResources) throws ResourceAllocationException {
         // check all domains in the account's domain hierarchy
         Long domainId = null;
         if (project != null) {
@@ -447,9 +490,9 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             DomainVO domain = _domainDao.findById(domainId);
             // no limit check if it is ROOT domain
             if (domainId != Domain.ROOT_DOMAIN) {
-                long domainResourceLimit = findCorrectResourceLimitForDomain(domain, type);
-                long currentDomainResourceCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type);
-                long currentResourceReservation = reservationDao.getDomainReservation(domainId, type);
+                long domainResourceLimit = findCorrectResourceLimitForDomain(domain, type, tag);
+                long currentDomainResourceCount = _resourceCountDao.getResourceCount(domainId, ResourceOwnerType.Domain, type, tag);
+                long currentResourceReservation = reservationDao.getDomainReservation(domainId, type, tag);
                 long requestedDomainResourceCount = currentDomainResourceCount + currentResourceReservation + numResources;
 
                 String convDomainResourceLimit = String.valueOf(domainResourceLimit);
@@ -464,10 +507,14 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
                     convNumResources = toHumanReadableSize(numResources);
                 }
 
+                String typeString = type.getName();
+                if (StringUtils.isNotEmpty(tag)) {
+                    typeString = String.format("%s (tag: %s)", typeString, tag);
+                }
                 String messageSuffix = String.format(
                         " domain resource limits of Type '%s' for Domain Id = %s is exceeded: Domain Resource Limit = %s, " +
                         "Current Domain Resource Amount = %s, Current Resource Reservation = %s, Requested Resource Amount = %s.",
-                        type, domainId, convDomainResourceLimit,
+                        typeString, domain.getUuid(), convDomainResourceLimit,
                         convCurrentDomainResourceCount, convCurrentResourceReservation, convNumResources
                 );
 
@@ -486,11 +533,11 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
     }
 
-    private void checkAccountResourceLimit(final Account account, final Project project, final ResourceType type, long numResources) throws ResourceAllocationException {
+    protected void checkAccountResourceLimit(final Account account, final Project project, final ResourceType type, String tag, long numResources) throws ResourceAllocationException {
         // Check account limits
-        long accountResourceLimit = findCorrectResourceLimitForAccount(account, type);
-        long currentResourceCount = _resourceCountDao.getResourceCount(account.getId(), ResourceOwnerType.Account, type);
-        long currentResourceReservation = reservationDao.getAccountReservation(account.getId(), type);
+        long accountResourceLimit = findCorrectResourceLimitForAccount(account, type, tag);
+        long currentResourceCount = _resourceCountDao.getResourceCount(account.getId(), ResourceOwnerType.Account, type, tag);
+        long currentResourceReservation = reservationDao.getAccountReservation(account.getId(), type, tag);
         long requestedResourceCount = currentResourceCount + currentResourceReservation + numResources;
 
         String convertedAccountResourceLimit = String.valueOf(accountResourceLimit);
@@ -506,9 +553,9 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
 
         String messageSuffix = String.format(
-                " amount of resources of Type = '%s' for %s in Domain Id = %s is exceeded: " +
+                " amount of resources of Type = '%s', tag = '%s' for %s in Domain Id = %s is exceeded: " +
                 "Account Resource Limit = %s, Current Account Resource Amount = %s, Current Account Resource Reservation = %s, Requested Resource Amount = %s.",
-                type, (project == null ? "Account Name = " + account.getAccountName() : "Project Name = " + project.getName()), account.getDomainId(),
+                type, tag, (project == null ? "Account Name = " + account.getAccountName() : "Project Name = " + project.getName()), account.getDomainId(),
                 convertedAccountResourceLimit, convertedCurrentResourceCount, convertedCurrentResourceReservation, convertedNumResources
         );
 
@@ -524,15 +571,15 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
     }
 
-    private List<ResourceCountVO> lockAccountAndOwnerDomainRows(long accountId, final ResourceType type) {
-        Set<Long> rowIdsToLock = _resourceCountDao.listAllRowsToUpdate(accountId, ResourceOwnerType.Account, type);
+    protected List<ResourceCountVO> lockAccountAndOwnerDomainRows(long accountId, final ResourceType type, String tag) {
+        Set<Long> rowIdsToLock = _resourceCountDao.listAllRowsToUpdate(accountId, ResourceOwnerType.Account, type, tag);
         SearchCriteria<ResourceCountVO> sc = ResourceCountSearch.create();
         sc.setParameters("id", rowIdsToLock.toArray());
         return _resourceCountDao.lockRows(sc, null, true);
     }
 
-    private List<ResourceCountVO> lockDomainRows(long domainId, final ResourceType type) {
-        Set<Long> rowIdsToLock = _resourceCountDao.listAllRowsToUpdate(domainId, ResourceOwnerType.Domain, type);
+    private List<ResourceCountVO> lockDomainRows(long domainId, final ResourceType type, String tag) {
+        Set<Long> rowIdsToLock = _resourceCountDao.listAllRowsToUpdate(domainId, ResourceOwnerType.Domain, type, tag);
         SearchCriteria<ResourceCountVO> sc = ResourceCountSearch.create();
         sc.setParameters("id", rowIdsToLock.toArray());
         return _resourceCountDao.lockRows(sc, null, true);
@@ -541,7 +588,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     @Override
     public long findDefaultResourceLimitForDomain(ResourceType resourceType) {
         Long resourceLimit = null;
-        resourceLimit = domainResourceLimitMap.get(resourceType);
+        resourceLimit = domainResourceLimitMap.get(resourceType.getName());
         if (resourceLimit != null && (resourceType == ResourceType.primary_storage || resourceType == ResourceType.secondary_storage)) {
             if (! Long.valueOf(Resource.RESOURCE_UNLIMITED).equals(resourceLimit)) {
                 resourceLimit = resourceLimit * ResourceType.bytesToGiB;
@@ -553,9 +600,9 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     }
 
     @Override
-    public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type) {
-        long maxSecondaryStorageForAccount = findCorrectResourceLimitForAccount(account, type);
-        long maxSecondaryStorageForDomain = findCorrectResourceLimitForDomain(domain, type);
+    public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type, String tag) {
+        long maxSecondaryStorageForAccount = findCorrectResourceLimitForAccount(account, type, tag);
+        long maxSecondaryStorageForDomain = findCorrectResourceLimitForDomain(domain, type, tag);
 
         if (maxSecondaryStorageForDomain == Resource.RESOURCE_UNLIMITED || maxSecondaryStorageForAccount == Resource.RESOURCE_UNLIMITED) {
             return Math.max(maxSecondaryStorageForDomain, maxSecondaryStorageForAccount);
@@ -567,6 +614,12 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     @Override
     @DB
     public void checkResourceLimit(final Account account, final ResourceType type, long... count) throws ResourceAllocationException {
+        checkResourceLimitWithTag(account, type, null, count);
+    }
+
+    @Override
+    @DB
+    public void checkResourceLimitWithTag(final Account account, final ResourceType type, String tag, long... count) throws ResourceAllocationException {
         final long numResources = ((count.length == 0) ? 1 : count[0]);
         Project project = null;
 
@@ -584,17 +637,42 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             @Override
             public void doInTransactionWithoutResult(TransactionStatus status) throws ResourceAllocationException {
                 // Lock all rows first so nobody else can read it
-                lockAccountAndOwnerDomainRows(account.getId(), type);
+                lockAccountAndOwnerDomainRows(account.getId(), type, tag);
                 // Check account limits
-                checkAccountResourceLimit(account, projectFinal, type, numResources);
+                checkAccountResourceLimit(account, projectFinal, type, tag, numResources);
                 // check all domains in the account's domain hierarchy
-                checkDomainResourceLimit(account, projectFinal, type, numResources);
+                checkDomainResourceLimit(account, projectFinal, type, tag, numResources);
             }
         });
     }
 
+    /**
+     * To retrieve host and storage limit tags lists with or without a given tag string
+     * while searching for limits for an account or domain
+     * @param tag - tag string to filter list of host and storage limit tags
+     * @return a pair of host tags list and storage tags list
+     */
+    protected Pair<List<String>, List<String>> getResourceLimitTagsForLimitSearch(String tag) {
+        List<String> hostTags = getResourceLimitHostTags();
+        List<String> storageTags = getResourceLimitStorageTags();
+        if (tag == null) {
+            return new Pair<>(hostTags, storageTags);
+        }
+        if (hostTags.contains(tag)) {
+            hostTags = List.of(tag);
+        } else {
+            hostTags = new ArrayList<>();
+        }
+        if (storageTags.contains(tag)) {
+            storageTags = List.of(tag);
+        } else  {
+            storageTags = new ArrayList<>();
+        }
+        return new Pair<>(hostTags, storageTags);
+    }
+
     @Override
-    public List<ResourceLimitVO> searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, Long startIndex, Long pageSizeVal) {
+    public List<ResourceLimitVO> searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, String tag, Long startIndex, Long pageSizeVal) {
         Account caller = CallContext.current().getCallingAccount();
         List<ResourceLimitVO> limits = new ArrayList<ResourceLimitVO>();
         boolean isAccount = true;
@@ -657,6 +735,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
         sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
         sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
+        sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ);
 
         SearchCriteria<ResourceLimitVO> sc = sb.create();
         Filter filter = new Filter(ResourceLimitVO.class, "id", true, startIndex, pageSizeVal);
@@ -674,15 +753,29 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             sc.setParameters("type", resourceType);
         }
 
+        if (tag != null) {
+            sc.setParameters("tag", tag);
+        }
+
         List<ResourceLimitVO> foundLimits = _resourceLimitDao.search(sc, filter);
 
+        Pair<List<String>, List<String>> tagsPair = getResourceLimitTagsForLimitSearch(tag);
+        List<String> hostTags = tagsPair.first();
+        List<String> storageTags = tagsPair.second();
+
         if (resourceType != null) {
             if (foundLimits.isEmpty()) {
+                ResourceOwnerType ownerType = ResourceOwnerType.Domain;
+                Long ownerId = domainId;
+                long max = 0;
                 if (isAccount) {
-                    limits.add(new ResourceLimitVO(resourceType, findCorrectResourceLimitForAccount(_accountMgr.getAccount(accountId), resourceType), accountId, ResourceOwnerType.Account));
+                    ownerType = ResourceOwnerType.Account;
+                    ownerId = accountId;
+                    max = findCorrectResourceLimitForAccount(_accountMgr.getAccount(accountId), resourceType, tag);
                 } else {
-                    limits.add(new ResourceLimitVO(resourceType, findCorrectResourceLimitForDomain(_domainDao.findById(domainId), resourceType), domainId, ResourceOwnerType.Domain));
+                    max = findCorrectResourceLimitForDomain(_domainDao.findById(domainId), resourceType, tag);
                 }
+                limits.add(new ResourceLimitVO(resourceType, max, ownerId, ownerType));
             } else {
                 limits.addAll(foundLimits);
             }
@@ -707,28 +800,83 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
                     if (accountLimitStr.size() < resourceTypes.length) {
                         for (ResourceType rt : resourceTypes) {
                             if (!accountLimitStr.contains(rt.toString())) {
-                                limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForAccount(_accountMgr.getAccount(accountId), rt), accountId, ResourceOwnerType.Account));
+                                limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForAccount(_accountMgr.getAccount(accountId), rt, null), accountId, ResourceOwnerType.Account));
                             }
                         }
                     }
-
                 } else {
                     if (domainLimitStr.size() < resourceTypes.length) {
                         for (ResourceType rt : resourceTypes) {
                             if (!domainLimitStr.contains(rt.toString())) {
-                                limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForDomain(_domainDao.findById(domainId), rt), domainId, ResourceOwnerType.Domain));
+                                limits.add(new ResourceLimitVO(rt, findCorrectResourceLimitForDomain(_domainDao.findById(domainId), rt, null), domainId, ResourceOwnerType.Domain));
                             }
                         }
                     }
                 }
             }
         }
-
+        addTaggedResourceLimits(limits, resourceType, isAccount ? ResourceOwnerType.Account : ResourceOwnerType.Domain, isAccount ? accountId : domainId, hostTags, storageTags);
         return limits;
     }
 
+    protected void addTaggedResourceLimits(List<ResourceLimitVO> limits, List<ResourceType> types, List<String> tags, ResourceOwnerType ownerType, long ownerId) {
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        if (CollectionUtils.isEmpty(types)) {
+            return;
+        }
+        for (String tag : tags) {
+            for (ResourceType type : types) {
+                if (limits.stream().noneMatch(l -> type.equals(l.getType()) && tag.equals(l.getTag()))) {
+                    limits.add(new ResourceLimitVO(type, ResourceOwnerType.Domain.equals(ownerType) ?
+                            findCorrectResourceLimitForDomain(_domainDao.findById(ownerId), type, tag) :
+                            findCorrectResourceLimitForAccount(_accountDao.findById(ownerId), type, tag),
+                            ownerId, ownerType, tag));
+                }
+            }
+        }
+    }
+
+    protected void removeUndesiredTaggedLimits(List<ResourceLimitVO> limits, List<String> hostTags, List<String> storageTags) {
+        Iterator<ResourceLimitVO> itr = limits.iterator();
+        while (itr.hasNext()) {
+            ResourceLimitVO limit = itr.next();
+            if (StringUtils.isEmpty(limit.getTag())) {
+                continue;
+            }
+            if (HostTagsSupportingTypes.contains(limit.getType()) &&
+                    (CollectionUtils.isEmpty(hostTags) || !hostTags.contains(limit.getTag()))) {
+                itr.remove();
+            }
+            if (StorageTagsSupportingTypes.contains(limit.getType()) &&
+                    (CollectionUtils.isEmpty(storageTags) || !storageTags.contains(limit.getTag()))) {
+                itr.remove();
+            }
+        }
+    }
+
+    protected void addTaggedResourceLimits(List<ResourceLimitVO> limits, ResourceType resourceType, ResourceOwnerType ownerType, long ownerId, List<String> hostTags, List<String> storageTags) {
+        removeUndesiredTaggedLimits(limits, hostTags, storageTags);
+        if (CollectionUtils.isEmpty(hostTags) && CollectionUtils.isEmpty(storageTags)) {
+            return;
+        }
+        List<ResourceType> types = resourceType != null ? HostTagsSupportingTypes.contains(resourceType) ? List.of(resourceType) : null : HostTagsSupportingTypes;
+        addTaggedResourceLimits(limits, types, hostTags, ownerType, ownerId);
+        types = resourceType != null ? StorageTagsSupportingTypes.contains(resourceType) ? List.of(resourceType) : null : StorageTagsSupportingTypes;
+        addTaggedResourceLimits(limits, types, storageTags, ownerType, ownerId);
+        limits.sort((o1, o2) -> {
+            Integer type1 = o1.getType().getOrdinal();
+            Integer type2 = o2.getType().getOrdinal();
+            if (type1.equals(type2)) {
+                return StringUtils.defaultString(o1.getTag(), "").compareTo(StringUtils.defaultString(o2.getTag(), ""));
+            }
+            return type1.compareTo(type2);
+        });
+    }
+
     @Override
-    public ResourceLimitVO updateResourceLimit(Long accountId, Long domainId, Integer typeId, Long max) {
+    public ResourceLimitVO updateResourceLimit(Long accountId, Long domainId, Integer typeId, Long max, String tag) {
         Account caller = CallContext.current().getCallingAccount();
 
         if (max == null) {
@@ -750,6 +898,12 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             }
         }
 
+        if (StringUtils.isNotEmpty(tag) &&
+                !(HostTagsSupportingTypes.contains(resourceType) ||
+                        StorageTagsSupportingTypes.contains(resourceType))) {
+            throw new InvalidParameterValueException(String.format("Resource limit with a tag is not supported for resource type %d", typeId));
+        }
+
         //Convert max storage size from GiB to bytes
         if ((resourceType == ResourceType.primary_storage || resourceType == ResourceType.secondary_storage) && max >= 0) {
             max *= ResourceType.bytesToGiB;
@@ -785,6 +939,13 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
 
             ownerType = ResourceOwnerType.Account;
             ownerId = accountId;
+            if (StringUtils.isNotEmpty(tag)) {
+                long untaggedLimit = findCorrectResourceLimitForAccount(account, resourceType, null);
+                if (untaggedLimit > 0 && max > untaggedLimit) {
+                    throw new InvalidParameterValueException(String.format("Maximum untagged resource limit for account %s for resource type %s is %d, please specify a value less than or equal to that",
+                            account.getAccountName(), resourceType, untaggedLimit));
+                }
+            }
         } else if (domainId != null) {
             Domain domain = _entityMgr.findById(Domain.class, domainId);
 
@@ -799,13 +960,20 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
                 // if the admin is trying to update their own domain, disallow...
                 throw new PermissionDeniedException("Unable to update resource limit for domain " + domainId + ", permission denied");
             }
+            if (StringUtils.isNotEmpty(tag)) {
+                long untaggedLimit = findCorrectResourceLimitForDomain(domain, resourceType, null);
+                if (untaggedLimit > 0 && max > untaggedLimit) {
+                    throw new InvalidParameterValueException(String.format("Maximum untagged resource limit for domain %s for resource type %s is %d, please specify a value less than or equal to that",
+                            domain.getName(), resourceType, untaggedLimit));
+                }
+            }
             Long parentDomainId = domain.getParent();
             if (parentDomainId != null) {
                 DomainVO parentDomain = _domainDao.findById(parentDomainId);
-                long parentMaximum = findCorrectResourceLimitForDomain(parentDomain, resourceType);
+                long parentMaximum = findCorrectResourceLimitForDomain(parentDomain, resourceType, tag);
                 if ((parentMaximum >= 0) && (max.longValue() > parentMaximum)) {
                     throw new InvalidParameterValueException("Domain " + domain.getName() + "(id: " + parentDomain.getId() + ") has maximum allowed resource limit " + parentMaximum + " for "
-                            + resourceType + ", please specify a value less that or equal to " + parentMaximum);
+                            + resourceType + ", please specify a value less than or equal to " + parentMaximum);
                 }
             }
             ownerType = ResourceOwnerType.Domain;
@@ -816,18 +984,82 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             throw new InvalidParameterValueException("AccountId or domainId have to be specified in order to update resource limit");
         }
 
-        ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndType(ownerId, ownerType, resourceType);
+        ResourceLimitVO limit = _resourceLimitDao.findByOwnerIdAndTypeAndTag(ownerId, ownerType, resourceType, tag);
         if (limit != null) {
             // Update the existing limit
             _resourceLimitDao.update(limit.getId(), max);
             return _resourceLimitDao.findById(limit.getId());
         } else {
-            return _resourceLimitDao.persist(new ResourceLimitVO(resourceType, max, ownerId, ownerType));
+            return _resourceLimitDao.persist(new ResourceLimitVO(resourceType, max, ownerId, ownerType, tag));
         }
     }
 
+    protected boolean isTaggedResourceCountRecalculationNotNeeded(ResourceType type, List<String> hostTags, List <String> storageTags) {
+        if (!HostTagsSupportingTypes.contains(type) && !StorageTagsSupportingTypes.contains(type)) {
+            return true;
+        }
+        return CollectionUtils.isEmpty(hostTags) && CollectionUtils.isEmpty(storageTags);
+    }
+
+    protected void removeResourceLimitAndCountForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType,
+                                                                 List<String> hostTags, List<String> storageTags) {
+        if (logger.isDebugEnabled()) {
+            String msg = String.format("Clearing tagged resource limits and counts which do not match " +
+                            "host tags: %s, storage tags: %s",
+                    StringUtils.join(hostTags), StringUtils.join(storageTags));
+            if (ObjectUtils.allNotNull(ownerId, ownerType)) {
+                msg = String.format("%s for %s ID: %d", msg, ownerType.getName().toLowerCase(), ownerId);
+            }
+            logger.debug(msg);
+        }
+        _resourceLimitDao.removeResourceLimitsForNonMatchingTags(ownerId, ownerType, HostTagsSupportingTypes, hostTags);
+        _resourceLimitDao.removeResourceLimitsForNonMatchingTags(ownerId, ownerType, StorageTagsSupportingTypes, storageTags);
+        _resourceCountDao.removeResourceCountsForNonMatchingTags(ownerId, ownerType, HostTagsSupportingTypes, hostTags);
+        _resourceCountDao.removeResourceCountsForNonMatchingTags(ownerId, ownerType, StorageTagsSupportingTypes, storageTags);
+    }
+
+    protected List<ResourceCountVO> recalculateAccountTaggedResourceCount(long accountId, ResourceType type, final List<String> hostTags, final List<String> storageTags) {
+        List<ResourceCountVO> result = new ArrayList<>();
+        if (isTaggedResourceCountRecalculationNotNeeded(type, hostTags, storageTags)) {
+            return result;
+        }
+        if (HostTagsSupportingTypes.contains(type) && CollectionUtils.isNotEmpty(hostTags)) {
+            for (String tag : hostTags) {
+                long count = recalculateAccountResourceCount(accountId, type, tag);
+                result.add(new ResourceCountVO(type, count, accountId, ResourceOwnerType.Account, tag));
+            }
+        }
+        if (StorageTagsSupportingTypes.contains(type) && CollectionUtils.isNotEmpty(storageTags)) {
+            for (String tag : storageTags) {
+                long count = recalculateAccountResourceCount(accountId, type, tag);
+                result.add(new ResourceCountVO(type, count, accountId, ResourceOwnerType.Account, tag));
+            }
+        }
+        return result;
+    }
+
+    protected List<ResourceCountVO> recalculateDomainTaggedResourceCount(long domainId, ResourceType type, final List<String> hostTags, final List<String> storageTags) {
+        List<ResourceCountVO> result = new ArrayList<>();
+        if (isTaggedResourceCountRecalculationNotNeeded(type, hostTags, storageTags)) {
+            return result;
+        }
+        if (HostTagsSupportingTypes.contains(type) && CollectionUtils.isNotEmpty(hostTags)) {
+            for (String tag : hostTags) {
+                long count = recalculateDomainResourceCount(domainId, type, tag);
+                result.add(new ResourceCountVO(type, count, domainId, ResourceOwnerType.Domain, tag));
+            }
+        }
+        if (StorageTagsSupportingTypes.contains(type) && CollectionUtils.isNotEmpty(storageTags)) {
+            for (String tag : storageTags) {
+                long count = recalculateDomainResourceCount(domainId, type, tag);
+                result.add(new ResourceCountVO(type, count, domainId, ResourceOwnerType.Domain, tag));
+            }
+        }
+        return result;
+    }
+
     @Override
-    public List<ResourceCountVO> recalculateResourceCount(Long accountId, Long domainId, Integer typeId) throws InvalidParameterValueException, CloudRuntimeException, PermissionDeniedException {
+    public List<? extends ResourceCount> recalculateResourceCount(Long accountId, Long domainId, Integer typeId, String tag) throws CloudRuntimeException {
         Account callerAccount = CallContext.current().getCallingAccount();
         long count = 0;
         List<ResourceCountVO> counts = new ArrayList<ResourceCountVO>();
@@ -844,6 +1076,11 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             if (resourceType == null) {
                 throw new InvalidParameterValueException("Please specify valid resource type");
             }
+            if (StringUtils.isNotEmpty(tag) &&
+                    !(HostTagsSupportingTypes.contains(resourceType) ||
+                            StorageTagsSupportingTypes.contains(resourceType))) {
+                throw new InvalidParameterValueException(String.format("Resource count with a tag is not supported for resource type %d", typeId));
+            }
         }
 
         DomainVO domain = _domainDao.findById(domainId);
@@ -858,35 +1095,50 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             resourceTypes = Arrays.asList(Resource.ResourceType.values());
         }
 
+        List<String> hostTags = getResourceLimitHostTags();
+        List<String> storageTags = getResourceLimitStorageTags();
+        removeResourceLimitAndCountForNonMatchingTags(accountId != null ? accountId : domainId,
+                accountId != null ? ResourceOwnerType.Account : ResourceOwnerType.Domain, hostTags, storageTags);
         for (ResourceType type : resourceTypes) {
             if (accountId != null) {
-                count = recalculateAccountResourceCount(accountId, type);
+                count = recalculateAccountResourceCount(accountId, type, tag);
                 counts.add(new ResourceCountVO(type, count, accountId, ResourceOwnerType.Account));
-
+                if (StringUtils.isEmpty(tag)) {
+                    counts.addAll(recalculateAccountTaggedResourceCount(accountId, type, hostTags, storageTags));
+                }
             } else {
-                count = recalculateDomainResourceCount(domainId, type);
+                count = recalculateDomainResourceCount(domainId, type, tag);
                 counts.add(new ResourceCountVO(type, count, domainId, ResourceOwnerType.Domain));
+                if (StringUtils.isEmpty(tag)) {
+                    counts.addAll(recalculateDomainTaggedResourceCount(domainId, type, hostTags, storageTags));
+                }
             }
         }
 
         return counts;
     }
 
+    @Override
+    public List<? extends ResourceCount> recalculateResourceCount(Long accountId, Long domainId, Integer typeId) throws CloudRuntimeException {
+        return recalculateResourceCount(accountId, domainId, typeId, null);
+    }
+
     @DB
-    protected boolean updateResourceCountForAccount(final long accountId, final ResourceType type, final boolean increment, final long delta) {
+    protected boolean updateResourceCountForAccount(final long accountId, final ResourceType type, String tag, final boolean increment, final long delta) {
         if (logger.isDebugEnabled()) {
             String convertedDelta = String.valueOf(delta);
             if (type == ResourceType.secondary_storage || type == ResourceType.primary_storage){
                 convertedDelta = toHumanReadableSize(delta);
             }
-            logger.debug("Updating resource Type = " + type + " count for Account = " + accountId + " Operation = " + (increment ? "increasing" : "decreasing") + " Amount = " + convertedDelta);
+            String typeStr = StringUtils.isNotEmpty(tag) ? String.format("%s (tag: %s)", type, tag) : type.getName();
+            logger.debug("Updating resource Type = " + typeStr + " count for Account = " + accountId + " Operation = " + (increment ? "increasing" : "decreasing") + " Amount = " + convertedDelta);
         }
         try {
             return Transaction.execute(new TransactionCallback<Boolean>() {
                 @Override
                 public Boolean doInTransaction(TransactionStatus status) {
                     boolean result = true;
-                    List<ResourceCountVO> rowsToUpdate = lockAccountAndOwnerDomainRows(accountId, type);
+                    List<ResourceCountVO> rowsToUpdate = lockAccountAndOwnerDomainRows(accountId, type, tag);
                     for (ResourceCountVO rowToUpdate : rowsToUpdate) {
                         if (!_resourceCountDao.updateById(rowToUpdate.getId(), increment, delta)) {
                             logger.trace("Unable to update resource count for the row " + rowToUpdate);
@@ -911,13 +1163,13 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
      * @return the resulting new resource count
      */
     @DB
-    protected long recalculateDomainResourceCount(final long domainId, final ResourceType type) {
+    protected long recalculateDomainResourceCount(final long domainId, final ResourceType type, String tag) {
         return Transaction.execute(new TransactionCallback<Long>() {
             @Override
             public Long doInTransaction(TransactionStatus status) {
                 long newResourceCount = 0;
-                lockDomainRows(domainId, type);
-                ResourceCountVO domainRC = _resourceCountDao.findByOwnerAndType(domainId, ResourceOwnerType.Domain, type);
+                lockDomainRows(domainId, type, tag);
+                ResourceCountVO domainRC = _resourceCountDao.findByOwnerAndTypeAndTag(domainId, ResourceOwnerType.Domain, type, tag);
                 long oldResourceCount = domainRC.getCount();
 
                 List<DomainVO> domainChildren = _domainDao.findImmediateChildrenForParent(domainId);
@@ -929,15 +1181,16 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
                 }
 
                 for (DomainVO childDomain : domainChildren) {
-                    long childDomainResourceCount = recalculateDomainResourceCount(childDomain.getId(), type);
+                    long childDomainResourceCount = recalculateDomainResourceCount(childDomain.getId(), type, tag);
                     newResourceCount += childDomainResourceCount; // add the child domain count to parent domain count
                 }
+
                 List<AccountVO> accounts = _accountDao.findActiveAccountsForDomain(domainId);
                 for (AccountVO account : accounts) {
-                    long accountResourceCount = recalculateAccountResourceCount(account.getId(), type);
+                    long accountResourceCount = recalculateAccountResourceCount(account.getId(), type, tag);
                     newResourceCount += accountResourceCount; // add account's resource count to parent domain count
                 }
-                _resourceCountDao.setResourceCount(domainId, ResourceOwnerType.Domain, type, newResourceCount);
+                _resourceCountDao.setResourceCount(domainId, ResourceOwnerType.Domain, type, tag, newResourceCount);
 
                 if (oldResourceCount != newResourceCount) {
                     logger.warn("Discrepency in the resource count has been detected " + "(original count = " + oldResourceCount + " correct count = " + newResourceCount + ") for Type = " + type
@@ -950,13 +1203,12 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     }
 
     @DB
-    protected long recalculateAccountResourceCount(final long accountId, final ResourceType type) {
+    protected long recalculateAccountResourceCount(final long accountId, final ResourceType type, String tag) {
         final Long newCount;
         if (type == Resource.ResourceType.user_vm) {
-            newCount = _userVmDao.countAllocatedVMsForAccount(accountId, VirtualMachineManager.ResourceCountRunningVMsonly.value());
+            newCount = calculateVmCountForAccount(accountId, tag);
         } else if (type == Resource.ResourceType.volume) {
-            long virtualRouterCount = _vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId).size();
-            newCount = _volumeDao.countAllocatedVolumesForAccount(accountId) - virtualRouterCount; // don't count the volumes of virtual router
+            newCount = calculateVolumeCountForAccount(accountId, tag);
         } else if (type == Resource.ResourceType.snapshot) {
             newCount = _snapshotDao.countSnapshotsForAccount(accountId);
         } else if (type == Resource.ResourceType.public_ip) {
@@ -970,12 +1222,11 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         } else if (type == Resource.ResourceType.vpc) {
             newCount = _vpcDao.countByAccountId(accountId);
         } else if (type == Resource.ResourceType.cpu) {
-            newCount = countCpusForAccount(accountId);
+            newCount = calculateVmCpuCountForAccount(accountId, tag);
         } else if (type == Resource.ResourceType.memory) {
-            newCount = calculateMemoryForAccount(accountId);
+            newCount = calculateVmMemoryCountForAccount(accountId, tag);
         } else if (type == Resource.ResourceType.primary_storage) {
-            List<Long> virtualRouters = _vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId);
-            newCount = _volumeDao.primaryStorageUsedForAccount(accountId, virtualRouters);
+            newCount = calculatePrimaryStorageForAccount(accountId, tag);
         } else if (type == Resource.ResourceType.secondary_storage) {
             newCount = calculateSecondaryStorageForAccount(accountId);
         } else {
@@ -983,7 +1234,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
 
         long oldCount = 0;
-        final ResourceCountVO accountRC = _resourceCountDao.findByOwnerAndType(accountId, ResourceOwnerType.Account, type);
+        final ResourceCountVO accountRC = _resourceCountDao.findByOwnerAndTypeAndTag(accountId, ResourceOwnerType.Account, type, tag);
         if (accountRC != null) {
             oldCount = accountRC.getCount();
         }
@@ -992,8 +1243,8 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             Transaction.execute(new TransactionCallbackNoReturn() {
                 @Override
                 public void doInTransactionWithoutResult(TransactionStatus status) {
-                    lockAccountAndOwnerDomainRows(accountId, type);
-                    _resourceCountDao.setResourceCount(accountId, ResourceOwnerType.Account, type, (newCount == null) ? 0 : newCount);
+                    lockAccountAndOwnerDomainRows(accountId, type, tag);
+                    _resourceCountDao.setResourceCount(accountId, ResourceOwnerType.Account, type, tag, (newCount == null) ? 0 : newCount);
                 }
             });
         }
@@ -1009,50 +1260,94 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         return (newCount == null) ? 0 : newCount;
     }
 
+    protected List<UserVmJoinVO> getVmsWithAccountAndTag(long accountId, String tag) {
+        List<VirtualMachine.State> states = new ArrayList<>(Arrays.asList(State.Destroyed, State.Error, State.Expunging));
+        if (VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
+            states.add(State.Stopped);
+        }
+        if (StringUtils.isEmpty(tag)) {
+            return _userVmJoinDao.listByAccountServiceOfferingTemplateAndNotInState(accountId, states, null, null);
+        }
+        List<ServiceOfferingVO> offerings = serviceOfferingDao.listByHostTag(tag);
+        List<VMTemplateVO> templates = _vmTemplateDao.listByTemplateTag(tag);
+        if (CollectionUtils.isEmpty(offerings) && CollectionUtils.isEmpty(templates)) {
+            return new ArrayList<>();
+        }
+        return _userVmJoinDao.listByAccountServiceOfferingTemplateAndNotInState(accountId, states,
+                offerings.stream().map(ServiceOfferingVO::getId).collect(Collectors.toList()),
+                templates.stream().map(VMTemplateVO::getId).collect(Collectors.toList()));
+    }
+
+    protected List<UserVmJoinVO> getVmsWithAccount(long accountId) {
+        return getVmsWithAccountAndTag(accountId, null);
+    }
+
+    protected List<VolumeVO> getVolumesWithAccountAndTag(long accountId, String tag) {
+        List<DiskOfferingVO> offerings = diskOfferingDao.listByStorageTag(tag);
+        if (CollectionUtils.isEmpty(offerings)) {
+            return new ArrayList<>();
+        }
+        List<Long> vrIds = _vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId);
+        return _volumeDao.listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(accountId,
+                offerings.stream().map(DiskOfferingVO::getId).collect(Collectors.toList()),
+                vrIds);
+    }
+
+    protected long calculateVmCountForAccount(long accountId, String tag) {
+        if (StringUtils.isEmpty(tag)) {
+            return _userVmDao.countAllocatedVMsForAccount(accountId, VirtualMachineManager.ResourceCountRunningVMsonly.value());
+        }
+        List<UserVmJoinVO> vms = getVmsWithAccountAndTag(accountId, tag);
+        return vms.size();
+    }
+
+    protected long calculateVolumeCountForAccount(long accountId, String tag) {
+        if (StringUtils.isEmpty(tag)) {
+            long virtualRouterCount = _vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId).size();
+            return _volumeDao.countAllocatedVolumesForAccount(accountId) - virtualRouterCount; // don't count the volumes of virtual router
+        }
+        List<VolumeVO> volumes = getVolumesWithAccountAndTag(accountId, tag);
+        return volumes.size();
+    }
+
+    protected long calculateVmCpuCountForAccount(long accountId, String tag) {
+        if (StringUtils.isEmpty(tag)) {
+            return countCpusForAccount(accountId);
+        }
+        long cputotal = 0;
+        List<UserVmJoinVO> vms = getVmsWithAccountAndTag(accountId, tag);
+        for (UserVmJoinVO vm : vms) {
+            cputotal += vm.getCpu();
+        }
+        return cputotal;
+    }
+
+    protected long calculateVmMemoryCountForAccount(long accountId, String tag) {
+        if (StringUtils.isEmpty(tag)) {
+            return calculateMemoryForAccount(accountId);
+        }
+        long memory = 0;
+        List<UserVmJoinVO> vms = getVmsWithAccountAndTag(accountId, tag);
+        for (UserVmJoinVO vm : vms) {
+            memory += vm.getRamSize();
+        }
+        return memory;
+    }
+
     public long countCpusForAccount(long accountId) {
         long cputotal = 0;
-        // user vms
-        SearchBuilder<UserVmJoinVO> userVmSearch = _userVmJoinDao.createSearchBuilder();
-        userVmSearch.and("accountId", userVmSearch.entity().getAccountId(), Op.EQ);
-        userVmSearch.and("state", userVmSearch.entity().getState(), SearchCriteria.Op.NIN);
-        userVmSearch.and("displayVm", userVmSearch.entity().isDisplayVm(), Op.EQ);
-        userVmSearch.groupBy(userVmSearch.entity().getId()); // select distinct
-        userVmSearch.done();
-
-        SearchCriteria<UserVmJoinVO> sc1 = userVmSearch.create();
-        sc1.setParameters("accountId", accountId);
-        if (VirtualMachineManager.ResourceCountRunningVMsonly.value())
-            sc1.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging, State.Stopped});
-        else
-            sc1.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
-        sc1.setParameters("displayVm", 1);
-        List<UserVmJoinVO> userVms = _userVmJoinDao.search(sc1,null);
+        List<UserVmJoinVO> userVms = getVmsWithAccount(accountId);
         for (UserVmJoinVO vm : userVms) {
-            cputotal += Long.valueOf(vm.getCpu());
+            cputotal += vm.getCpu();
         }
         return cputotal;
     }
 
     public long calculateMemoryForAccount(long accountId) {
         long ramtotal = 0;
-        // user vms
-        SearchBuilder<UserVmJoinVO> userVmSearch = _userVmJoinDao.createSearchBuilder();
-        userVmSearch.and("accountId", userVmSearch.entity().getAccountId(), Op.EQ);
-        userVmSearch.and("state", userVmSearch.entity().getState(), SearchCriteria.Op.NIN);
-        userVmSearch.and("displayVm", userVmSearch.entity().isDisplayVm(), Op.EQ);
-        userVmSearch.groupBy(userVmSearch.entity().getId()); // select distinct
-        userVmSearch.done();
-
-        SearchCriteria<UserVmJoinVO> sc1 = userVmSearch.create();
-        sc1.setParameters("accountId", accountId);
-        if (VirtualMachineManager.ResourceCountRunningVMsonly.value())
-            sc1.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging, State.Stopped});
-        else
-            sc1.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
-        sc1.setParameters("displayVm", 1);
-        List<UserVmJoinVO> userVms = _userVmJoinDao.search(sc1,null);
+        List<UserVmJoinVO> userVms = getVmsWithAccount(accountId);
         for (UserVmJoinVO vm : userVms) {
-            ramtotal += Long.valueOf(vm.getRamSize());
+            ramtotal += vm.getRamSize();
         }
         return ramtotal;
     }
@@ -1099,9 +1394,22 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         }
     }
 
+    protected long calculatePrimaryStorageForAccount(long accountId, String tag) {
+        if (StringUtils.isEmpty(tag)) {
+            List<Long> virtualRouters = _vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId);
+            return _volumeDao.primaryStorageUsedForAccount(accountId, virtualRouters);
+        }
+        long storage = 0;
+        List<VolumeVO> volumes = getVolumesWithAccountAndTag(accountId, tag);
+        for (VolumeVO volume : volumes) {
+            storage += volume.getSize() == null ? 0L : volume.getSize();
+        }
+        return storage;
+    }
+
     @Override
-    public long getResourceCount(Account account, ResourceType type) {
-        return _resourceCountDao.getResourceCount(account.getId(), ResourceOwnerType.Account, type);
+    public long getResourceCount(Account account, ResourceType type, String tag) {
+        return _resourceCountDao.getResourceCount(account.getId(), ResourceOwnerType.Account, type, tag);
     }
 
     private boolean isDisplayFlagOn(Boolean displayResource) {
@@ -1152,11 +1460,367 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     }
 
     @Override
-    public ResourceReservation getReservation(final Account account, final Boolean displayResource, final Resource.ResourceType type, final Long delta) throws ResourceAllocationException {
-        if (! Boolean.FALSE.equals(displayResource)) {
-            return new CheckedReservation(account, type, delta, reservationDao, resourceLimitService);
+    public List<String> getResourceLimitHostTags() {
+        if (StringUtils.isEmpty(ResourceLimitService.ResourceLimitHostTags.value())) {
+            return new ArrayList<>();
+        }
+        return Stream.of(ResourceLimitService.ResourceLimitHostTags.value().split(","))
+                .map(String::trim)
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public List<String> getResourceLimitStorageTags() {
+        if (StringUtils.isEmpty(ResourceLimitService.ResourceLimitStorageTags.value())) {
+            return new ArrayList<>();
+        }
+        return Arrays.asList(ResourceLimitService.ResourceLimitStorageTags.value().split(","));
+    }
+
+    protected TaggedResourceLimitAndCountResponse getTaggedResourceLimitAndCountResponse(Account account,
+         Domain domain, ResourceOwnerType ownerType, ResourceType type, String tag) {
+        Long limit = ResourceOwnerType.Account.equals(ownerType) ?
+                findCorrectResourceLimitForAccount(account, type, tag) :
+                findCorrectResourceLimitForDomain(domain, type, tag);
+        Long count = 0L;
+        ResourceCountVO countVO = _resourceCountDao.findByOwnerAndTypeAndTag(
+                ResourceOwnerType.Account.equals(ownerType) ? account.getId() : domain.getId(), ownerType, type, tag);
+        if (countVO != null) {
+            count = countVO.getCount();
+        }
+        TaggedResourceLimitAndCountResponse taggedResourceLimitAndCountResponse = new TaggedResourceLimitAndCountResponse();
+        taggedResourceLimitAndCountResponse.setResourceType(type);
+        taggedResourceLimitAndCountResponse.setTag(tag);
+        taggedResourceLimitAndCountResponse.setLimit(limit);
+        taggedResourceLimitAndCountResponse.setTotal(count);
+        taggedResourceLimitAndCountResponse.setAvailable(limit == Resource.RESOURCE_UNLIMITED ? Resource.RESOURCE_UNLIMITED : (limit - count));
+        return taggedResourceLimitAndCountResponse;
+    }
+
+    protected void updateTaggedResourceLimitsAndCounts(String uuid, ResourceOwnerType ownerType, List<String> hostTags,
+           List<String> storageTags, ResourceLimitAndCountResponse response) {
+        Account account = null;
+        if (ResourceOwnerType.Account.equals(ownerType)) {
+            account = _accountDao.findByUuid(uuid);
+        }
+        Domain domain = null;
+        if (ResourceOwnerType.Domain.equals(ownerType)) {
+            domain = _domainDao.findByUuid(uuid);
+        }
+        List<TaggedResourceLimitAndCountResponse> taggedResponses = new ArrayList<>();
+        for (String tag : hostTags) {
+            for (ResourceType type : HostTagsSupportingTypes) {
+                taggedResponses.add(getTaggedResourceLimitAndCountResponse(account, domain, ownerType, type, tag));
+            }
+        }
+        for (String tag : storageTags) {
+            for (ResourceType type : StorageTagsSupportingTypes) {
+                taggedResponses.add(getTaggedResourceLimitAndCountResponse(account, domain, ownerType, type, tag));
+            }
+        }
+        response.setTaggedResourceLimitsAndCounts(taggedResponses);
+    }
+
+    protected void updateTaggedResourceLimitsAndCountsForAccountsOrDomains(List<AccountResponse> accountResponses, List<DomainResponse> domainResponses, String tag) {
+        List<String> hostTags = new ArrayList<>(getResourceLimitHostTags());
+        List<String> storageTags = new ArrayList<>(getResourceLimitStorageTags());
+        if (StringUtils.isNotEmpty(tag)) {
+            hostTags.retainAll(List.of(tag));
+            storageTags.retainAll(List.of(tag));
+        }
+        if (CollectionUtils.isEmpty(hostTags) && CollectionUtils.isEmpty(storageTags)) {
+            return;
+        }
+        if (CollectionUtils.isNotEmpty(accountResponses)) {
+            for (AccountResponse response : accountResponses) {
+                updateTaggedResourceLimitsAndCounts(response.getObjectId(), ResourceOwnerType.Account, hostTags, storageTags, response);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(domainResponses)) {
+            for (DomainResponse response : domainResponses) {
+                updateTaggedResourceLimitsAndCounts(response.getId(), ResourceOwnerType.Domain, hostTags, storageTags, response);
+            }
+        }
+    }
+
+    @Override
+    public void updateTaggedResourceLimitsAndCountsForAccounts(List<AccountResponse> responses, String tag) {
+        updateTaggedResourceLimitsAndCountsForAccountsOrDomains(responses, null, tag);
+    }
+
+    @Override
+    public void updateTaggedResourceLimitsAndCountsForDomains(List<DomainResponse> responses, String tag) {
+        updateTaggedResourceLimitsAndCountsForAccountsOrDomains(null, responses, tag);
+    }
+
+    @Override
+    public List<String> getResourceLimitHostTags(ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        if (StringUtils.isEmpty(serviceOffering.getHostTag()) && StringUtils.isEmpty(template.getTemplateTag())) {
+            return new ArrayList<>();
+        }
+        List<String> resourceLimitTagsFromConfig = getResourceLimitHostTags();
+        if (CollectionUtils.isEmpty(resourceLimitTagsFromConfig)) {
+            return new ArrayList<>();
+        }
+        List<String> tags = new ArrayList<>();
+        if (StringUtils.isNotEmpty(serviceOffering.getHostTag())) {
+            List<String> offeringTags = com.cloud.utils.StringUtils.csvTagsToList(serviceOffering.getHostTag());
+            for (String tag : offeringTags) {
+                if (StringUtils.isNotEmpty(tag) && resourceLimitTagsFromConfig.contains(tag)) {
+                    tags.add(tag);
+                }
+            }
+        }
+        if (StringUtils.isNotEmpty(template.getTemplateTag())
+                && resourceLimitTagsFromConfig.contains(template.getTemplateTag())
+                && !tags.contains(template.getTemplateTag())) {
+            tags.add(template.getTemplateTag());
+        }
+        return tags;
+    }
+
+    @Override
+    public List<String> getResourceLimitStorageTags(DiskOffering diskOffering) {
+        if (diskOffering == null || StringUtils.isEmpty(diskOffering.getTags())) {
+            return new ArrayList<>();
+        }
+        List<String> resourceLimitTagsFromConfig = getResourceLimitStorageTags();
+        if (CollectionUtils.isEmpty(resourceLimitTagsFromConfig)) {
+            return new ArrayList<>();
+        }
+        String[] offeringTags = diskOffering.getTagsArray();
+        List<String> tags = new ArrayList<>();
+        for (String tag : offeringTags) {
+            if (StringUtils.isNotEmpty(tag) && resourceLimitTagsFromConfig.contains(tag)) {
+                tags.add(tag);
+            }
+        }
+        return tags;
+    }
+
+    protected List<String> getResourceLimitStorageTagsForResourceCountOperation(Boolean display, DiskOffering diskOffering) {
+        if (Boolean.FALSE.equals(display)) {
+            return new ArrayList<>();
+        }
+        List<String> tags = getResourceLimitStorageTags(diskOffering);
+        if (tags.isEmpty()) {
+            tags.add(null);
+        } else {
+            tags.add(0, null);
+        }
+        return tags;
+    }
+
+    @Override
+    public void checkVolumeResourceLimit(Account owner, Boolean display, Long size, DiskOffering diskOffering) throws ResourceAllocationException {
+        List<String> tags = getResourceLimitStorageTagsForResourceCountOperation(display, diskOffering);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        for (String tag : tags) {
+            checkResourceLimitWithTag(owner, ResourceType.volume, tag);
+            if (size != null) {
+                checkResourceLimitWithTag(owner, ResourceType.primary_storage, tag, size);
+            }
+        }
+    }
+
+    @Override
+    public void incrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering) {
+        List<String> tags = getResourceLimitStorageTagsForResourceCountOperation(display, diskOffering);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        for (String tag : tags) {
+            incrementResourceCountWithTag(accountId, ResourceType.volume, tag);
+            if (size != null) {
+                incrementResourceCountWithTag(accountId, ResourceType.primary_storage, tag, size);
+            }
+        }
+    }
+
+    @Override
+    public void decrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering) {
+        List<String> tags = getResourceLimitStorageTagsForResourceCountOperation(display, diskOffering);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        for (String tag : tags) {
+            decrementResourceCountWithTag(accountId, ResourceType.volume, tag);
+            if (size != null) {
+                decrementResourceCountWithTag(accountId, ResourceType.primary_storage, tag, size);
+            }
+        }
+    }
+
+    @Override
+    public void incrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering) {
+        if (size == null) {
+            return;
+        }
+        List<String> tags = getResourceLimitStorageTagsForResourceCountOperation(display, diskOffering);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        for (String tag : tags) {
+            incrementResourceCountWithTag(accountId, ResourceType.primary_storage, tag, size);
+        }
+    }
+
+    @Override
+    public void decrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering) {
+        if (size == null) {
+            return;
+        }
+        List<String> tags = getResourceLimitStorageTagsForResourceCountOperation(display, diskOffering);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        for (String tag : tags) {
+            decrementResourceCountWithTag(accountId, ResourceType.primary_storage, tag, size);
+        }
+    }
+
+    protected List<String> getResourceLimitHostTagsForResourceCountOperation(Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        if (Boolean.FALSE.equals(display)) {
+            return new ArrayList<>();
+        }
+        List<String> tags = getResourceLimitHostTags(serviceOffering, template);
+        if (tags.isEmpty()) {
+            tags.add(null);
+        } else {
+            tags.add(0, null);
+        }
+        return tags;
+    }
+
+    @Override
+    public void checkVmResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template) throws ResourceAllocationException {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        Long cpu = serviceOffering.getCpu() != null ? Long.valueOf(serviceOffering.getCpu()) : 0L;
+        Long ram = serviceOffering.getRamSize() != null ? Long.valueOf(serviceOffering.getRamSize()) : 0L;
+        for (String tag : tags) {
+            checkResourceLimitWithTag(owner, ResourceType.user_vm, tag);
+            checkResourceLimitWithTag(owner, ResourceType.cpu, tag, cpu);
+            checkResourceLimitWithTag(owner, ResourceType.memory, tag, ram);
+        }
+    }
+
+    @Override
+    public void incrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        Long cpu = serviceOffering.getCpu() != null ? Long.valueOf(serviceOffering.getCpu()) : 0L;
+        Long ram = serviceOffering.getRamSize() != null ? Long.valueOf(serviceOffering.getRamSize()) : 0L;
+        for (String tag : tags) {
+            incrementResourceCountWithTag(accountId, ResourceType.user_vm, tag);
+            incrementResourceCountWithTag(accountId, ResourceType.cpu, tag, cpu);
+            incrementResourceCountWithTag(accountId, ResourceType.memory, tag, ram);
+        }
+    }
+
+    @Override
+    public void decrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        Long cpu = serviceOffering.getCpu() != null ? Long.valueOf(serviceOffering.getCpu()) : 0L;
+        Long ram = serviceOffering.getRamSize() != null ? Long.valueOf(serviceOffering.getRamSize()) : 0L;
+        for (String tag : tags) {
+            decrementResourceCountWithTag(accountId, ResourceType.user_vm, tag);
+            decrementResourceCountWithTag(accountId, ResourceType.cpu, tag, cpu);
+            decrementResourceCountWithTag(accountId, ResourceType.memory, tag, ram);
+        }
+    }
+
+    @Override
+    public void checkVmCpuResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu) throws ResourceAllocationException {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        if (cpu == null) {
+            cpu = serviceOffering.getCpu() != null ? Long.valueOf(serviceOffering.getCpu()) : 0L;
+        }
+        for (String tag : tags) {
+            checkResourceLimitWithTag(owner, ResourceType.cpu, tag, cpu);
+        }
+    }
+
+    @Override
+    public void incrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu) {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        if (cpu == null) {
+            cpu = serviceOffering.getCpu() != null ? Long.valueOf(serviceOffering.getCpu()) : 0L;
+        }
+        for (String tag : tags) {
+            incrementResourceCountWithTag(accountId, ResourceType.cpu, tag, cpu);
+        }
+    }
+
+    @Override
+    public void decrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu) {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        if (cpu == null) {
+            cpu = serviceOffering.getCpu() != null ? Long.valueOf(serviceOffering.getCpu()) : 0L;
+        }
+        for (String tag : tags) {
+            decrementResourceCountWithTag(accountId, ResourceType.cpu, tag, cpu);
+        }
+    }
+
+    @Override
+    public void checkVmMemoryResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory) throws ResourceAllocationException {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        if (memory == null) {
+            memory = serviceOffering.getRamSize() != null ? Long.valueOf(serviceOffering.getRamSize()) : 0L;
+        }
+        for (String tag : tags) {
+            checkResourceLimitWithTag(owner, ResourceType.memory, tag, memory);
+        }
+    }
+
+    @Override
+    public void incrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory) {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        if (memory == null) {
+            memory = serviceOffering.getRamSize() != null ? Long.valueOf(serviceOffering.getRamSize()) : 0L;
+        }
+        for (String tag : tags) {
+            incrementResourceCountWithTag(accountId, ResourceType.memory, tag, memory);
+        }
+    }
+
+    @Override
+    public void decrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory) {
+        List<String> tags = getResourceLimitHostTagsForResourceCountOperation(display, serviceOffering, template);
+        if (CollectionUtils.isEmpty(tags)) {
+            return;
+        }
+        if (memory == null) {
+            memory = serviceOffering.getRamSize() != null ? Long.valueOf(serviceOffering.getRamSize()) : 0L;
+        }
+        for (String tag : tags) {
+            decrementResourceCountWithTag(accountId, ResourceType.memory, tag, memory);
         }
-        throw new CloudRuntimeException("no reservation needed for resources that display as false");
     }
 
     @Override
@@ -1166,7 +1830,13 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
 
     @Override
     public ConfigKey<?>[] getConfigKeys() {
-        return new ConfigKey<?>[] {ResourceCountCheckInterval, MaxAccountSecondaryStorage, MaxProjectSecondaryStorage};
+        return new ConfigKey<?>[] {
+                ResourceCountCheckInterval,
+                MaxAccountSecondaryStorage,
+                MaxProjectSecondaryStorage,
+                ResourceLimitHostTags,
+                ResourceLimitStorageTags
+        };
     }
 
     protected class ResourceCountCheckTask extends ManagedContextRunnable {
@@ -1215,37 +1885,30 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
                 // initialize accounts as empty list to do best effort recalculation
                 accounts = new ArrayList<>();
             }
+            // try/catch task, otherwise it won't be rescheduled in case of exception
+            try {
+                removeResourceLimitAndCountForNonMatchingTags(null, null, getResourceLimitHostTags(), getResourceLimitStorageTags());
+            } catch (Exception e) {
+                logger.warn("Failure in resource counters recalculation periodic task, unable to clear undesired tagged limits and counts", e);
+            }
 
             for (ResourceType type : ResourceType.values()) {
                 if (CollectionUtils.isEmpty(domains)) {
-                    recalculateDomainResourceCountInContext(Domain.ROOT_DOMAIN, type);
+                    recalculateDomainResourceCount(Domain.ROOT_DOMAIN, type, null);
+                    recalculateDomainTaggedResourceCount(Domain.ROOT_DOMAIN, type, getResourceLimitHostTags(), getResourceLimitStorageTags());
                 } else {
                     for (Domain domain : domains) {
-                        recalculateDomainResourceCount(domain.getId(), type);
+                        recalculateDomainResourceCount(domain.getId(), type, null);
+                        recalculateDomainTaggedResourceCount(domain.getId(), type, getResourceLimitHostTags(), getResourceLimitStorageTags());
                     }
                 }
-
                 // run through the accounts in the root domain
                 for (AccountVO account : accounts) {
-                    recalculateAccountResourceCountInContext(account.getId(), type);
+                    recalculateAccountResourceCount(account.getId(), type, null);
+                    recalculateAccountTaggedResourceCount(account.getId(), type, getResourceLimitHostTags(), getResourceLimitStorageTags());
                 }
             }
             logger.info("Finished resource counters recalculation periodic task.");
         }
-
-        private void recalculateDomainResourceCountInContext(long domainId, ResourceType type) {
-            try {
-                recalculateDomainResourceCount(domainId, type);
-            } catch (Exception e) {
-                logger.warn("Resource counters recalculation periodic task failed for the domain " + domainId + " and the resource type " + type + " .", e);
-            }
-        }
-        private void recalculateAccountResourceCountInContext(long accountId, ResourceType type) {
-            try {
-                recalculateAccountResourceCount(accountId, type);
-            } catch (Exception e) {
-                logger.warn("Resource counters recalculation periodic task failed for the account " + accountId + " and the resource type " + type + " .", e);
-            }
-        }
     }
 }
diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java
index baa59954bb6..c23d23f7231 100644
--- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java
@@ -43,8 +43,6 @@ import javax.crypto.spec.SecretKeySpec;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import com.cloud.network.dao.PublicIpQuarantineDao;
-import com.cloud.hypervisor.HypervisorGuru;
 import org.apache.cloudstack.acl.ControlledEntity;
 import org.apache.cloudstack.acl.SecurityChecker;
 import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -225,8 +223,8 @@ import org.apache.cloudstack.api.command.admin.storage.ListSecondaryStagingStore
 import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
 import org.apache.cloudstack.api.command.admin.storage.ListStorageProvidersCmd;
 import org.apache.cloudstack.api.command.admin.storage.ListStorageTagsCmd;
-import org.apache.cloudstack.api.command.admin.storage.MigrateSecondaryStorageDataCmd;
 import org.apache.cloudstack.api.command.admin.storage.MigrateResourcesToAnotherSecondaryStorageCmd;
+import org.apache.cloudstack.api.command.admin.storage.MigrateSecondaryStorageDataCmd;
 import org.apache.cloudstack.api.command.admin.storage.PreparePrimaryStorageForMaintenanceCmd;
 import org.apache.cloudstack.api.command.admin.storage.SyncStoragePoolCmd;
 import org.apache.cloudstack.api.command.admin.storage.UpdateCloudToUseObjectStoreCmd;
@@ -716,6 +714,7 @@ import com.cloud.host.dao.HostTagsDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.HypervisorCapabilities;
 import com.cloud.hypervisor.HypervisorCapabilitiesVO;
+import com.cloud.hypervisor.HypervisorGuru;
 import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
 import com.cloud.hypervisor.kvm.dpdk.DpdkHelper;
 import com.cloud.info.ConsoleProxyInfo;
@@ -735,6 +734,7 @@ import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkDomainDao;
 import com.cloud.network.dao.NetworkDomainVO;
 import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.dao.PublicIpQuarantineDao;
 import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.org.Cluster;
 import com.cloud.org.Grouping.AllocationState;
@@ -766,6 +766,7 @@ import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.GuestOSCategoryDao;
 import com.cloud.storage.dao.GuestOSDao;
 import com.cloud.storage.dao.GuestOSHypervisorDao;
+import com.cloud.storage.dao.StoragePoolTagsDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.secondary.SecondaryStorageVmManager;
@@ -775,6 +776,7 @@ import com.cloud.template.TemplateManager;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountService;
+import com.cloud.user.ResourceLimitService;
 import com.cloud.user.SSHKeyPair;
 import com.cloud.user.SSHKeyPairVO;
 import com.cloud.user.User;
@@ -994,10 +996,20 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
     protected AnnotationDao annotationDao;
     @Inject
     UserDataManager userDataManager;
+    @Inject
+    StoragePoolTagsDao storagePoolTagsDao;
 
     @Inject
     private PublicIpQuarantineDao publicIpQuarantineDao;
 
+    @Inject
+    ClusterManager _clusterMgr;
+
+    @Inject
+    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
+    @Inject
+    ResourceLimitService resourceLimitService;
+
     private LockControllerListener _lockControllerListener;
     private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker"));
     private final ScheduledExecutorService _alertExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AlertChecker"));
@@ -1024,12 +1036,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         _planners = planners;
     }
 
-    @Inject
-    ClusterManager _clusterMgr;
-
-    @Inject
-    protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
-
     protected List<AffinityGroupProcessor> _affinityProcessors;
 
     public List<AffinityGroupProcessor> getAffinityGroupProcessors() {
@@ -3198,6 +3204,77 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         return result;
     }
 
+    Pair<Boolean, List<Long>> getHostIdsForCapacityListing(Long zoneId, Long podId, Long clusterId, Integer capacityType, String tag) {
+        if (StringUtils.isEmpty(tag)) {
+            return new Pair<>(true, null);
+        }
+        Short type = capacityType == null ? null : capacityType.shortValue();
+        if (type != null && Capacity.STORAGE_CAPACITY_TYPES.contains(type)) {
+            return new Pair<>(false, null);
+        }
+        List<Long> hostIds = null;
+        try {
+            List<HostVO> hosts = _hostDao.listByHostTag(Type.Routing, clusterId, podId, zoneId, tag);
+            hostIds = hosts.stream().map(HostVO::getId).collect(Collectors.toList());
+        } catch (CloudRuntimeException ignored) {}
+        return new Pair<>(CollectionUtils.isNotEmpty(hostIds), hostIds);
+    }
+
+    protected List<String> getResourceLimitTagsForCapacityListing() {
+        List<String> tags = new ArrayList<>();
+        tags.add(null);
+        tags.addAll(resourceLimitService.getResourceLimitHostTags());
+        tags.addAll(resourceLimitService.getResourceLimitStorageTags());
+        tags = tags.stream().distinct().collect(Collectors.toList());
+        return tags;
+    }
+
+    protected Pair<Boolean, List<Long>> getStoragePoolIdsForCapacityListing(Integer capacityType, String tag) {
+        if (StringUtils.isEmpty(tag)) {
+            return new Pair<>(true, null);
+        }
+        Short type = capacityType == null ? null : capacityType.shortValue();
+        if (type != null && !Capacity.STORAGE_CAPACITY_TYPES.contains(type)) {
+            return new Pair<>(false, null);
+        }
+        List<Long> storagePoolIds = storagePoolTagsDao.listPoolIdsByTag(tag);
+        return new Pair<>(CollectionUtils.isNotEmpty(storagePoolIds), storagePoolIds);
+    }
+
+    protected List<SummedCapacity> getCapacitiesWithDetails(final Long zoneId, final Long podId, Long clusterId,
+            final Integer capacityType, final String tag, int level, Long pageSize) {
+        List<String> tags = new ArrayList<>();
+        if (StringUtils.isNotEmpty(tag)) {
+            tags.add(tag);
+        } else {
+            tags = getResourceLimitTagsForCapacityListing();
+        }
+        List<SummedCapacity> summedCapacities = new ArrayList<>();
+        for (String t : tags) {
+            List<SummedCapacity> taggedSummedCapacities = new ArrayList<>();
+            Pair<Boolean, List<Long>> hostIdsForCapacity = getHostIdsForCapacityListing(zoneId, podId, clusterId, capacityType, t);
+            Pair<Boolean, List<Long>> storagePoolIdsForCapacity = getStoragePoolIdsForCapacityListing(capacityType, t);
+            if (hostIdsForCapacity.first() || storagePoolIdsForCapacity.first()) {
+                final List<SummedCapacity> summedHostCapacities = _capacityDao.listCapacitiesGroupedByLevelAndType(
+                        capacityType, zoneId, podId, clusterId, level, hostIdsForCapacity.second(),
+                        storagePoolIdsForCapacity.second(), pageSize);
+                if (summedHostCapacities != null) {
+                    taggedSummedCapacities.addAll(summedHostCapacities);
+                }
+            }
+            if (storagePoolIdsForCapacity.first()) {
+                List<SummedCapacity> summedStorageCapacities = getStorageCapacities(clusterId, podId, zoneId,
+                        storagePoolIdsForCapacity.second(), capacityType == null ? null : capacityType.shortValue());
+                if (summedStorageCapacities != null) {
+                    taggedSummedCapacities.addAll(summedStorageCapacities);
+                }
+            }
+            taggedSummedCapacities.forEach(x -> x.setTag(t));
+            summedCapacities.addAll(taggedSummedCapacities);
+        }
+        return summedCapacities;
+    }
+
     @Override
     public List<CapacityVO> listTopConsumedResources(final ListCapacityCmd cmd) {
 
@@ -3206,53 +3283,37 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         final Long podId = cmd.getPodId();
         final Long clusterId = cmd.getClusterId();
         final Boolean fetchLatest = cmd.getFetchLatest();
+        final String tag = cmd.getTag();
 
         if (clusterId != null) {
-            throw new InvalidParameterValueException("Currently clusterId param is not suppoerted");
+            throw new InvalidParameterValueException("Currently clusterId param is not supported");
         }
         zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
 
         if (fetchLatest != null && fetchLatest) {
             _alertMgr.recalculateCapacity();
         }
-        List<SummedCapacity> summedCapacities = new ArrayList<SummedCapacity>();
 
+        int level = 3;
         if (zoneId == null && podId == null) {// Group by Zone, capacity type
-            final List<SummedCapacity> summedCapacitiesAtZone = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 1, cmd.getPageSizeVal());
-            if (summedCapacitiesAtZone != null) {
-                summedCapacities.addAll(summedCapacitiesAtZone);
-            }
+            level = 1;
         } else if (podId == null) {// Group by Pod, capacity type
-            final List<SummedCapacity> summedCapacitiesAtPod = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 2, cmd.getPageSizeVal());
-            if (summedCapacitiesAtPod != null) {
-                summedCapacities.addAll(summedCapacitiesAtPod);
-            }
-        } else { // Group by Cluster, capacity type
-            final List<SummedCapacity> summedCapacitiesAtCluster = _capacityDao.listCapacitiesGroupedByLevelAndType(capacityType, zoneId, podId, clusterId, 3, cmd.getPageSizeVal());
-            if (summedCapacitiesAtCluster != null) {
-                summedCapacities.addAll(summedCapacitiesAtCluster);
-            }
+            level = 2;
         }
 
-        List<SummedCapacity> summedCapacitiesForSecStorage = getStorageUsed(clusterId, podId, zoneId, capacityType);
-        if (summedCapacitiesForSecStorage != null) {
-            summedCapacities.addAll(summedCapacitiesForSecStorage);
-        }
+        final List<CapacityVO> capacities = new ArrayList<>();
+        List<SummedCapacity> summedCapacities = getCapacitiesWithDetails(zoneId, podId, clusterId, capacityType, tag, level, cmd.getPageSizeVal());
 
         // Sort Capacities
-        Collections.sort(summedCapacities, new Comparator<SummedCapacity>() {
-            @Override
-            public int compare(final SummedCapacity arg0, final SummedCapacity arg1) {
-                if (arg0.getPercentUsed() < arg1.getPercentUsed()) {
-                    return 1;
-                } else if (arg0.getPercentUsed().equals(arg1.getPercentUsed())) {
-                    return 0;
-                }
-                return -1;
+        summedCapacities.sort((arg0, arg1) -> {
+            if (arg0.getPercentUsed() < arg1.getPercentUsed()) {
+                return 1;
+            } else if (arg0.getPercentUsed().equals(arg1.getPercentUsed())) {
+                return 0;
             }
+            return -1;
         });
 
-        final List<CapacityVO> capacities = new ArrayList<CapacityVO>();
 
         Integer pageSize = null;
         try {
@@ -3267,53 +3328,104 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
                     summedCapacity.getPercentUsed());
             capacity.setUsedCapacity(summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity());
             capacity.setTotalCapacity(summedCapacity.getTotalCapacity());
+            capacity.setTag(summedCapacity.getTag());
             capacities.add(capacity);
         }
         return capacities;
     }
 
-    List<SummedCapacity> getStorageUsed(Long clusterId, Long podId, Long zoneId, Integer capacityType) {
-        if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
-            final List<SummedCapacity> list = new ArrayList<SummedCapacity>();
-            if (zoneId != null) {
-                final DataCenterVO zone = ApiDBUtils.findZoneById(zoneId);
-                if (zone == null || zone.getAllocationState() == AllocationState.Disabled) {
-                    return null;
+    List<SummedCapacity> getStorageCapacities(Long clusterId, Long podId, Long zoneId, List<Long> poolIds, Short capacityType) {
+        List<Short> capacityTypes = Arrays.asList(Capacity.CAPACITY_TYPE_STORAGE, Capacity.CAPACITY_TYPE_SECONDARY_STORAGE);
+        if (capacityType != null && !capacityTypes.contains(capacityType)) {
+            return null;
+        }
+        if (capacityType != null) {
+            capacityTypes = capacityTypes.stream().filter(x -> x.equals(capacityType)).collect(Collectors.toList());
+        }
+        if (CollectionUtils.isNotEmpty(poolIds)) {
+            capacityTypes = capacityTypes.stream().filter(x -> x != Capacity.CAPACITY_TYPE_SECONDARY_STORAGE).collect(Collectors.toList());
+        }
+        if (CollectionUtils.isEmpty(capacityTypes)) {
+            return null;
+        }
+        final List<SummedCapacity> list = new ArrayList<>();
+        List<DataCenterVO> dcList = new ArrayList<>();
+        if (zoneId != null) {
+            final DataCenterVO zone = ApiDBUtils.findZoneById(zoneId);
+            if (zone == null || zone.getAllocationState() == AllocationState.Disabled) {
+                return null;
+            }
+            dcList.add(zone);
+        } else {
+            dcList = _dcDao.listEnabledZones();
+            podId = null;
+            clusterId = null;
+        }
+        for (DataCenterVO dc : dcList) {
+            List<CapacityVO> capacities = new ArrayList<>();
+            if (capacityTypes.contains(Capacity.CAPACITY_TYPE_SECONDARY_STORAGE)) {
+                capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, dc.getId()));
+            }
+            if (capacityTypes.contains(Capacity.CAPACITY_TYPE_STORAGE)) {
+                capacities.add(_storageMgr.getStoragePoolUsedStats(dc.getId(), podId, clusterId, poolIds));
+            }
+            for (CapacityVO capacity : capacities) {
+                if (capacity.getTotalCapacity() != 0) {
+                    capacity.setUsedPercentage((float)capacity.getUsedCapacity() / capacity.getTotalCapacity());
+                } else {
+                    capacity.setUsedPercentage(0);
                 }
-                List<CapacityVO> capacities = new ArrayList<CapacityVO>();
-                capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
-                capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
-                for (CapacityVO capacity : capacities) {
-                    if (capacity.getTotalCapacity() != 0) {
-                        capacity.setUsedPercentage((float)capacity.getUsedCapacity() / capacity.getTotalCapacity());
-                    } else {
-                        capacity.setUsedPercentage(0);
-                    }
-                    final SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(),
-                            capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
-                    list.add(summedCapacity);
+                SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(),
+                        capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
+                list.add(summedCapacity);
+            }
+        }// End of for
+        return list;
+    }
+
+
+    protected List<CapacityVO> listCapacitiesWithDetails(final Long zoneId, final Long podId, Long clusterId,
+             final Integer capacityType, final String tag, List<Long> dcList) {
+        List<String> tags = new ArrayList<>();
+        if (StringUtils.isNotEmpty(tag)) {
+            tags.add(tag);
+        } else {
+            tags = getResourceLimitTagsForCapacityListing();
+        }
+        List<CapacityVO> capacities = new ArrayList<>();
+        for (String t : tags) {
+            List<CapacityVO> taggedCapacities = new ArrayList<>();
+            Pair<Boolean, List<Long>> hostIdsForCapacity = getHostIdsForCapacityListing(zoneId, podId, clusterId, capacityType, t);
+            Pair<Boolean, List<Long>> storagePoolIdsForCapacity = getStoragePoolIdsForCapacityListing(capacityType, t);
+            if (hostIdsForCapacity.first() || storagePoolIdsForCapacity.first()) {
+                final List<SummedCapacity> summedCapacities = _capacityDao.findFilteredCapacityBy(capacityType,
+                        zoneId, podId, clusterId, hostIdsForCapacity.second(), storagePoolIdsForCapacity.second());
+
+                for (final SummedCapacity summedCapacity : summedCapacities) {
+                    final CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), summedCapacity.getPodId(), summedCapacity.getClusterId(),
+                            summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(), summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
+                    capacity.setAllocatedCapacity(summedCapacity.getAllocatedCapacity());
+                    taggedCapacities.add(capacity);
+                }
+            }
+            for (final Long zId : dcList) {
+                // op_host_Capacity contains only allocated stats and the real time
+                // stats are stored "in memory".
+                // List secondary storage capacity only when the api is invoked for the zone layer.
+                if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) &&
+                        podId == null && clusterId == null &&
+                        StringUtils.isEmpty(t)) {
+                    taggedCapacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zId));
+                }
+                if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) && storagePoolIdsForCapacity.first()) {
+                    taggedCapacities.add(_storageMgr.getStoragePoolUsedStats(zId, podId, clusterId, storagePoolIdsForCapacity.second()));
                 }
-            } else {
-                List<DataCenterVO> dcList = _dcDao.listEnabledZones();
-                for (DataCenterVO dc : dcList) {
-                    List<CapacityVO> capacities = new ArrayList<CapacityVO>();
-                    capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, dc.getId()));
-                    capacities.add(_storageMgr.getStoragePoolUsedStats(null, null, null, dc.getId()));
-                    for (CapacityVO capacity : capacities) {
-                        if (capacity.getTotalCapacity() != 0) {
-                            capacity.setUsedPercentage((float)capacity.getUsedCapacity() / capacity.getTotalCapacity());
-                        } else {
-                            capacity.setUsedPercentage(0);
-                        }
-                        SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(),
-                                capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
-                        list.add(summedCapacity);
-                    }
-                }// End of for
             }
-            return list;
+            taggedCapacities.forEach(x -> x.setTag(t));
+            capacities.addAll(taggedCapacities);
         }
-        return null;
+        return capacities;
+
     }
 
     @Override
@@ -3324,51 +3436,25 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         final Long podId = cmd.getPodId();
         final Long clusterId = cmd.getClusterId();
         final Boolean fetchLatest = cmd.getFetchLatest();
+        final String tag = cmd.getTag();
 
         zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
         if (fetchLatest != null && fetchLatest) {
             _alertMgr.recalculateCapacity();
         }
-
-        final List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
-        final List<CapacityVO> capacities = new ArrayList<CapacityVO>();
-
-        for (final SummedCapacity summedCapacity : summedCapacities) {
-            final CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), summedCapacity.getPodId(), summedCapacity.getClusterId(),
-                    summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(), summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
-            capacity.setAllocatedCapacity(summedCapacity.getAllocatedCapacity());
-            capacities.add(capacity);
-        }
-
-        // op_host_Capacity contains only allocated stats and the real time
-        // stats are stored "in memory".
-        // Show Sec. Storage only when the api is invoked for the zone layer.
-        List<DataCenterVO> dcList = new ArrayList<DataCenterVO>();
-        if (zoneId == null && podId == null && clusterId == null) {
-            dcList = ApiDBUtils.listZones();
-        } else if (zoneId != null) {
-            dcList.add(ApiDBUtils.findZoneById(zoneId));
+        List<Long> dcList = new ArrayList<>();
+        if (zoneId != null) {
+            dcList.add(zoneId);
         } else {
-            if (clusterId != null) {
-                zoneId = ApiDBUtils.findClusterById(clusterId).getDataCenterId();
-            } else {
-                zoneId = ApiDBUtils.findPodById(podId).getDataCenterId();
-            }
-            if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
-                capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
+            if (podId == null && clusterId == null) {
+                dcList.addAll(ApiDBUtils.listZones().stream().map(DataCenterVO::getId).collect(Collectors.toList()));
+            } if (clusterId != null) {
+                dcList.add(ApiDBUtils.findClusterById(clusterId).getDataCenterId());
+            } else if (podId != null) {
+                dcList.add(ApiDBUtils.findPodById(podId).getDataCenterId());
             }
         }
-
-        for (final DataCenterVO zone : dcList) {
-            zoneId = zone.getId();
-            if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
-                capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
-            }
-            if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
-                capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
-            }
-        }
-        return capacities;
+        return listCapacitiesWithDetails(zoneId, podId, clusterId, capacityType, tag, dcList);
     }
 
     @Override
diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
index c20baf990b4..a68acb543f9 100644
--- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
@@ -1600,7 +1600,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
                                 if (_serverId == host.getManagementServerId().longValue()) {
                                     volService.destroyVolume(volume.getId());
                                     // decrement volume resource count
-                                    _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplayVolume());
+                                    _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), volume.isDisplayVolume(),
+                                            null, _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()));
                                     // expunge volume from secondary if volume is on image store
                                     VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image);
                                     if (volOnSecondary != null) {
@@ -2414,25 +2415,24 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         return capacity;
     }
 
-    @Override
-    public CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId) {
+    private CapacityVO getStoragePoolUsedStatsInternal(Long zoneId, Long podId, Long clusterId, List<Long> poolIds, Long poolId) {
         SearchCriteria<StoragePoolVO> sc = _storagePoolDao.createSearchCriteria();
-        List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
+        List<StoragePoolVO> pools = new ArrayList<>();
 
         if (zoneId != null) {
             sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
         }
-
         if (podId != null) {
             sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
         }
-
         if (clusterId != null) {
             sc.addAnd("clusterId", SearchCriteria.Op.EQ, clusterId);
         }
-
+        if (CollectionUtils.isNotEmpty(poolIds)) {
+            sc.addAnd("id", SearchCriteria.Op.IN, poolIds.toArray());
+        }
         if (poolId != null) {
-            sc.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, poolId);
+            sc.addAnd("id", SearchCriteria.Op.EQ, poolId);
         }
         sc.addAnd("parent", SearchCriteria.Op.EQ, 0L);
         if (poolId != null) {
@@ -2442,8 +2442,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         }
 
         CapacityVO capacity = new CapacityVO(poolId, zoneId, podId, clusterId, 0, 0, Capacity.CAPACITY_TYPE_STORAGE);
-        for (StoragePoolVO PrimaryDataStoreVO : pools) {
-            StorageStats stats = ApiDBUtils.getStoragePoolStatistics(PrimaryDataStoreVO.getId());
+        for (StoragePoolVO pool : pools) {
+            StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
             if (stats == null) {
                 continue;
             }
@@ -2451,6 +2451,17 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
             capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity());
         }
         return capacity;
+
+    }
+
+    @Override
+    public CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId) {
+        return getStoragePoolUsedStatsInternal(zoneId, podId, clusterId, null, poolId);
+    }
+
+    @Override
+    public CapacityVO getStoragePoolUsedStats(Long zoneId, Long podId, Long clusterId, List<Long> poolIds) {
+        return getStoragePoolUsedStatsInternal(zoneId, podId, clusterId, poolIds, null);
     }
 
     @Override
@@ -2663,13 +2674,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         return 0;
     }
 
-    @Override
-    public boolean storagePoolHasEnoughIops(List<Pair<Volume, DiskProfile>> requestedVolumes, StoragePool pool) {
-        if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) {
-            logger.debug(String.format("Cannot check if storage [%s] has enough IOPS to allocate volumes [%s].", pool, requestedVolumes));
-            return false;
-        }
-
+    protected boolean checkIfPoolIopsCapacityNull(StoragePool pool) {
         // Only IOPS-guaranteed primary storage like SolidFire is using/setting IOPS.
         // This check returns true for storage that does not specify IOPS.
         if (pool.getCapacityIops() == null) {
@@ -2677,12 +2682,32 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
 
             return true;
         }
+        return false;
+    }
 
+    protected boolean storagePoolHasEnoughIops(long requestedIops, List<Pair<Volume, DiskProfile>> requestedVolumes, StoragePool pool, boolean skipPoolNullIopsCheck) {
+        if (!skipPoolNullIopsCheck && checkIfPoolIopsCapacityNull(pool)) {
+            return true;
+        }
         StoragePoolVO storagePoolVo = _storagePoolDao.findById(pool.getId());
         long currentIops = _capacityMgr.getUsedIops(storagePoolVo);
+        long futureIops = currentIops + requestedIops;
+        boolean hasEnoughIops = futureIops <= pool.getCapacityIops();
+        String hasCapacity = hasEnoughIops ? "has" : "does not have";
+        logger.debug(String.format("Pool [%s] %s enough IOPS to allocate volumes [%s].", pool, hasCapacity, requestedVolumes));
+        return hasEnoughIops;
+    }
 
+    @Override
+    public boolean storagePoolHasEnoughIops(List<Pair<Volume, DiskProfile>> requestedVolumes, StoragePool pool) {
+        if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) {
+            logger.debug(String.format("Cannot check if storage [%s] has enough IOPS to allocate volumes [%s].", pool, requestedVolumes));
+            return false;
+        }
+        if (checkIfPoolIopsCapacityNull(pool)) {
+            return true;
+        }
         long requestedIops = 0;
-
         for (Pair<Volume, DiskProfile> volumeDiskProfilePair : requestedVolumes) {
             Volume requestedVolume = volumeDiskProfilePair.first();
             DiskProfile diskProfile = volumeDiskProfilePair.second();
@@ -2695,12 +2720,28 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
                 requestedIops += minIops;
             }
         }
+        return storagePoolHasEnoughIops(requestedIops, requestedVolumes, pool, true);
+    }
 
-        long futureIops = currentIops + requestedIops;
-        boolean hasEnoughIops = futureIops <= pool.getCapacityIops();
-        String hasCapacity = hasEnoughIops ? "has" : "does not have";
-        logger.debug(String.format("Pool [%s] %s enough IOPS to allocate volumes [%s].", pool, hasCapacity, requestedVolumes));
-        return hasEnoughIops;
+    @Override
+    public boolean storagePoolHasEnoughIops(Long requestedIops, StoragePool pool) {
+        if (pool == null) {
+            return false;
+        }
+        if (requestedIops == null || requestedIops == 0) {
+            return true;
+        }
+        return storagePoolHasEnoughIops(requestedIops, new ArrayList<>(), pool, false);
+    }
+
+    @Override
+    public boolean storagePoolHasEnoughSpace(Long size, StoragePool pool) {
+        if (size == null || size == 0) {
+            return true;
+        }
+        final StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
+        long allocatedSizeWithTemplate = _capacityMgr.getAllocatedPoolCapacity(poolVO, null);
+        return checkPoolforSpace(pool, allocatedSizeWithTemplate, size);
     }
 
     @Override
@@ -2790,6 +2831,38 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         }
     }
 
+    protected Answer getCheckDatastorePolicyComplianceAnswer(String storagePolicyId, StoragePool pool) throws StorageUnavailableException {
+        if (StringUtils.isEmpty(storagePolicyId)) {
+            return null;
+        }
+        VsphereStoragePolicyVO storagePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyId));
+        List<Long> hostIds = getUpHostsInPool(pool.getId());
+        Collections.shuffle(hostIds);
+
+        if (CollectionUtils.isEmpty(hostIds)) {
+            throw new StorageUnavailableException("Unable to send command to the pool " + pool.getName() + " due to there is no enabled hosts up in this cluster", pool.getId());
+        }
+        try {
+            StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
+            CheckDataStoreStoragePolicyComplainceCommand cmd = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicyVO.getPolicyId(), storageFilerTO);
+            long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostIds.get(0), cmd);
+            return _agentMgr.send(targetHostId, cmd);
+        } catch (AgentUnavailableException e) {
+            logger.debug("Unable to send storage pool command to " + pool + " via " + hostIds.get(0), e);
+            throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
+        } catch (OperationTimedoutException e) {
+            logger.debug("Failed to process storage pool command to " + pool + " via " + hostIds.get(0), e);
+            throw new StorageUnavailableException("Failed to process storage command to the pool ", pool.getId());
+        }
+    }
+
+    @Override
+    public boolean isStoragePoolCompliantWithStoragePolicy(long diskOfferingId, StoragePool pool) throws StorageUnavailableException {
+        String storagePolicyId = _diskOfferingDetailsDao.getDetail(diskOfferingId, ApiConstants.STORAGE_POLICY);
+        Answer answer = getCheckDatastorePolicyComplianceAnswer(storagePolicyId, pool);
+        return answer == null || answer.getResult();
+    }
+
     @Override
     public boolean isStoragePoolCompliantWithStoragePolicy(List<Pair<Volume, DiskProfile>> volumes, StoragePool pool) throws StorageUnavailableException {
         if (CollectionUtils.isEmpty(volumes)) {
@@ -2810,27 +2883,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
             } else {
                 storagePolicyId = _diskOfferingDetailsDao.getDetail(diskProfile.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
             }
-            if (StringUtils.isNotEmpty(storagePolicyId)) {
-                VsphereStoragePolicyVO storagePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyId));
-                List<Long> hostIds = getUpHostsInPool(pool.getId());
-                Collections.shuffle(hostIds);
-
-                if (hostIds == null || hostIds.isEmpty()) {
-                    throw new StorageUnavailableException("Unable to send command to the pool " + pool.getName() + " due to there is no enabled hosts up in this cluster", pool.getId());
-                }
-                try {
-                    StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
-                    CheckDataStoreStoragePolicyComplainceCommand cmd = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicyVO.getPolicyId(), storageFilerTO);
-                    long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostIds.get(0), cmd);
-                    Answer answer = _agentMgr.send(targetHostId, cmd);
-                    answers.add(new Pair<>(volume, answer));
-                } catch (AgentUnavailableException e) {
-                    logger.debug("Unable to send storage pool command to " + pool + " via " + hostIds.get(0), e);
-                    throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
-                } catch (OperationTimedoutException e) {
-                    logger.debug("Failed to process storage pool command to " + pool + " via " + hostIds.get(0), e);
-                    throw new StorageUnavailableException("Failed to process storage command to the pool ", pool.getId());
-                }
+            Answer answer = getCheckDatastorePolicyComplianceAnswer(storagePolicyId, pool);
+            if (answer != null) {
+                answers.add(new Pair<>(volume, answer));
             }
         }
         // check cummilative result for all volumes
@@ -2843,7 +2898,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         return true;
     }
 
-    private boolean checkPoolforSpace(StoragePool pool, long allocatedSizeWithTemplate, long totalAskingSize) {
+    protected boolean checkPoolforSpace(StoragePool pool, long allocatedSizeWithTemplate, long totalAskingSize) {
         // allocated space includes templates
         StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
 
diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index 8597028f6c8..887bbc91d02 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -348,7 +348,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
     protected Gson _gson;
 
     private static final List<HypervisorType> SupportedHypervisorsForVolResize = Arrays.asList(HypervisorType.KVM, HypervisorType.XenServer,
-            HypervisorType.VMware, HypervisorType.Any, HypervisorType.None);
+            HypervisorType.VMware, HypervisorType.Simulator, HypervisorType.Any, HypervisorType.None);
     private List<StoragePoolAllocator> _storagePoolAllocators;
 
     private List<HypervisorType> supportingDefaultHV;
@@ -504,7 +504,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
                 Account account = _accountDao.findById(accountId);
                 Domain domain = domainDao.findById(account.getDomainId());
 
-                command.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
+                command.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage, null));
                 command.setAccountId(accountId);
                 Gson gson = new GsonBuilder().create();
                 String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
@@ -523,10 +523,14 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
 
         // permission check
         Account volumeOwner = _accountMgr.getActiveAccountById(ownerId);
+        DiskOfferingVO diskOffering = null;
+        if (diskOfferingId != null) {
+            diskOffering = _diskOfferingDao.findById(diskOfferingId);
+        }
         _accountMgr.checkAccess(caller, null, true, volumeOwner);
 
         // Check that the resource limit for volumes won't be exceeded
-        _resourceLimitMgr.checkResourceLimit(volumeOwner, ResourceType.volume);
+        _resourceLimitMgr.checkVolumeResourceLimit(volumeOwner, true, null, diskOffering);
 
         // Verify that zone exists
         DataCenterVO zone = _dcDao.findById(zoneId);
@@ -559,7 +563,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
 
         // Check that the disk offering specified is valid
         if (diskOfferingId != null) {
-            DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
             if ((diskOffering == null) || diskOffering.getRemoved() != null || diskOffering.isComputeOnly()) {
                 throw new InvalidParameterValueException("Please specify a valid disk offering.");
             }
@@ -649,7 +652,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
 
                 // Increment resource count during allocation; if actual creation fails,
                 // decrement it
-                _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.volume);
+                _resourceLimitMgr.incrementVolumeResourceCount(volume.getAccountId(), true, null, diskOfferingVO);
                 //url can be null incase of postupload
                 if (url != null) {
                     _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, UriUtils.getRemoteSize(url));
@@ -706,9 +709,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
             }
         }
 
-        // Check that the resource limit for volumes won't be exceeded
-        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.volume, displayVolume);
-
         Long zoneId = cmd.getZoneId();
         Long diskOfferingId = null;
         DiskOfferingVO diskOffering = null;
@@ -891,8 +891,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
 
         Storage.ProvisioningType provisioningType = diskOffering.getProvisioningType();
 
-        // Check that the resource limit for primary storage won't be exceeded
-        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.primary_storage, displayVolume, new Long(size));
+        // Check that the resource limit for volume & primary storage won't be exceeded
+        _resourceLimitMgr.checkVolumeResourceLimit(owner,displayVolume, size, diskOffering);
 
         // Verify that zone exists
         DataCenterVO zone = _dcDao.findById(zoneId);
@@ -978,8 +978,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
                 CallContext.current().putContextParameter(Volume.class, volume.getId());
                 // Increment resource count during allocation; if actual creation fails,
                 // decrement it
-                _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.volume, displayVolume);
-                _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, displayVolume, new Long(volume.getSize()));
+                _resourceLimitMgr.incrementVolumeResourceCount(volume.getAccountId(), displayVolume, volume.getSize(),
+                        _diskOfferingDao.findById(volume.getDiskOfferingId()));
                 return volume;
             }
         });
@@ -1038,8 +1038,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
         } finally {
             if (!created) {
                 logger.trace("Decrementing volume resource count for account id=" + volume.getAccountId() + " as volume failed to create on the backend");
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, cmd.getDisplayVolume());
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, cmd.getDisplayVolume(), new Long(volume.getSize()));
+                _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), cmd.getDisplayVolume(),
+                        volume.getSize(), _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()));
             }
         }
     }
@@ -1527,10 +1527,11 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
             }
 
             /* Update resource count for the account on primary storage resource */
+            DiskOffering diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId());
             if (!shrinkOk) {
-                _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), newSize - currentSize);
+                _resourceLimitMgr.incrementVolumePrimaryStorageResourceCount(volume.getAccountId(), volume.isDisplayVolume(), newSize - currentSize, diskOffering);
             } else {
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplayVolume(), currentSize - newSize);
+                _resourceLimitMgr.decrementVolumePrimaryStorageResourceCount(volume.getAccountId(), volume.isDisplayVolume(), currentSize - newSize, diskOffering);
             }
 
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
@@ -1732,8 +1733,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
                     logger.debug("Failed to destroy volume" + volume.getId(), e);
                     return null;
                 }
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplay());
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplay(), new Long(volume.getSize()));
+                _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), volume.isDisplay(),
+                        volume.getSize(), _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()));
                 return volume;
             }
             if (!deleteVolumeFromStorage(volume, caller)) {
@@ -1790,8 +1791,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
             logger.debug("Failed to recover volume" + volume.getId(), e);
             throw new CloudRuntimeException("Failed to recover volume" + volume.getId(), e);
         }
-        _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplay());
-        _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplay(), new Long(volume.getSize()));
+        _resourceLimitMgr.incrementVolumeResourceCount(volume.getAccountId(), volume.isDisplay(),
+                volume.getSize(), _diskOfferingDao.findById(volume.getDiskOfferingId()));
 
 
         publishVolumeCreationUsageEvent(volume);
@@ -2023,9 +2024,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
         /* Only works for KVM/XenServer/VMware (or "Any") for now, and volumes with 'None' since they're just allocated in DB */
         HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId());
 
-        if (hypervisorType != HypervisorType.KVM && hypervisorType != HypervisorType.XenServer
-                && hypervisorType != HypervisorType.VMware && hypervisorType != HypervisorType.Any
-                && hypervisorType != HypervisorType.None) {
+        if (!SupportedHypervisorsForVolResize.contains(hypervisorType)) {
             throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support volume resize");
         }
 
@@ -2648,8 +2647,11 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
     private void updateResourceCount(Volume volume, Boolean displayVolume) {
         // Update only when the flag has changed.
         if (displayVolume != null && displayVolume != volume.isDisplayVolume()) {
-            _resourceLimitMgr.changeResourceCount(volume.getAccountId(), ResourceType.volume, displayVolume);
-            _resourceLimitMgr.changeResourceCount(volume.getAccountId(), ResourceType.primary_storage, displayVolume, new Long(volume.getSize()));
+            if (Boolean.FALSE.equals(displayVolume)) {
+                _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), true, volume.getSize(), _diskOfferingDao.findById(volume.getDiskOfferingId()));
+            } else {
+                _resourceLimitMgr.incrementVolumeResourceCount(volume.getAccountId(), true, volume.getSize(), _diskOfferingDao.findById(volume.getDiskOfferingId()));
+            }
         }
     }
 
@@ -3868,8 +3870,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
         _accountMgr.checkAccess(caller, null, true, oldAccount);
         _accountMgr.checkAccess(caller, null, true, newAccount);
 
-        _resourceLimitMgr.checkResourceLimit(newAccount, ResourceType.volume);
-        _resourceLimitMgr.checkResourceLimit(newAccount, ResourceType.primary_storage, volume.getSize());
+        _resourceLimitMgr.checkVolumeResourceLimit(newAccount, true, volume.getSize(), _diskOfferingDao.findById(volume.getDiskOfferingId()));
 
         Transaction.execute(new TransactionCallbackNoReturn() {
             @Override
@@ -3884,16 +3885,15 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
     protected void updateVolumeAccount(Account oldAccount, VolumeVO volume, Account newAccount) {
         UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
                 Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume());
-        _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.volume);
-        _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.primary_storage, volume.getSize());
+        DiskOfferingVO diskOfferingVO = _diskOfferingDao.findById(volume.getDiskOfferingId());
+        _resourceLimitMgr.decrementVolumeResourceCount(oldAccount.getAccountId(), true, volume.getSize(),
+                diskOfferingVO);
 
         volume.setAccountId(newAccount.getAccountId());
         volume.setDomainId(newAccount.getDomainId());
         _volsDao.persist(volume);
-
-        _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.volume);
-        _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.primary_storage, volume.getSize());
-
+        _resourceLimitMgr.incrementVolumeResourceCount(newAccount.getAccountId(), true, volume.getSize(),
+                diskOfferingVO);
         UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
                 volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize(), Volume.class.getName(),
                 volume.getUuid(), volume.isDisplayVolume());
diff --git a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index c20dc9e05c2..56981cfe55c 100755
--- a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -1036,8 +1036,8 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
 
         // Verify that max doesn't exceed domain and account snapshot limits in case display is on
         if (display) {
-            long accountLimit = _resourceLimitMgr.findCorrectResourceLimitForAccount(owner, ResourceType.snapshot);
-            long domainLimit = _resourceLimitMgr.findCorrectResourceLimitForDomain(_domainMgr.getDomain(owner.getDomainId()), ResourceType.snapshot);
+            long accountLimit = _resourceLimitMgr.findCorrectResourceLimitForAccount(owner, ResourceType.snapshot, null);
+            long domainLimit = _resourceLimitMgr.findCorrectResourceLimitForDomain(_domainMgr.getDomain(owner.getDomainId()), ResourceType.snapshot, null);
             if (!_accountMgr.isRootAdmin(owner.getId()) && ((accountLimit != -1 && maxSnaps > accountLimit) || (domainLimit != -1 && maxSnaps > domainLimit))) {
                 String message = "domain/account";
                 if (owner.getType() == Account.Type.PROJECT) {
diff --git a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
index 47daec0eeda..2974cc90e6e 100644
--- a/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/main/java/com/cloud/template/HypervisorTemplateAdapter.java
@@ -421,7 +421,6 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
                     postUploadAllocation(imageStores, template, payloads);
                 } else {
                     postUploadAllocation(List.of(imageStore), template, payloads);
-
                 }
 
                 if(payloads.isEmpty()) {
@@ -470,7 +469,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
             Account account = _accountDao.findById(accountId);
             Domain domain = _domainDao.findById(account.getDomainId());
 
-            payload.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage));
+            payload.setDefaultMaxSecondaryStorageInGB(_resourceLimitMgr.findCorrectResourceLimitForAccountAndDomain(account, domain, ResourceType.secondary_storage, null));
             payload.setAccountId(accountId);
             payload.setRemoteEndPoint(ep.getPublicAddr());
             payload.setRequiresHvm(template.requiresHvm());
diff --git a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java
index 1080ad7f026..c4692ce62d6 100755
--- a/server/src/main/java/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/main/java/com/cloud/template/TemplateManagerImpl.java
@@ -2135,6 +2135,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
 
         // update template type
         TemplateType templateType = null;
+        String templateTag = null;
         if (cmd instanceof UpdateTemplateCmd) {
             boolean isAdmin = _accountMgr.isAdmin(account.getId());
             templateType = validateTemplateType(cmd, isAdmin, template.isCrossZones());
@@ -2142,6 +2143,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
                 VnfTemplateUtils.validateApiCommandParams(cmd, template);
                 vnfTemplateManager.updateVnfTemplate(template.getId(), (UpdateVnfTemplateCmd) cmd);
             }
+            templateTag = ((UpdateTemplateCmd)cmd).getTemplateTag();
         }
 
         // update is needed if any of the fields below got filled by the user
@@ -2158,6 +2160,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
                   isDynamicallyScalable == null &&
                   isRoutingTemplate == null &&
                   templateType == null &&
+                  templateTag == null &&
                   (! cleanupDetails && details == null) //update details in every case except this one
                   );
         if (!updateNeeded) {
@@ -2243,6 +2246,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         } else if (templateType != null) {
             template.setTemplateType(templateType);
         }
+        if (templateTag != null) {
+            template.setTemplateTag(org.apache.commons.lang3.StringUtils.trimToNull(templateTag));
+        }
 
         validateDetails(template, details);
 
diff --git a/server/src/main/java/com/cloud/user/DomainManagerImpl.java b/server/src/main/java/com/cloud/user/DomainManagerImpl.java
index 321d0500f22..51705e63f3a 100644
--- a/server/src/main/java/com/cloud/user/DomainManagerImpl.java
+++ b/server/src/main/java/com/cloud/user/DomainManagerImpl.java
@@ -982,25 +982,43 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
         return domainToBeMoved;
     }
 
-    protected void validateNewParentDomainResourceLimits(DomainVO domainToBeMoved, DomainVO newParentDomain) throws ResourceAllocationException {
+    protected void validateNewParentDomainResourceLimit(DomainVO domainToBeMoved, DomainVO newParentDomain,
+            Resource.ResourceType resourceType, String tag) throws ResourceAllocationException {
         long domainToBeMovedId = domainToBeMoved.getId();
         long newParentDomainId = newParentDomain.getId();
-        for (Resource.ResourceType resourceType : Resource.ResourceType.values()) {
-            long currentDomainResourceCount = _resourceCountDao.getResourceCount(domainToBeMovedId, ResourceOwnerType.Domain, resourceType);
-            long newParentDomainResourceCount = _resourceCountDao.getResourceCount(newParentDomainId, ResourceOwnerType.Domain, resourceType);
-            long newParentDomainResourceLimit = resourceLimitService.findCorrectResourceLimitForDomain(newParentDomain, resourceType);
+        long currentDomainResourceCount = _resourceCountDao.getResourceCount(domainToBeMovedId, ResourceOwnerType.Domain, resourceType, tag);
+        long newParentDomainResourceCount = _resourceCountDao.getResourceCount(newParentDomainId, ResourceOwnerType.Domain, resourceType, tag);
+        long newParentDomainResourceLimit = resourceLimitService.findCorrectResourceLimitForDomain(newParentDomain, resourceType, tag);
+
+        if (newParentDomainResourceLimit == Resource.RESOURCE_UNLIMITED) {
+            return;
+        }
+
+        if (currentDomainResourceCount + newParentDomainResourceCount > newParentDomainResourceLimit) {
+            String message = String.format("Cannot move domain [%s] to parent domain [%s] as maximum domain resource limit of type [%s] would be exceeded. The current resource "
+                            + "count for domain [%s] is [%s], the resource count for the new parent domain [%s] is [%s], and the limit is [%s].", domainToBeMoved.getUuid(),
+                    newParentDomain.getUuid(), resourceType, domainToBeMoved.getUuid(), currentDomainResourceCount, newParentDomain.getUuid(), newParentDomainResourceCount,
+                    newParentDomainResourceLimit);
+            logger.error(message);
+            throw new ResourceAllocationException(message, resourceType);
+        }
+    }
 
-            if (newParentDomainResourceLimit == Resource.RESOURCE_UNLIMITED) {
-                return;
-            }
 
-            if (currentDomainResourceCount + newParentDomainResourceCount > newParentDomainResourceLimit) {
-                String message = String.format("Cannot move domain [%s] to parent domain [%s] as maximum domain resource limit of type [%s] would be exceeded. The current resource "
-                        + "count for domain [%s] is [%s], the resource count for the new parent domain [%s] is [%s], and the limit is [%s].", domainToBeMoved.getUuid(),
-                        newParentDomain.getUuid(), resourceType, domainToBeMoved.getUuid(), currentDomainResourceCount, newParentDomain.getUuid(), newParentDomainResourceCount,
-                        newParentDomainResourceLimit);
-                logger.error(message);
-                throw new ResourceAllocationException(message, resourceType);
+    protected void validateNewParentDomainResourceLimits(DomainVO domainToBeMoved, DomainVO newParentDomain) throws ResourceAllocationException {
+        List<String> hostTags = resourceLimitService.getResourceLimitHostTags();
+        List<String> storageTags = resourceLimitService.getResourceLimitStorageTags();
+        for (Resource.ResourceType resourceType : Resource.ResourceType.values()) {
+            validateNewParentDomainResourceLimit(domainToBeMoved, newParentDomain, resourceType, null);
+            if (ResourceLimitService.HostTagsSupportingTypes.contains(resourceType)) {
+                for (String tag : hostTags) {
+                    validateNewParentDomainResourceLimit(domainToBeMoved, newParentDomain, resourceType, tag);
+                }
+            }
+            if (ResourceLimitService.StorageTagsSupportingTypes.contains(resourceType)) {
+                for (String tag : storageTags) {
+                    validateNewParentDomainResourceLimit(domainToBeMoved, newParentDomain, resourceType, tag);
+                }
             }
         }
     }
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index 99b334a9f74..770826ecfa5 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -682,25 +682,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         return _vmDao.listByHostId(hostId);
     }
 
-    private void resourceLimitCheck(Account owner, Boolean displayVm, Long cpu, Long memory) throws ResourceAllocationException {
-        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.user_vm, displayVm);
-        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.cpu, displayVm, cpu);
-        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.memory, displayVm, memory);
-    }
-
-    protected void resourceCountIncrement(long accountId, Boolean displayVm, Long cpu, Long memory) {
-        if (! VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
-            _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.user_vm, displayVm);
-            _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.cpu, displayVm, cpu);
-            _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.memory, displayVm, memory);
+    protected void resourceCountIncrement(long accountId, Boolean displayVm, ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        if (!VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
+            _resourceLimitMgr.incrementVmResourceCount(accountId, displayVm, serviceOffering, template);
         }
     }
 
-    protected void resourceCountDecrement(long accountId, Boolean displayVm, Long cpu, Long memory) {
-        if (! VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
-            _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.user_vm, displayVm);
-            _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.cpu, displayVm, cpu);
-            _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.memory, displayVm, memory);
+    protected void resourceCountDecrement(long accountId, Boolean displayVm, ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        if (!VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
+            _resourceLimitMgr.decrementVmResourceCount(accountId, displayVm, serviceOffering, template);
         }
     }
 
@@ -1339,12 +1329,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         int currentMemory = currentServiceOffering.getRamSize();
 
         Account owner = _accountMgr.getActiveAccountById(vmInstance.getAccountId());
+        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
         if (! VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
             if (newCpu > currentCpu) {
-                _resourceLimitMgr.checkResourceLimit(owner, ResourceType.cpu, newCpu - currentCpu);
+                _resourceLimitMgr.checkVmCpuResourceLimit(owner, vmInstance.isDisplay(), newServiceOffering, template, (long)(newCpu - currentCpu));
             }
             if (newMemory > currentMemory) {
-                _resourceLimitMgr.checkResourceLimit(owner, ResourceType.memory, newMemory - currentMemory);
+                _resourceLimitMgr.checkVmMemoryResourceLimit(owner, vmInstance.isDisplay(), newServiceOffering, template, (long)(newMemory - currentMemory));
             }
         }
 
@@ -1363,14 +1354,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         // Increment or decrement CPU and Memory count accordingly.
         if (! VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
             if (newCpu > currentCpu) {
-                _resourceLimitMgr.incrementResourceCount(owner.getAccountId(), ResourceType.cpu, new Long(newCpu - currentCpu));
+                _resourceLimitMgr.incrementVmCpuResourceCount(owner.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)(newCpu - currentCpu));
             } else if (currentCpu > newCpu) {
-                _resourceLimitMgr.decrementResourceCount(owner.getAccountId(), ResourceType.cpu, new Long(currentCpu - newCpu));
+                _resourceLimitMgr.decrementVmMemoryResourceCount(owner.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)(currentCpu - newCpu));
             }
             if (newMemory > currentMemory) {
-                _resourceLimitMgr.incrementResourceCount(owner.getAccountId(), ResourceType.memory, new Long(newMemory - currentMemory));
+                _resourceLimitMgr.incrementVmMemoryResourceCount(owner.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)(newMemory - currentMemory));
             } else if (currentMemory > newMemory) {
-                _resourceLimitMgr.decrementResourceCount(owner.getAccountId(), ResourceType.memory, new Long(currentMemory - newMemory));
+                _resourceLimitMgr.decrementVmMemoryResourceCount(owner.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)(currentMemory - newMemory));
             }
         }
 
@@ -1960,10 +1951,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
         if (State.Running.equals(vmInstance.getState())) {
             ServiceOfferingVO newServiceOfferingVO = serviceOfferingDao.findById(newServiceOfferingId);
+            VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
             HostVO instanceHost = _hostDao.findById(vmInstance.getHostId());
             _hostDao.loadHostTags(instanceHost);
 
-            if (!instanceHost.checkHostServiceOfferingTags(newServiceOfferingVO)) {
+            if (!instanceHost.checkHostServiceOfferingAndTemplateTags(newServiceOfferingVO, template)) {
                 logger.error(String.format("Cannot upgrade VM [%s] as the new service offering [%s] does not have the required host tags %s.", vmInstance, newServiceOfferingVO,
                         instanceHost.getHostTags()));
                 return false;
@@ -1977,6 +1969,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
         Account caller = CallContext.current().getCallingAccount();
         VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
+        Account owner = _accountDao.findById(vmInstance.getAccountId());
 
         Set<HypervisorType> supportedHypervisorTypes = new HashSet<>();
         supportedHypervisorTypes.add(HypervisorType.XenServer);
@@ -2048,13 +2041,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
             throw new InvalidParameterValueException(String.format("Dynamic scaling of vGPU type is not supported. VM has vGPU Type: [%s].", currentVgpuType));
         }
 
+        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
+
         // Check resource limits
         if (newCpu > currentCpu) {
-            _resourceLimitMgr.checkResourceLimit(caller, ResourceType.cpu, newCpu - currentCpu);
+            _resourceLimitMgr.checkVmCpuResourceLimit(owner, vmInstance.isDisplay(), newServiceOffering, template, (long)(newCpu - currentCpu));
         }
 
         if (newMemory > currentMemory) {
-            _resourceLimitMgr.checkResourceLimit(caller, ResourceType.memory, memoryDiff);
+            _resourceLimitMgr.checkVmMemoryResourceLimit(caller, vmInstance.isDisplay(), newServiceOffering, template, (long)memoryDiff);
         }
 
         // Dynamically upgrade the running vms
@@ -2086,11 +2081,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
                     // Increment CPU and Memory count accordingly.
                     if (newCpu > currentCpu) {
-                        _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long(newCpu - currentCpu));
+                        _resourceLimitMgr.incrementVmCpuResourceCount(caller.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)(newCpu - currentCpu));
                     }
 
                     if (memoryDiff > 0) {
-                        _resourceLimitMgr.incrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long(memoryDiff));
+                        _resourceLimitMgr.incrementVmMemoryResourceCount(caller.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)memoryDiff);
                     }
 
                     // #1 Check existing host has capacity
@@ -2122,11 +2117,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
                     if (!success) {
                         // Decrement CPU and Memory count accordingly.
                         if (newCpu > currentCpu) {
-                            _resourceLimitMgr.decrementResourceCount(caller.getAccountId(), ResourceType.cpu, new Long(newCpu - currentCpu));
+                            _resourceLimitMgr.decrementVmCpuResourceCount(caller.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)(newCpu - currentCpu));
                         }
 
                         if (memoryDiff > 0) {
-                            _resourceLimitMgr.decrementResourceCount(caller.getAccountId(), ResourceType.memory, new Long(memoryDiff));
+                            _resourceLimitMgr.decrementVmMemoryResourceCount(caller.getAccountId(), vmInstance.isDisplay(), newServiceOffering, template, (long)memoryDiff);
                         }
                     }
                 }
@@ -2315,11 +2310,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
                 // Get serviceOffering for Virtual Machine
                 ServiceOfferingVO serviceOffering = serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
+                VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
 
                 // First check that the maximum number of UserVMs, CPU and Memory limit for the given
                 // accountId will not be exceeded
                 if (! VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
-                    resourceLimitCheck(account, vm.isDisplayVm(), new Long(serviceOffering.getCpu()), new Long(serviceOffering.getRamSize()));
+                    resourceLimitService.checkVmResourceLimit(account, vm.isDisplayVm(), serviceOffering, template);
                 }
 
                 _haMgr.cancelDestroy(vm, vm.getHostId());
@@ -2343,7 +2339,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
                 }
 
                 //Update Resource Count for the given account
-                resourceCountIncrement(account.getId(), vm.isDisplayVm(), new Long(serviceOffering.getCpu()), new Long(serviceOffering.getRamSize()));
+                resourceCountIncrement(account.getId(), vm.isDisplayVm(), serviceOffering, template);
             }
         });
 
@@ -2632,11 +2628,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
                 String msg = "Failed to deploy Vm with Id: " + vmId + ", on Host with Id: " + hostId;
                 _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg);
 
-                // Get serviceOffering for Virtual Machine
+                // Get serviceOffering and template for Virtual Machine
                 ServiceOfferingVO offering = serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
+                VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
 
                 // Update Resource Count for the given account
-                resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize()));
+                resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), offering, template);
             }
         }
     }
@@ -2758,13 +2755,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         }
         long currentCpu = currentServiceOffering.getCpu();
         long currentMemory = currentServiceOffering.getRamSize();
-
+        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
         try {
             if (newCpu > currentCpu) {
-                _resourceLimitMgr.checkResourceLimit(owner, ResourceType.cpu, newCpu - currentCpu);
+                _resourceLimitMgr.checkVmCpuResourceLimit(owner, vmInstance.isDisplay(), svcOffering, template, newCpu - currentCpu);
             }
             if (newMemory > currentMemory) {
-                _resourceLimitMgr.checkResourceLimit(owner, ResourceType.memory, newMemory - currentMemory);
+                _resourceLimitMgr.checkVmMemoryResourceLimit(owner, vmInstance.isDisplay(), svcOffering, template, newMemory - currentMemory);
             }
         } catch (ResourceAllocationException e) {
             logger.error(String.format("Failed to updated VM due to: %s", e.getLocalizedMessage()));
@@ -2772,14 +2769,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         }
 
         if (newCpu > currentCpu) {
-            _resourceLimitMgr.incrementResourceCount(owner.getAccountId(), ResourceType.cpu, newCpu - currentCpu);
+            _resourceLimitMgr.incrementVmCpuResourceCount(owner.getAccountId(), vmInstance.isDisplay(), svcOffering, template, newCpu - currentCpu);
         } else if (newCpu > 0 && currentCpu > newCpu){
-            _resourceLimitMgr.decrementResourceCount(owner.getAccountId(), ResourceType.cpu, currentCpu - newCpu);
+            _resourceLimitMgr.decrementVmCpuResourceCount(owner.getAccountId(), vmInstance.isDisplay(), svcOffering, template, currentCpu - newCpu);
         }
         if (newMemory > currentMemory) {
-            _resourceLimitMgr.incrementResourceCount(owner.getAccountId(), ResourceType.memory, newMemory - currentMemory);
+            _resourceLimitMgr.incrementVmMemoryResourceCount(owner.getAccountId(), vmInstance.isDisplay(), svcOffering, template, newMemory - currentMemory);
         } else if (newMemory > 0 && currentMemory > newMemory){
-            _resourceLimitMgr.decrementResourceCount(owner.getAccountId(), ResourceType.memory, currentMemory - newMemory);
+            _resourceLimitMgr.decrementVmMemoryResourceCount(owner.getAccountId(), vmInstance.isDisplay(), svcOffering, template, currentMemory - newMemory);
         }
     }
 
@@ -2900,10 +2897,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
         // Resource limit changes
         ServiceOffering offering = serviceOfferingDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
+        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
         if (isDisplayVm) {
-            resourceCountIncrement(vmInstance.getAccountId(), true, Long.valueOf(offering.getCpu()), Long.valueOf(offering.getRamSize()));
+            resourceCountIncrement(vmInstance.getAccountId(), true, offering, template);
         } else {
-            resourceCountDecrement(vmInstance.getAccountId(), true, Long.valueOf(offering.getCpu()), Long.valueOf(offering.getRamSize()));
+            resourceCountDecrement(vmInstance.getAccountId(), true, offering, template);
         }
 
         // Usage
@@ -4035,11 +4033,22 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         CallContext.current().putContextParameter(VirtualMachine.class, vm.getUuid());
         return vm;
     }
-    private UserVm getCheckedUserVmResource(DataCenter zone, String hostName, String displayName, Account owner, Long diskOfferingId, Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, HTTPMethod httpmethod, String userData, Long userDataId, String userDataDetails, List<String> sshKeyPairs, Account caller, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean isDisplayVm, String keyboard, List<Long> affinityGroupIdList, Map<String, St [...]
+
+    private UserVm getCheckedUserVmResource(DataCenter zone, String hostName, String displayName, Account owner,
+        Long diskOfferingId, Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group,
+        HTTPMethod httpmethod, String userData, Long userDataId, String userDataDetails, List<String> sshKeyPairs,
+        Account caller, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean isDisplayVm,
+        String keyboard, List<Long> affinityGroupIdList, Map<String, String> customParameters, String customId,
+        Map<String, Map<Integer, String>> dhcpOptionMap, Map<Long, DiskOffering> datadiskTemplateToDiskOfferringMap,
+        Map<String, String> userVmOVFPropertiesMap, boolean dynamicScalingEnabled, String vmType, VMTemplateVO template,
+        HypervisorType hypervisorType, long accountId, ServiceOfferingVO offering, boolean isIso,
+        Long rootDiskOfferingId, long volumesSize) throws ResourceAllocationException, StorageUnavailableException,
+            InsufficientCapacityException {
         if (!VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
-            try (CheckedReservation vmReservation = new CheckedReservation(owner, ResourceType.user_vm, 1l, reservationDao, resourceLimitService);
-                 CheckedReservation cpuReservation = new CheckedReservation(owner, ResourceType.cpu, Long.valueOf(offering.getCpu()), reservationDao, resourceLimitService);
-                 CheckedReservation memReservation = new CheckedReservation(owner, ResourceType.memory, Long.valueOf(offering.getRamSize()), reservationDao, resourceLimitService);
+            List<String> resourceLimitHostTags = resourceLimitService.getResourceLimitHostTags(offering, template);
+            try (CheckedReservation vmReservation = new CheckedReservation(owner, ResourceType.user_vm, resourceLimitHostTags, 1l, reservationDao, resourceLimitService);
+                 CheckedReservation cpuReservation = new CheckedReservation(owner, ResourceType.cpu, resourceLimitHostTags, Long.valueOf(offering.getCpu()), reservationDao, resourceLimitService);
+                 CheckedReservation memReservation = new CheckedReservation(owner, ResourceType.memory, resourceLimitHostTags, Long.valueOf(offering.getRamSize()), reservationDao, resourceLimitService);
             ) {
                 return getUncheckedUserVmResource(zone, hostName, displayName, owner, diskOfferingId, diskSize, networkList, securityGroupIdList, group, httpmethod, userData, userDataId, userDataDetails, sshKeyPairs, caller, requestedIps, defaultIps, isDisplayVm, keyboard, affinityGroupIdList, customParameters, customId, dhcpOptionMap, datadiskTemplateToDiskOfferringMap, userVmOVFPropertiesMap, dynamicScalingEnabled, vmType, template, hypervisorType, accountId, offering, isIso, rootDiskO [...]
             } catch (ResourceAllocationException | CloudRuntimeException  e) {
@@ -4054,9 +4063,24 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         }
     }
 
-    private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, String displayName, Account owner, Long diskOfferingId, Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, HTTPMethod httpmethod, String userData, Long userDataId, String userDataDetails, List<String> sshKeyPairs, Account caller, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean isDisplayVm, String keyboard, List<Long> affinityGroupIdList, Map<String,  [...]
-        try (CheckedReservation volumeReservation = new CheckedReservation(owner, ResourceType.volume, (isIso || diskOfferingId == null ? 1l : 2), reservationDao, resourceLimitService);
-             CheckedReservation primaryStorageReservation = new CheckedReservation(owner, ResourceType.primary_storage, volumesSize, reservationDao, resourceLimitService)) {
+    protected List<String> getResourceLimitStorageTags(long diskOfferingId) {
+        DiskOfferingVO diskOfferingVO = _diskOfferingDao.findById(diskOfferingId);
+        return resourceLimitService.getResourceLimitStorageTags(diskOfferingVO);
+    }
+
+    private UserVm getUncheckedUserVmResource(DataCenter zone, String hostName, String displayName, Account owner,
+        Long diskOfferingId, Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group,
+        HTTPMethod httpmethod, String userData, Long userDataId, String userDataDetails, List<String> sshKeyPairs,
+        Account caller, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean isDisplayVm,
+        String keyboard, List<Long> affinityGroupIdList, Map<String, String> customParameters, String customId,
+        Map<String, Map<Integer, String>> dhcpOptionMap, Map<Long, DiskOffering> datadiskTemplateToDiskOfferringMap,
+        Map<String, String> userVmOVFPropertiesMap, boolean dynamicScalingEnabled, String vmType, VMTemplateVO template,
+        HypervisorType hypervisorType, long accountId, ServiceOfferingVO offering, boolean isIso,
+        Long rootDiskOfferingId, long volumesSize) throws ResourceAllocationException, StorageUnavailableException,
+            InsufficientCapacityException {
+        List<String> resourceLimitStorageTags = getResourceLimitStorageTags(diskOfferingId != null ? diskOfferingId : offering.getDiskOfferingId());
+        try (CheckedReservation volumeReservation = new CheckedReservation(owner, ResourceType.volume, resourceLimitStorageTags, (isIso || diskOfferingId == null ? 1l : 2), reservationDao, resourceLimitService);
+             CheckedReservation primaryStorageReservation = new CheckedReservation(owner, ResourceType.primary_storage, resourceLimitStorageTags, volumesSize, reservationDao, resourceLimitService)) {
 
             // verify security group ids
             if (securityGroupIdList != null) {
@@ -4098,8 +4122,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
                                 dataDiskTemplateId + ". Disk offering size should be greater than or equal to the template size");
                     }
                     _templateDao.loadDetails(dataDiskTemplate);
-                    _resourceLimitMgr.checkResourceLimit(owner, ResourceType.volume, 1);
-                    _resourceLimitMgr.checkResourceLimit(owner, ResourceType.primary_storage, dataDiskOffering.getDiskSize());
+                    resourceLimitService.checkVolumeResourceLimit(owner, true, dataDiskOffering.getDiskSize(), dataDiskOffering);
                 }
             }
 
@@ -4603,7 +4626,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
             try {
                 //Update Resource Count for the given account
-                resourceCountIncrement(accountId, isDisplayVm, new Long(offering.getCpu()), new Long(offering.getRamSize()));
+                resourceCountIncrement(accountId, isDisplayVm, offering, template);
             } catch (CloudRuntimeException cre) {
                 ArrayList<ExceptionProxyObject> epoList =  cre.getIdProxyList();
                 if (epoList == null || !epoList.stream().anyMatch( e -> e.getUuid().equals(vm.getUuid()))) {
@@ -5420,10 +5443,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         if (owner.getState() == Account.State.DISABLED) {
             throw new PermissionDeniedException("The owner of " + vm + " is disabled: " + vm.getAccountId());
         }
+        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
         if (VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
             // check if account/domain is with in resource limits to start a new vm
             ServiceOfferingVO offering = serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
-            resourceLimitCheck(owner, vm.isDisplayVm(), Long.valueOf(offering.getCpu()), Long.valueOf(offering.getRamSize()));
+            resourceLimitService.checkVmResourceLimit(owner, vm.isDisplayVm(), offering, template);
         }
         // check if vm is security group enabled
         if (_securityGroupMgr.isVmSecurityGroupEnabled(vmId) && _securityGroupMgr.getSecurityGroupsForVm(vmId).isEmpty()
@@ -5481,11 +5505,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
         // Set parameters
         Map<VirtualMachineProfile.Param, Object> params = null;
-        VMTemplateVO template = null;
         if (vm.isUpdateParameters()) {
             _vmDao.loadDetails(vm);
-            // Check that the password was passed in and is valid
-            template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
 
             String password = getCurrentVmPasswordOrDefineNewPassword(String.valueOf(additionalParams.getOrDefault(VirtualMachineProfile.Param.VmPassword, "")), vm, template);
 
@@ -5680,11 +5701,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
             }
 
             if (vmState != State.Error) {
-                // Get serviceOffering for Virtual Machine
+                // Get serviceOffering and template for Virtual Machine
                 ServiceOfferingVO offering = serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId());
-
+                VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
                 //Update Resource Count for the given account
-                resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize()));
+                resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(),offering, template);
             }
             return _vmDao.findById(vmId);
         } else {
@@ -7179,6 +7200,41 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         return findMigratedVm(vm.getId(), vm.getType());
     }
 
+    protected void checkVolumesLimits(Account account, List<VolumeVO> volumes) throws ResourceAllocationException {
+        Long totalVolumes = 0L;
+        Long totalVolumesSize = 0L;
+        Map<Long, List<String>> diskOfferingTagsMap = new HashMap<>();
+        Map<String, Long> tagVolumeCountMap = new HashMap<>();
+        Map<String, Long> tagSizeMap = new HashMap<>();
+        for (VolumeVO volume : volumes) {
+            if (!volume.isDisplay()) {
+                continue;
+            }
+            totalVolumes++;
+            totalVolumesSize += volume.getSize();
+            if (!diskOfferingTagsMap.containsKey(volume.getDiskOfferingId())) {
+                diskOfferingTagsMap.put(volume.getDiskOfferingId(), _resourceLimitMgr.getResourceLimitStorageTags(
+                        _diskOfferingDao.findById(volume.getDiskOfferingId())));
+            }
+            List<String> tags = diskOfferingTagsMap.get(volume.getDiskOfferingId());
+            for (String tag : tags) {
+                if (tagVolumeCountMap.containsKey(tag)) {
+                    tagVolumeCountMap.put(tag, tagVolumeCountMap.get(tag) + 1);
+                    tagSizeMap.put(tag, tagSizeMap.get(tag) + volume.getSize());
+                } else {
+                    tagVolumeCountMap.put(tag, 1L);
+                    tagSizeMap.put(tag, volume.getSize());
+                }
+            }
+        }
+        _resourceLimitMgr.checkResourceLimit(account, ResourceType.volume, totalVolumes);
+        _resourceLimitMgr.checkResourceLimit(account, ResourceType.primary_storage, totalVolumesSize);
+        for (String tag : tagVolumeCountMap.keySet()) {
+            resourceLimitService.checkResourceLimitWithTag(account, ResourceType.volume, tag, tagVolumeCountMap.get(tag));
+            resourceLimitService.checkResourceLimitWithTag(account, ResourceType.primary_storage, tag, tagSizeMap.get(tag));
+        }
+    }
+
     @DB
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_VM_MOVE, eventDescription = "move VM to another user", async = false)
@@ -7271,6 +7327,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
         DataCenterVO zone = _dcDao.findById(vm.getDataCenterId());
 
+        VirtualMachineTemplate template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
         // Get serviceOffering and Volumes for Virtual Machine
         final ServiceOfferingVO offering = serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId());
 
@@ -7278,20 +7335,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         removeInstanceFromInstanceGroup(cmd.getVmId());
 
         // VV 2: check if account/domain is with in resource limits to create a new vm
-        if (! VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
-            resourceLimitCheck(newAccount, vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize()));
+        if (!VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
+            resourceLimitService.checkVmResourceLimit(newAccount, vm.isDisplayVm(), offering, template);
         }
 
         // VV 3: check if volumes and primary storage space are with in resource limits
-        _resourceLimitMgr.checkResourceLimit(newAccount, ResourceType.volume, _volsDao.findByInstance(cmd.getVmId()).size());
-        Long totalVolumesSize = (long)0;
-        for (VolumeVO volume : volumes) {
-            totalVolumesSize += volume.getSize();
-        }
-        _resourceLimitMgr.checkResourceLimit(newAccount, ResourceType.primary_storage, totalVolumesSize);
+        checkVolumesLimits(newAccount, volumes);
 
         // VV 4: Check if new owner can use the vm template
-        VirtualMachineTemplate template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
         if (template == null) {
             throw new InvalidParameterValueException(String.format("Template for VM: %s cannot be found", vm.getUuid()));
         }
@@ -7312,7 +7363,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
                         vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(),
                         vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
                 // update resource counts for old account
-                resourceCountDecrement(oldAccount.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize()));
+                resourceCountDecrement(oldAccount.getAccountId(), vm.isDisplayVm(), offering, template);
 
                 // OWNERSHIP STEP 1: update the vm owner
                 vm.setAccountId(newAccount.getAccountId());
@@ -7323,22 +7374,19 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
                 for (VolumeVO volume : volumes) {
                     UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
                             Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume());
-                    _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.volume);
-                    _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize()));
+                    DiskOfferingVO diskOfferingVO = _diskOfferingDao.findById(volume.getDiskOfferingId());
+                    _resourceLimitMgr.decrementVolumeResourceCount(oldAccount.getAccountId(), volume.isDisplay(), volume.getSize(), diskOfferingVO);
                     volume.setAccountId(newAccount.getAccountId());
                     volume.setDomainId(newAccount.getDomainId());
                     _volsDao.persist(volume);
-                    _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.volume);
-                    _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize()));
+                    _resourceLimitMgr.incrementVolumeResourceCount(newAccount.getAccountId(), volume.isDisplay(), volume.getSize(), diskOfferingVO);
                     UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
                             volume.getDiskOfferingId(), volume.getTemplateId(), volume.getSize(), Volume.class.getName(),
                             volume.getUuid(), volume.isDisplayVolume());
                 }
 
                 //update resource count of new account
-                if (! VirtualMachineManager.ResourceCountRunningVMsonly.value()) {
-                    resourceCountIncrement(newAccount.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize()));
-                }
+                resourceCountIncrement(newAccount.getAccountId(), vm.isDisplayVm(), offering, template);
 
                 //generate usage events to account for this change
                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
@@ -7882,8 +7930,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
 
                         // 1. Save usage event and update resource count for user vm volumes
                         try {
-                            _resourceLimitMgr.incrementResourceCount(newVol.getAccountId(), ResourceType.volume, newVol.isDisplay());
-                            _resourceLimitMgr.incrementResourceCount(newVol.getAccountId(),  ResourceType.primary_storage, newVol.isDisplay(), new Long(newVol.getSize()));
+                            _resourceLimitMgr.incrementVolumeResourceCount(newVol.getAccountId(), newVol.isDisplay(), newVol.getSize(), _diskOfferingDao.findById(newVol.getDiskOfferingId()));
                         } catch (final CloudRuntimeException e) {
                             throw e;
                         } catch (final Exception e) {
@@ -8411,21 +8458,24 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
      */
     private void postProcessingUnmanageVM(UserVmVO vm) {
         ServiceOfferingVO offering = serviceOfferingDao.findById(vm.getServiceOfferingId());
-        Long cpu = offering.getCpu() != null ? new Long(offering.getCpu()) : 0L;
-        Long ram = offering.getRamSize() != null ? new Long(offering.getRamSize()) : 0L;
+        VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
         // First generate a VM stop event if the VM was not stopped already
+        boolean resourceNotDecremented = true;
         if (vm.getState() != State.Stopped) {
             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_STOP, vm.getAccountId(), vm.getDataCenterId(),
                     vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(),
                     vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
-            resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), cpu, ram);
+            resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), offering, template);
+            resourceNotDecremented = false;
         }
 
         // VM destroy usage event
         UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(),
                 vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(),
                 vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
-        resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), cpu, ram);
+        if (resourceNotDecremented) {
+            resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), offering, template);
+        }
     }
 
     /*
@@ -8439,8 +8489,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
                         Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume());
             }
-            _resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.volume);
-            _resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize()));
+            _resourceLimitMgr.decrementVolumeResourceCount(vm.getAccountId(), volume.isDisplayVolume(),
+                    volume.getSize(), _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()));
         }
     }
 
@@ -8524,7 +8574,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
         return DestroyRootVolumeOnVmDestruction.valueIn(domainId);
     }
 
-    private void setVncPasswordForKvmIfAvailable(Map<String, String> customParameters, UserVmVO vm){
+    private void setVncPasswordForKvmIfAvailable(Map<String, String> customParameters, UserVmVO vm) {
         if (customParameters.containsKey(VmDetailConstants.KVM_VNC_PASSWORD)
                 && StringUtils.isNotEmpty(customParameters.get(VmDetailConstants.KVM_VNC_PASSWORD))) {
             vm.setVncPassword(customParameters.get(VmDetailConstants.KVM_VNC_PASSWORD));
diff --git a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java
index 2f8c7fb19bc..de2eddc0375 100644
--- a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java
+++ b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java
@@ -439,9 +439,12 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
         return managedVms;
     }
 
-    private boolean hostSupportsServiceOffering(HostVO host, ServiceOffering serviceOffering) {
+    private boolean hostSupportsServiceOfferingAndTemplate(HostVO host, ServiceOffering serviceOffering, VirtualMachineTemplate template) {
+        if (StringUtils.isAllEmpty(serviceOffering.getHostTag(), template.getTemplateTag())) {
+            return true;
+        }
         hostDao.loadHostTags(host);
-        return host.checkHostServiceOfferingTags(serviceOffering);
+        return host.checkHostServiceOfferingAndTemplateTags(serviceOffering, template);
     }
 
     private boolean storagePoolSupportsDiskOffering(StoragePool pool, DiskOffering diskOffering) {
@@ -502,8 +505,6 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Service offering (%s) %dMHz CPU speed does not match VM CPU speed %dMHz and VM is not in powered off state (Power state: %s)", serviceOffering.getUuid(), serviceOffering.getSpeed(), cpuSpeed, instance.getPowerState()));
             }
         }
-        resourceLimitService.checkResourceLimit(owner, Resource.ResourceType.cpu, Long.valueOf(serviceOffering.getCpu()));
-        resourceLimitService.checkResourceLimit(owner, Resource.ResourceType.memory, Long.valueOf(serviceOffering.getRamSize()));
         return serviceOffering;
     }
 
@@ -605,7 +606,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
         if (diskOffering != null) {
             accountService.checkAccess(owner, diskOffering, zone);
         }
-        resourceLimitService.checkResourceLimit(owner, Resource.ResourceType.volume);
+        resourceLimitService.checkVolumeResourceLimit(owner, true, null, diskOffering);
         if (disk.getCapacity() == null || disk.getCapacity() == 0) {
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Size of disk(ID: %s) is found invalid during VM import", disk.getDiskId()));
         }
@@ -893,7 +894,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
             cleanupFailedImportVM(vm);
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to check migrations need during import, VM: %s", userVm.getInstanceName()));
         }
-        if (!hostSupportsServiceOffering(sourceHost, serviceOffering)) {
+        if (!hostSupportsServiceOfferingAndTemplate(sourceHost, serviceOffering, template)) {
             logger.debug(String.format("VM %s needs to be migrated", vm.getUuid()));
             final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, template, serviceOffering, owner, null);
             DeploymentPlanner.ExcludeList excludeList = new DeploymentPlanner.ExcludeList();
@@ -1010,7 +1011,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
         return userVm;
     }
 
-    private void publishVMUsageUpdateResourceCount(final UserVm userVm, ServiceOfferingVO serviceOfferingVO) {
+    private void publishVMUsageUpdateResourceCount(final UserVm userVm, ServiceOfferingVO serviceOfferingVO, VirtualMachineTemplate templateVO) {
         if (userVm == null || serviceOfferingVO == null) {
             logger.error(String.format("Failed to publish usage records during VM import because VM [%s] or ServiceOffering [%s] is null.", userVm, serviceOfferingVO));
             cleanupFailedImportVM(userVm);
@@ -1033,9 +1034,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
             cleanupFailedImportVM(userVm);
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("VM import failed for unmanaged vm %s during publishing usage records", userVm.getInstanceName()));
         }
-        resourceLimitService.incrementResourceCount(userVm.getAccountId(), Resource.ResourceType.user_vm, userVm.isDisplayVm());
-        resourceLimitService.incrementResourceCount(userVm.getAccountId(), Resource.ResourceType.cpu, userVm.isDisplayVm(), Long.valueOf(serviceOfferingVO.getCpu()));
-        resourceLimitService.incrementResourceCount(userVm.getAccountId(), Resource.ResourceType.memory, userVm.isDisplayVm(), Long.valueOf(serviceOfferingVO.getRamSize()));
+        resourceLimitService.incrementVmResourceCount(userVm.getAccountId(), userVm.isDisplayVm(), serviceOfferingVO, templateVO);
         // Save usage event and update resource count for user vm volumes
         List<VolumeVO> volumes = volumeDao.findByInstance(userVm.getId());
         for (VolumeVO volume : volumes) {
@@ -1045,8 +1044,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
             } catch (Exception e) {
                 logger.error(String.format("Failed to publish volume ID: %s usage records during VM import", volume.getUuid()), e);
             }
-            resourceLimitService.incrementResourceCount(userVm.getAccountId(), Resource.ResourceType.volume, volume.isDisplayVolume());
-            resourceLimitService.incrementResourceCount(userVm.getAccountId(), Resource.ResourceType.primary_storage, volume.isDisplayVolume(), volume.getSize());
+            resourceLimitService.incrementVolumeResourceCount(userVm.getAccountId(), volume.isDisplayVolume(),
+                    volume.getSize(), diskOfferingDao.findById(volume.getDiskOfferingId()));
         }
 
         List<NicVO> nics = nicDao.listByVmId(userVm.getId());
@@ -1061,6 +1060,40 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
         }
     }
 
+    protected void checkUnmanagedDiskLimits(Account account, UnmanagedInstanceTO.Disk rootDisk, ServiceOffering serviceOffering,
+            List<UnmanagedInstanceTO.Disk> dataDisks, Map<String, Long> dataDiskOfferingMap) throws ResourceAllocationException {
+        Long totalVolumes = 0L;
+        Long totalVolumesSize = 0L;
+        List<UnmanagedInstanceTO.Disk> disks = new ArrayList<>();
+        disks.add(rootDisk);
+        disks.addAll(dataDisks);
+        Map<String, Long> diskOfferingMap = new HashMap<>(dataDiskOfferingMap);
+        diskOfferingMap.put(rootDisk.getDiskId(), serviceOffering.getDiskOfferingId());
+        Map<Long, Long> diskOfferingVolumeCountMap = new HashMap<>();
+        Map<Long, Long> diskOfferingSizeMap = new HashMap<>();
+        for (UnmanagedInstanceTO.Disk disk : disks) {
+            totalVolumes++;
+            totalVolumesSize += disk.getCapacity();
+            Long diskOfferingId = diskOfferingMap.get(disk.getDiskId());
+            if (diskOfferingVolumeCountMap.containsKey(diskOfferingId)) {
+                diskOfferingVolumeCountMap.put(diskOfferingId, diskOfferingVolumeCountMap.get(diskOfferingId) + 1);
+                diskOfferingSizeMap.put(diskOfferingId, diskOfferingSizeMap.get(diskOfferingId) + disk.getCapacity());
+            } else {
+                diskOfferingVolumeCountMap.put(diskOfferingId, 1L);
+                diskOfferingSizeMap.put(diskOfferingId, disk.getCapacity());
+            }
+        }
+        resourceLimitService.checkResourceLimit(account, Resource.ResourceType.volume, totalVolumes);
+        resourceLimitService.checkResourceLimit(account, Resource.ResourceType.primary_storage, totalVolumesSize);
+        for (Long diskOfferingId : diskOfferingVolumeCountMap.keySet()) {
+            List<String> tags = resourceLimitService.getResourceLimitStorageTags(diskOfferingDao.findById(diskOfferingId));
+            for (String tag : tags) {
+                resourceLimitService.checkResourceLimitWithTag(account, Resource.ResourceType.volume, tag, diskOfferingVolumeCountMap.get(diskOfferingId));
+                resourceLimitService.checkResourceLimitWithTag(account, Resource.ResourceType.primary_storage, tag, diskOfferingSizeMap.get(diskOfferingId));
+            }
+        }
+    }
+
     private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedInstance, final String instanceName, final DataCenter zone, final Cluster cluster, final HostVO host,
                                                 final VirtualMachineTemplate template, final String displayName, final String hostName, final Account caller, final Account owner, final Long userId,
                                                 final ServiceOfferingVO serviceOffering, final Map<String, Long> dataDiskOfferingMap,
@@ -1091,8 +1124,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
             }
         }
 
-        if (!migrateAllowed && host != null && !hostSupportsServiceOffering(host, validatedServiceOffering)) {
-            throw new InvalidParameterValueException(String.format("Service offering: %s is not compatible with host: %s of unmanaged VM: %s", serviceOffering.getUuid(), host.getUuid(), instanceName));
+        if (!migrateAllowed && host != null && !hostSupportsServiceOfferingAndTemplate(host, validatedServiceOffering, template)) {
+            throw new InvalidParameterValueException(String.format("Service offering: %s or template: %s is not compatible with host: %s of unmanaged VM: %s", serviceOffering.getUuid(), template.getUuid(), host.getUuid(), instanceName));
         }
         // Check disks and supplied disk offerings
         List<UnmanagedInstanceTO.Disk> unmanagedInstanceDisks = unmanagedInstance.getDisks();
@@ -1124,7 +1157,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
                 checkUnmanagedDiskAndOfferingForImport(unmanagedInstance.getName(), dataDisks, dataDiskOfferingMap, owner, zone, cluster, migrateAllowed);
                 allDetails.put(VmDetailConstants.DATA_DISK_CONTROLLER, dataDisks.get(0).getController());
             }
-            resourceLimitService.checkResourceLimit(owner, Resource.ResourceType.volume, unmanagedInstanceDisks.size());
+            checkUnmanagedDiskLimits(owner, rootDisk, serviceOffering, dataDisks, dataDiskOfferingMap);
         } catch (ResourceAllocationException e) {
             logger.error(String.format("Volume resource allocation error for owner: %s", owner.getUuid()), e);
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Volume resource allocation error for owner: %s. %s", owner.getUuid(), StringUtils.defaultString(e.getMessage())));
@@ -1207,7 +1240,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
         if (migrateAllowed) {
             userVm = migrateImportedVM(host, template, validatedServiceOffering, userVm, owner, diskProfileStoragePoolList);
         }
-        publishVMUsageUpdateResourceCount(userVm, validatedServiceOffering);
+        publishVMUsageUpdateResourceCount(userVm, validatedServiceOffering, template);
         return userVm;
     }
 
@@ -1309,7 +1342,6 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
         String hostName = getHostNameForImportInstance(cmd.getHostName(), cluster.getHypervisorType(), instanceName, displayName);
 
         checkVmwareInstanceNameForImportInstance(cluster.getHypervisorType(), instanceName, hostName, zone);
-
         final Map<String, Long> nicNetworkMap = cmd.getNicNetworkList();
         final Map<String, Network.IpAddresses> nicIpAddressMap = cmd.getNicIpAddressList();
         final Map<String, Long> dataDiskOfferingMap = cmd.getDataDiskToDiskOfferingList();
@@ -2240,7 +2272,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
             cleanupFailedImportVM(userVm);
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to import NICs while importing vm: %s. %s", instanceName, StringUtils.defaultString(e.getMessage())));
         }
-        publishVMUsageUpdateResourceCount(userVm, serviceOffering);
+        publishVMUsageUpdateResourceCount(userVm, serviceOffering, template);
         return userVm;
     }
 
@@ -2373,8 +2405,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
             cleanupFailedImportVM(userVm);
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to import volumes while importing vm: %s. %s", instanceName, StringUtils.defaultString(e.getMessage())));
         }
-        networkOrchestrationService.importNic(macAddress,0,network, true, userVm, requestedIpPair, zone, true);
-        publishVMUsageUpdateResourceCount(userVm, serviceOffering);
+        networkOrchestrationService.importNic(macAddress, 0, network, true, userVm, requestedIpPair, zone, true);
+        publishVMUsageUpdateResourceCount(userVm, serviceOffering, template);
         return userVm;
     }
 
diff --git a/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java b/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java
index 1bea3ac78f3..a68623aa144 100644
--- a/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java
+++ b/server/src/test/java/com/cloud/api/ApiResponseHelperTest.java
@@ -16,6 +16,8 @@
 // under the License.
 package com.cloud.api;
 
+import com.cloud.capacity.Capacity;
+import com.cloud.configuration.Resource;
 import com.cloud.domain.DomainVO;
 import com.cloud.network.PublicIpQuarantine;
 import com.cloud.network.as.AutoScaleVmGroup;
@@ -452,4 +454,31 @@ public class ApiResponseHelperTest {
         Assert.assertEquals(removerAccountUuid, result.getRemoverAccountId());
         Assert.assertEquals("quarantinedip", result.getResponseName());
     }
+
+    @Test
+    public void testCapacityListingForSingleTag() {
+        Capacity c1 = Mockito.mock(Capacity.class);
+        Mockito.when(c1.getTag()).thenReturn("tag1");
+        Capacity c2 = Mockito.mock(Capacity.class);
+        Mockito.when(c2.getTag()).thenReturn("tag1");
+        Capacity c3 = Mockito.mock(Capacity.class);
+        Mockito.when(c3.getTag()).thenReturn("tag2");
+        Capacity c4 = Mockito.mock(Capacity.class);
+        Assert.assertTrue(apiResponseHelper.capacityListingForSingleTag(List.of(c1, c2)));
+        Assert.assertFalse(apiResponseHelper.capacityListingForSingleTag(List.of(c1, c2, c3)));
+        Assert.assertFalse(apiResponseHelper.capacityListingForSingleTag(List.of(c4, c2, c3)));
+    }
+
+    @Test
+    public void testCapacityListingForSingleNonGpuType() {
+        Capacity c1 = Mockito.mock(Capacity.class);
+        Mockito.when(c1.getCapacityType()).thenReturn((short)Resource.ResourceType.user_vm.getOrdinal());
+        Capacity c2 = Mockito.mock(Capacity.class);
+        Mockito.when(c2.getCapacityType()).thenReturn((short)Resource.ResourceType.user_vm.getOrdinal());
+        Capacity c3 = Mockito.mock(Capacity.class);
+        Mockito.when(c3.getCapacityType()).thenReturn((short)Resource.ResourceType.volume.getOrdinal());
+        Capacity c4 = Mockito.mock(Capacity.class);
+        Assert.assertTrue(apiResponseHelper.capacityListingForSingleNonGpuType(List.of(c1, c2)));
+        Assert.assertFalse(apiResponseHelper.capacityListingForSingleNonGpuType(List.of(c1, c2, c3)));
+    }
 }
diff --git a/server/src/test/java/com/cloud/api/query/QueryManagerImplTest.java b/server/src/test/java/com/cloud/api/query/QueryManagerImplTest.java
index 4af84cfa814..09fcde24d79 100644
--- a/server/src/test/java/com/cloud/api/query/QueryManagerImplTest.java
+++ b/server/src/test/java/com/cloud/api/query/QueryManagerImplTest.java
@@ -28,7 +28,9 @@ import com.cloud.network.VNF;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.server.ResourceTag;
 import com.cloud.storage.BucketVO;
+import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.dao.BucketDao;
+import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
@@ -53,6 +55,7 @@ import org.apache.cloudstack.api.response.ObjectStoreResponse;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.storage.datastore.db.ObjectStoreDao;
 import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO;
+import org.apache.commons.collections.CollectionUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -109,6 +112,8 @@ public class QueryManagerImplTest {
 
     @Mock
     BucketDao bucketDao;
+    @Mock
+    VMTemplateDao templateDao;
 
     private AccountVO account;
     private UserVO user;
@@ -340,4 +345,53 @@ public class QueryManagerImplTest {
         when(bucketDao.searchAndCount(any(), any())).thenReturn(new Pair<>(buckets, 2));
         queryManagerImplSpy.searchForBuckets(listBucketsCmd);
     }
+
+    @Test
+    public void testGetHostTagsFromTemplateForServiceOfferingsListingNoTemplateId() {
+        CollectionUtils.isEmpty(queryManager.getHostTagsFromTemplateForServiceOfferingsListing(Mockito.mock(AccountVO.class), null));
+    }
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testGetHostTagsFromTemplateForServiceOfferingsListingException() {
+        queryManager.getHostTagsFromTemplateForServiceOfferingsListing(Mockito.mock(AccountVO.class), 1L);
+    }
+
+    @Test(expected = PermissionDeniedException.class)
+    public void testGetHostTagsForServiceOfferingsListingNoAccess() {
+        long templateId = 1L;
+        Account account = Mockito.mock(Account.class);
+        Mockito.when(account.getType()).thenReturn(Account.Type.NORMAL);
+        VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
+        Mockito.when(templateDao.findByIdIncludingRemoved(templateId)).thenReturn(template);
+        Mockito.lenient().doThrow(PermissionDeniedException.class).when(accountManager).checkAccess(account, null, false, template);
+        queryManager.getHostTagsFromTemplateForServiceOfferingsListing(account, templateId);
+    }
+
+    @Test
+    public void testGetHostTagsFromTemplateForServiceOfferingsListingAdmin() {
+        long templateId = 1L;
+        Account account = Mockito.mock(Account.class);
+        Mockito.when(account.getType()).thenReturn(Account.Type.ADMIN);
+        VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
+        Mockito.when(template.getTemplateTag()).thenReturn("tag");
+        Mockito.when(templateDao.findByIdIncludingRemoved(templateId)).thenReturn(template);
+        Mockito.lenient().doThrow(PermissionDeniedException.class).when(accountManager).checkAccess(account, null, false, template);
+        List<String> result = queryManager.getHostTagsFromTemplateForServiceOfferingsListing(account, templateId);
+        Assert.assertTrue(CollectionUtils.isNotEmpty(result));
+    }
+
+    @Test
+    public void testGetHostTagsForServiceOfferingsListingSuccess() {
+        long templateId = 1L;
+        Account account = Mockito.mock(Account.class);
+        Mockito.when(account.getType()).thenReturn(Account.Type.NORMAL);
+        VMTemplateVO template = Mockito.mock(VMTemplateVO.class);
+        Mockito.when(templateDao.findByIdIncludingRemoved(templateId)).thenReturn(template);
+        Mockito.lenient().doNothing().when(accountManager).checkAccess(account, null, false, template);
+        List<String> result = queryManager.getHostTagsFromTemplateForServiceOfferingsListing(account, templateId);
+        Assert.assertTrue(CollectionUtils.isEmpty(result));
+        Mockito.when(template.getTemplateTag()).thenReturn("tag");
+        result = queryManager.getHostTagsFromTemplateForServiceOfferingsListing(account, templateId);
+        Assert.assertTrue(CollectionUtils.isNotEmpty(result));
+    }
 }
diff --git a/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java b/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java
index b8b35e2ce87..e44fa17330c 100644
--- a/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java
+++ b/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java
@@ -18,28 +18,37 @@
 //
 package com.cloud.resourcelimit;
 
-import com.cloud.configuration.Resource;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.user.Account;
-import com.cloud.user.ResourceLimitService;
-import com.cloud.utils.db.GlobalLock;
-import com.cloud.utils.exception.CloudRuntimeException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.context.CallContext;
 import org.apache.cloudstack.reservation.ReservationVO;
 import org.apache.cloudstack.reservation.dao.ReservationDao;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.mockito.MockedStatic;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+import org.springframework.test.util.ReflectionTestUtils;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.lenient;
-import static org.mockito.Mockito.when;
+import com.cloud.configuration.Resource;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.utils.db.GlobalLock;
+import com.cloud.utils.exception.CloudRuntimeException;
 
 @RunWith(MockitoJUnitRunner.class)
 public class CheckedReservationTest {
@@ -58,14 +67,19 @@ public class CheckedReservationTest {
     GlobalLock quotaLimitLock;
 
     private AutoCloseable closeable;
+    private MockedStatic<GlobalLock> globalLockMocked;
 
     @Before
-    public void setup() {
+    public void setup() throws Exception {
         closeable = MockitoAnnotations.openMocks(this);
+        globalLockMocked = Mockito.mockStatic(GlobalLock.class);
+        Mockito.when(quotaLimitLock.lock(Mockito.anyInt())).thenReturn(true);
+        globalLockMocked.when(() -> GlobalLock.getInternLock(Mockito.anyString())).thenReturn(quotaLimitLock);
     }
 
     @After
     public void tearDown() throws Exception {
+        globalLockMocked.close();
         closeable.close();
     }
 
@@ -76,7 +90,9 @@ public class CheckedReservationTest {
         lenient().when(reservationDao.persist(Mockito.any())).thenReturn(reservation);
         lenient().when(reservation.getId()).thenReturn(1L);
         try (CheckedReservation cr = new CheckedReservation(account, Resource.ResourceType.user_vm,1l, reservationDao, resourceLimitService) ) {
-            long id = cr.getId();
+            List<Long> ids = cr.getIds();
+            assertEquals(1, cr.getIds().size());
+            long id = ids.get(0);
             assertEquals(1L, id);
         } catch (NullPointerException npe) {
             fail("NPE caught");
@@ -103,4 +119,28 @@ public class CheckedReservationTest {
             throw new RuntimeException(e);
         }
     }
+
+    @Test
+    public void testReservationPersistAndCallContextParam() {
+        List<String> tags = List.of("abc", "xyz");
+        when(account.getAccountId()).thenReturn(1L);
+        when(account.getDomainId()).thenReturn(4L);
+        List<ReservationVO> persistedReservations = new ArrayList<>();
+        Mockito.when(reservationDao.persist(Mockito.any(ReservationVO.class))).thenAnswer((Answer<ReservationVO>) invocation -> {
+            ReservationVO reservationVO = (ReservationVO) invocation.getArguments()[0];
+            ReflectionTestUtils.setField(reservationVO, "id", (long) (persistedReservations.size() + 1));
+            persistedReservations.add(reservationVO);
+            return reservationVO;
+        });
+        Resource.ResourceType type = Resource.ResourceType.cpu;
+        try (CheckedReservation cr = new CheckedReservation(account, type, tags, 2L, reservationDao, resourceLimitService);) {
+            Assert.assertEquals(tags.size() + 1, persistedReservations.size()); // An extra for no tag
+            Object obj = CallContext.current().getContextParameter(CheckedReservation.getResourceReservationContextParameterKey(type));
+            Assert.assertTrue(obj instanceof List);
+            List<Long> list = (List<Long>) obj;
+            Assert.assertEquals(tags.size() + 1, list.size()); // An extra for no tag
+        } catch (Exception e) {
+            Assert.fail("Exception faced: " + e.getMessage());
+        }
+    }
 }
diff --git a/server/src/test/java/com/cloud/resourcelimit/ResourceLimitManagerImplTest.java b/server/src/test/java/com/cloud/resourcelimit/ResourceLimitManagerImplTest.java
index 86a1a0f4356..97a4b12f84e 100644
--- a/server/src/test/java/com/cloud/resourcelimit/ResourceLimitManagerImplTest.java
+++ b/server/src/test/java/com/cloud/resourcelimit/ResourceLimitManagerImplTest.java
@@ -16,27 +16,127 @@
 // under the License.
 package com.cloud.resourcelimit;
 
-import com.cloud.configuration.ResourceLimit;
-import com.cloud.vpc.MockResourceLimitManagerImpl;
-import junit.framework.TestCase;
-import org.apache.logging.log4j.Logger;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.TaggedResourceLimitAndCountResponse;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
 
+import com.cloud.api.query.dao.UserVmJoinDao;
+import com.cloud.api.query.vo.UserVmJoinVO;
+import com.cloud.configuration.Resource;
+import com.cloud.configuration.ResourceCountVO;
+import com.cloud.configuration.ResourceLimit;
+import com.cloud.configuration.ResourceLimitVO;
+import com.cloud.configuration.dao.ResourceCountDao;
+import com.cloud.configuration.dao.ResourceLimitDao;
+import com.cloud.domain.Domain;
+import com.cloud.domain.DomainVO;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.offering.DiskOffering;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.projects.ProjectVO;
+import com.cloud.projects.dao.ProjectDao;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.DiskOfferingVO;
+import com.cloud.storage.VMTemplateVO;
+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.template.VirtualMachineTemplate;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.Pair;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDao;
+import com.cloud.vpc.MockResourceLimitManagerImpl;
+
+import junit.framework.TestCase;
+
+@RunWith(MockitoJUnitRunner.class)
 public class ResourceLimitManagerImplTest extends TestCase {
     private Logger logger = LogManager.getLogger(ResourceLimitManagerImplTest.class);
 
     MockResourceLimitManagerImpl _resourceLimitService = new MockResourceLimitManagerImpl();
 
-    @Override
+    @Spy
+    @InjectMocks
+    ResourceLimitManagerImpl resourceLimitManager;
+
+    @Mock
+    VMInstanceDao vmDao;
+    @Mock
+    AccountDao accountDao;
+    @Mock
+    AccountManager accountManager;
+    @Mock
+    ResourceLimitDao resourceLimitDao;
+    @Mock
+    DomainDao domainDao;
+    @Mock
+    ProjectDao projectDao;
+    @Mock
+    ResourceCountDao resourceCountDao;
+    @Mock
+    UserVmJoinDao userVmJoinDao;
+    @Mock
+    ServiceOfferingDao serviceOfferingDao;
+    @Mock
+    VMTemplateDao vmTemplateDao;
+    @Mock
+    DiskOfferingDao diskOfferingDao;
+    @Mock
+    VolumeDao volumeDao;
+    @Mock
+    UserVmDao userVmDao;
+
+    private List<String> hostTags = List.of("htag1", "htag2", "htag3");
+    private List<String> storageTags = List.of("stag1", "stag2");
+
+    private void overrideDefaultConfigValue(final ConfigKey configKey, final String name, final Object o) throws IllegalAccessException, NoSuchFieldException {
+        Field f = ConfigKey.class.getDeclaredField(name);
+        f.setAccessible(true);
+        f.set(configKey, o);
+    }
+
     @Before
     public void setUp() {
-
+        try {
+            overrideDefaultConfigValue(ResourceLimitService.ResourceLimitHostTags, "_defaultValue", StringUtils.join(hostTags, ","));
+            overrideDefaultConfigValue(ResourceLimitService.ResourceLimitStorageTags, "_defaultValue", StringUtils.join(storageTags, ","));
+        } catch (IllegalAccessException | NoSuchFieldException e) {
+            logger.error("Failed to update configurations");
+        }
     }
 
-    @Override
     @After
     public void tearDown() throws Exception {
     }
@@ -55,12 +155,12 @@ public class ResourceLimitManagerImplTest extends TestCase {
         Long accountId = (long)1;
         Long domainId = (long)1;
         String msg = "Update Resource Count for account: TEST FAILED";
-        assertNull(msg, _resourceLimitService.recalculateResourceCount(accountId, domainId, null));
+        Assert.assertNull(msg, _resourceLimitService.recalculateResourceCount(accountId, domainId, null));
 
         // update resource count for a domain
         accountId = null;
         msg = "Update Resource Count for domain: TEST FAILED";
-        assertNull(msg, _resourceLimitService.recalculateResourceCount(accountId, domainId, null));
+        Assert.assertNull(msg, _resourceLimitService.recalculateResourceCount(accountId, domainId, null));
     }
 
     protected void updateResourceLimit() {
@@ -93,10 +193,937 @@ public class ResourceLimitManagerImplTest extends TestCase {
         String msg = "Update Resource Limit: TEST FAILED";
         ResourceLimit result = null;
         try {
-            result = _resourceLimitService.updateResourceLimit(accountId, domainId, resourceType, max);
-            assertFalse(msg, (result != null || (result == null && max != null && max.longValue() == -1L)));
+            result = _resourceLimitService.updateResourceLimit(accountId, domainId, resourceType, max, null);
+            Assert.assertFalse(msg, (result != null || (result == null && max != null && max.longValue() == -1L)));
         } catch (Exception ex) {
-            fail(msg);
+            Assert.fail(msg);
+        }
+    }
+
+    @Test
+    public void testRemoveUndesiredTaggedLimits() {
+        String desiredTag = "tag1";
+        String undesiredTag = "tag2";
+        List<ResourceLimitVO> limits = new ArrayList<>();
+        limits.add(new ResourceLimitVO(Resource.ResourceType.cpu, 100L, 1L, Resource.ResourceOwnerType.Account, desiredTag));
+        limits.add(new ResourceLimitVO(Resource.ResourceType.cpu, 100L, 1L, Resource.ResourceOwnerType.Account, undesiredTag));
+        resourceLimitManager.removeUndesiredTaggedLimits(limits, List.of(desiredTag), null);
+        Assert.assertEquals(1, limits.size());
+        Assert.assertEquals(desiredTag, limits.get(0).getTag());
+    }
+
+    @Test
+    public void testGetResourceLimitHostTags() {
+        List<String> tags = resourceLimitManager.getResourceLimitHostTags();
+        Assert.assertEquals(3, tags.size());
+        for (int i = 0; i < tags.size(); ++i) {
+            Assert.assertEquals(hostTags.get(i), tags.get(i));
+        }
+    }
+
+    @Test
+    public void testGetResourceLimitHostTags1() {
+        ServiceOffering serviceOffering = Mockito.mock(ServiceOffering.class);
+        VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
+        Mockito.when(serviceOffering.getHostTag()).thenReturn(hostTags.get(0));
+        Mockito.when(template.getTemplateTag()).thenReturn(hostTags.get(1));
+        List<String> tags = resourceLimitManager.getResourceLimitHostTags(serviceOffering, template);
+        Assert.assertEquals(2, tags.size());
+        Assert.assertEquals(hostTags.get(0), tags.get(0));
+        Assert.assertEquals(hostTags.get(1), tags.get(1));
+    }
+
+    @Test
+    public void testGetResourceLimitStorageTags() {
+        List<String> tags = resourceLimitManager.getResourceLimitStorageTags();
+        Assert.assertEquals(2, tags.size());
+        for (int i = 0; i < tags.size(); ++i) {
+            Assert.assertEquals(storageTags.get(i), tags.get(i));
+        }
+    }
+
+    @Test
+    public void testGetResourceLimitStorageTags1() {
+        DiskOffering diskOffering = Mockito.mock(DiskOffering.class);
+        Mockito.when(diskOffering.getTags()).thenReturn(storageTags.get(1));
+        Mockito.when(diskOffering.getTagsArray()).thenReturn(new String[]{storageTags.get(1)});
+        List<String> tags = resourceLimitManager.getResourceLimitStorageTags(diskOffering);
+        Assert.assertEquals(1, tags.size());
+        Assert.assertEquals(storageTags.get(1), tags.get(0));
+    }
+
+    @Test
+    public void testCheckVmResourceLimit() {
+        ServiceOffering serviceOffering = Mockito.mock(ServiceOffering.class);
+        VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
+        Mockito.when(serviceOffering.getHostTag()).thenReturn(hostTags.get(0));
+        Mockito.when(serviceOffering.getCpu()).thenReturn(2);
+        Mockito.when(serviceOffering.getRamSize()).thenReturn(256);
+        Mockito.when(template.getTemplateTag()).thenReturn(hostTags.get(0));
+        Account account = Mockito.mock(Account.class);
+        try {
+            Mockito.doNothing().when(resourceLimitManager).checkResourceLimitWithTag(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
+            resourceLimitManager.checkVmResourceLimit(account, true, serviceOffering, template);
+            List<String> tags = new ArrayList<>();
+            tags.add(null);
+            tags.add(hostTags.get(0));
+            for (String tag: tags) {
+                Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.user_vm, tag);
+                Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.cpu, tag, 2L);
+                Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.memory, tag, 256L);
+            }
+        } catch (ResourceAllocationException e) {
+            Assert.fail("Exception encountered: " + e.getMessage());
+        }
+    }
+
+    @Test
+    public void testCheckVmCpuResourceLimit() {
+        ServiceOffering serviceOffering = Mockito.mock(ServiceOffering.class);
+        VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
+        Mockito.when(serviceOffering.getHostTag()).thenReturn(hostTags.get(0));
+        Mockito.when(template.getTemplateTag()).thenReturn(hostTags.get(0));
+        Account account = Mockito.mock(Account.class);
+        long cpu = 2L;
+        try {
+            Mockito.doNothing().when(resourceLimitManager).checkResourceLimitWithTag(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
+            resourceLimitManager.checkVmCpuResourceLimit(account, true, serviceOffering, template, cpu);
+            Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.cpu, null, cpu);
+            Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.cpu, hostTags.get(0), cpu);
+        } catch (ResourceAllocationException e) {
+            Assert.fail("Exception encountered: " + e.getMessage());
+        }
+    }
+
+    @Test
+    public void testCheckVmMemoryResourceLimit() {
+        ServiceOffering serviceOffering = Mockito.mock(ServiceOffering.class);
+        VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
+        Mockito.when(serviceOffering.getHostTag()).thenReturn(hostTags.get(0));
+        Mockito.when(template.getTemplateTag()).thenReturn(hostTags.get(0));
+        Account account = Mockito.mock(Account.class);
+        long delta = 256L;
+        try {
+            Mockito.doNothing().when(resourceLimitManager).checkResourceLimitWithTag(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
+            resourceLimitManager.checkVmMemoryResourceLimit(account, true, serviceOffering, template, delta);
+            Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.memory, null, delta);
+            Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.memory, hostTags.get(0), delta);
+        } catch (ResourceAllocationException e) {
+            Assert.fail("Exception encountered: " + e.getMessage());
+        }
+    }
+
+    @Test
+    public void testCheckVolumeResourceLimit() {
+        String checkTag = storageTags.get(0);
+        DiskOffering diskOffering = Mockito.mock(DiskOffering.class);
+        Mockito.when(diskOffering.getTags()).thenReturn(checkTag);
+        Mockito.when(diskOffering.getTagsArray()).thenReturn(new String[]{checkTag});
+        Account account = Mockito.mock(Account.class);
+        try {
+            Mockito.doNothing().when(resourceLimitManager).checkResourceLimitWithTag(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
+            resourceLimitManager.checkVolumeResourceLimit(account, true, 100L, diskOffering);
+            List<String> tags = new ArrayList<>();
+            tags.add(null);
+            tags.add(checkTag);
+            for (String tag: tags) {
+                Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.volume, tag);
+                Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(account, Resource.ResourceType.primary_storage, tag, 100L);
+            }
+        } catch (ResourceAllocationException e) {
+            Assert.fail("Exception encountered: " + e.getMessage());
+        }
+    }
+
+    @Test
+    public void testGetResourceLimitTagsForLimitSearch() {
+        Pair<List<String>, List<String>> result = resourceLimitManager.getResourceLimitTagsForLimitSearch(null);
+        Assert.assertEquals(hostTags, result.first());
+        Assert.assertEquals(storageTags, result.second());
+        String nonExistentTag = "sometag";
+        result = resourceLimitManager.getResourceLimitTagsForLimitSearch(nonExistentTag);
+        Assert.assertTrue(CollectionUtils.isEmpty(result.first()));
+        Assert.assertTrue(CollectionUtils.isEmpty(result.second()));
+        String hostTag = "htag2";
+        result = resourceLimitManager.getResourceLimitTagsForLimitSearch(hostTag);
+        Assert.assertTrue(CollectionUtils.isNotEmpty(result.first()));
+        Assert.assertEquals(1, result.first().size());
+        Assert.assertEquals(hostTag, result.first().get(0));
+        Assert.assertTrue(CollectionUtils.isEmpty(result.second()));
+        String storageTag = "stag1";
+        result = resourceLimitManager.getResourceLimitTagsForLimitSearch(storageTag);
+        Assert.assertTrue(CollectionUtils.isNotEmpty(result.second()));
+        Assert.assertEquals(1, result.second().size());
+        Assert.assertEquals(storageTag, result.second().get(0));
+        Assert.assertTrue(CollectionUtils.isEmpty(result.first()));
+    }
+
+    @Test
+    public void testIsTaggedResourceCountRecalculationNotNeeded() {
+        Assert.assertTrue(resourceLimitManager.isTaggedResourceCountRecalculationNotNeeded(
+                Resource.ResourceType.network, List.of("h1", "h2"), List.of("s1", "s2")));
+        Assert.assertTrue(resourceLimitManager.isTaggedResourceCountRecalculationNotNeeded(
+                Resource.ResourceType.cpu, new ArrayList<>(), new ArrayList<>()));
+        Assert.assertFalse(resourceLimitManager.isTaggedResourceCountRecalculationNotNeeded(
+                Resource.ResourceType.cpu, List.of("h1", "h2"), new ArrayList<>()));
+    }
+
+    @Test
+    public void testAddTaggedResourceLimits() {
+        List<ResourceLimitVO> limits = new ArrayList<>();
+        resourceLimitManager.addTaggedResourceLimits(limits, null, hostTags, Resource.ResourceOwnerType.Account, 1L);
+        Assert.assertTrue(CollectionUtils.isEmpty(limits));
+        resourceLimitManager.addTaggedResourceLimits(limits, List.of(Resource.ResourceType.cpu), null, Resource.ResourceOwnerType.Account, 1L);
+        Assert.assertTrue(CollectionUtils.isEmpty(limits));
+        limits = new ArrayList<>();
+        limits.add(Mockito.mock(ResourceLimitVO.class));
+        int size = limits.size();
+        AccountVO account = Mockito.mock(AccountVO.class);
+        Mockito.when(account.getId()).thenReturn(1L);
+        Mockito.when(accountDao.findById(1L)).thenReturn(account);
+        Mockito.when(accountManager.isRootAdmin(1L)).thenReturn(true);
+        resourceLimitManager.addTaggedResourceLimits(limits, List.of(Resource.ResourceType.cpu), hostTags, Resource.ResourceOwnerType.Account, 1L);
+        Assert.assertEquals(size + hostTags.size(), limits.size());
+    }
+
+    @Test
+    public void testFindCorrectResourceLimitForAccount() {
+        AccountVO account = Mockito.mock(AccountVO.class);
+        Mockito.when(account.getId()).thenReturn(1L);
+        Mockito.when(accountManager.isRootAdmin(1L)).thenReturn(true);
+        long result = resourceLimitManager.findCorrectResourceLimitForAccount(account, Resource.ResourceType.cpu, hostTags.get(0));
+        Assert.assertEquals(Resource.RESOURCE_UNLIMITED, result);
+
+        Mockito.when(accountManager.isRootAdmin(1L)).thenReturn(false);
+        ResourceLimitVO limit = new ResourceLimitVO();
+        limit.setMax(10L);
+        Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(1L, Resource.ResourceOwnerType.Account, Resource.ResourceType.cpu, hostTags.get(0))).thenReturn(limit);
+        result = resourceLimitManager.findCorrectResourceLimitForAccount(account, Resource.ResourceType.cpu, hostTags.get(0));
+        Assert.assertEquals(10L, result);
+
+        long defaultAccountCpuMax = 25L;
+        Map<String, Long> accountResourceLimitMap = new HashMap<>();
+        accountResourceLimitMap.put(Resource.ResourceType.cpu.name(), defaultAccountCpuMax);
+        resourceLimitManager.accountResourceLimitMap = accountResourceLimitMap;
+        Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(1L, Resource.ResourceOwnerType.Account, Resource.ResourceType.cpu, hostTags.get(0))).thenReturn(null);
+        result = resourceLimitManager.findCorrectResourceLimitForAccount(account, Resource.ResourceType.cpu, hostTags.get(0));
+        Assert.assertEquals(defaultAccountCpuMax, result);
+    }
+
+    @Test
+    public void testFindCorrectResourceLimitForAccountId1() {
+//        long accountId = 1L;
+//        Mockito.when(accountManager.isRootAdmin(accountId)).thenReturn(true);
+//        long result = resourceLimitManager.findCorrectResourceLimitForAccount(accountId, null, Resource.ResourceType.cpu);
+//        Assert.assertEquals(Resource.RESOURCE_UNLIMITED, result);
+//
+//        accountId = 2L;
+//        Mockito.when(accountManager.isRootAdmin(accountId)).thenReturn(false);
+//        Long limit = 100L;
+//        long result = resourceLimitManager.findCorrectResourceLimitForAccount(accountId, limit, Resource.ResourceType.cpu);
+//        Assert.assertEquals(limit.longValue(), result);
+//
+//        long defaultAccountCpuMax = 25L;
+//        Mockito.when(accountManager.isRootAdmin(accountId)).thenReturn(false);
+//        Map<String, Long> accountResourceLimitMap = new HashMap<>();
+//        accountResourceLimitMap.put(Resource.ResourceType.cpu.name(), defaultAccountCpuMax);
+//        resourceLimitManager.accountResourceLimitMap = accountResourceLimitMap;
+//        result = resourceLimitManager.findCorrectResourceLimitForAccount(accountId, null, Resource.ResourceType.cpu);
+//        Assert.assertEquals(defaultAccountCpuMax, result);
+    }
+
+    @Test
+    public void testFindCorrectResourceLimitForDomain() {
+        DomainVO domain = Mockito.mock(DomainVO.class);
+        Mockito.when(domain.getId()).thenReturn(1L);
+        long result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.cpu, hostTags.get(0));
+        Assert.assertEquals(Resource.RESOURCE_UNLIMITED, result);
+
+        Mockito.when(domain.getId()).thenReturn(2L);
+        Mockito.when(domain.getParent()).thenReturn(null);
+        ResourceLimitVO limit = new ResourceLimitVO();
+        limit.setMax(100L);
+        Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(2L, Resource.ResourceOwnerType.Domain, Resource.ResourceType.cpu, hostTags.get(0))).thenReturn(limit);
+        result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.cpu, hostTags.get(0));
+        Assert.assertEquals(100L, result);
+
+        Mockito.when(domain.getId()).thenReturn(3L);
+        DomainVO parentDomain = Mockito.mock(DomainVO.class);
+        Mockito.when(domain.getParent()).thenReturn(5L);
+        Mockito.when(domainDao.findById(5L)).thenReturn(parentDomain);
+        limit = new ResourceLimitVO();
+        limit.setMax(200L);
+        Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(3L, Resource.ResourceOwnerType.Domain, Resource.ResourceType.cpu, hostTags.get(0))).thenReturn(null);
+        Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(5L, Resource.ResourceOwnerType.Domain, Resource.ResourceType.cpu, hostTags.get(0))).thenReturn(limit);
+        result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.cpu, hostTags.get(0));
+        Assert.assertEquals(200L, result);
+
+        long defaultDomainCpuMax = 250L;
+        Mockito.when(domain.getId()).thenReturn(4L);
+        Mockito.when(domain.getParent()).thenReturn(null);
+        Map<String, Long> domainResourceLimitMap = new HashMap<>();
+        domainResourceLimitMap.put(Resource.ResourceType.cpu.name(), defaultDomainCpuMax);
+        resourceLimitManager.domainResourceLimitMap = domainResourceLimitMap;
+        Mockito.when(resourceLimitDao.findByOwnerIdAndTypeAndTag(4L, Resource.ResourceOwnerType.Domain, Resource.ResourceType.cpu, hostTags.get(0))).thenReturn(null);
+        result = resourceLimitManager.findCorrectResourceLimitForDomain(domain, Resource.ResourceType.cpu, hostTags.get(0));
+        Assert.assertEquals(defaultDomainCpuMax, result);
+    }
+
+    @Test
+    public void testCheckResourceLimitWithTag() {
+        AccountVO account = Mockito.mock(AccountVO.class);
+        Mockito.when(account.getId()).thenReturn(1L);
+        Mockito.when(accountManager.isRootAdmin(1L)).thenReturn(true);
+        try {
+            resourceLimitManager.checkResourceLimitWithTag(account, Resource.ResourceType.cpu, hostTags.get(0), 1);
+        } catch (ResourceAllocationException e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testCheckResourceLimitWithTagNonAdmin() throws ResourceAllocationException {
+        AccountVO account = Mockito.mock(AccountVO.class);
+        Mockito.when(account.getId()).thenReturn(1L);
+        Mockito.when(accountManager.isRootAdmin(1L)).thenReturn(false);
+        Mockito.doReturn(new ArrayList<ResourceLimitVO>()).when(resourceLimitManager).lockAccountAndOwnerDomainRows(Mockito.anyLong(), Mockito.any(Resource.ResourceType.class), Mockito.anyString());
+        Mockito.doNothing().when(resourceLimitManager).checkAccountResourceLimit(account, null, Resource.ResourceType.cpu, hostTags.get(0), 1);
+        Mockito.doNothing().when(resourceLimitManager).checkDomainResourceLimit(account, null, Resource.ResourceType.cpu, hostTags.get(0), 1);
+        try {
+            resourceLimitManager.checkResourceLimitWithTag(account, Resource.ResourceType.cpu, hostTags.get(0), 1);
+        } catch (ResourceAllocationException e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testCheckResourceLimitWithTagProject() throws ResourceAllocationException {
+        AccountVO account = Mockito.mock(AccountVO.class);
+        Mockito.when(account.getId()).thenReturn(1L);
+        Mockito.when(account.getType()).thenReturn(Account.Type.PROJECT);
+        Mockito.when(accountManager.isRootAdmin(1L)).thenReturn(false);
+        ProjectVO projectVO = Mockito.mock(ProjectVO.class);
+        Mockito.when(projectDao.findByProjectAccountId(Mockito.anyLong())).thenReturn(projectVO);
+        Mockito.doReturn(new ArrayList<ResourceLimitVO>()).when(resourceLimitManager).lockAccountAndOwnerDomainRows(Mockito.anyLong(), Mockito.any(Resource.ResourceType.class), Mockito.anyString());
+        Mockito.doNothing().when(resourceLimitManager).checkAccountResourceLimit(account, projectVO, Resource.ResourceType.cpu, hostTags.get(0), 1);
+        Mockito.doNothing().when(resourceLimitManager).checkDomainResourceLimit(account, projectVO, Resource.ResourceType.cpu, hostTags.get(0), 1);
+        try {
+            resourceLimitManager.checkResourceLimitWithTag(account, Resource.ResourceType.cpu, hostTags.get(0), 1);
+        } catch (ResourceAllocationException e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testRemoveResourceLimitAndCountForNonMatchingTags() {
+        resourceLimitManager.removeResourceLimitAndCountForNonMatchingTags(1L, Resource.ResourceOwnerType.Account, hostTags, storageTags);
+        Mockito.verify(resourceLimitDao, Mockito.times(1))
+                .removeResourceLimitsForNonMatchingTags(1L, Resource.ResourceOwnerType.Account, ResourceLimitService.HostTagsSupportingTypes, hostTags);
+        Mockito.verify(resourceLimitDao, Mockito.times(1))
+                .removeResourceLimitsForNonMatchingTags(1L, Resource.ResourceOwnerType.Account, ResourceLimitService.StorageTagsSupportingTypes, storageTags);
+        Mockito.verify(resourceCountDao, Mockito.times(1))
+                .removeResourceCountsForNonMatchingTags(1L, Resource.ResourceOwnerType.Account, ResourceLimitService.HostTagsSupportingTypes, hostTags);
+        Mockito.verify(resourceCountDao, Mockito.times(1))
+                .removeResourceCountsForNonMatchingTags(1L, Resource.ResourceOwnerType.Account, ResourceLimitService.StorageTagsSupportingTypes, storageTags);
+    }
+
+    @Test
+    public void testRecalculateAccountTaggedResourceCountNegative() {
+        List<ResourceCountVO> result = resourceLimitManager.recalculateAccountTaggedResourceCount(1L, Resource.ResourceType.network, hostTags, storageTags);
+        CollectionUtils.isEmpty(result);
+        result = resourceLimitManager.recalculateAccountTaggedResourceCount(1L, Resource.ResourceType.cpu, null, storageTags);
+        CollectionUtils.isEmpty(result);
+        result = resourceLimitManager.recalculateAccountTaggedResourceCount(1L, Resource.ResourceType.volume, hostTags, null);
+        CollectionUtils.isEmpty(result);
+    }
+
+    @Test
+    public void testRecalculateAccountTaggedResourceCountHostTypes() {
+        long accountId = 1L;
+        Resource.ResourceType type = Resource.ResourceType.cpu;
+        for (String tag: hostTags) {
+            Mockito.doReturn(10L).when(resourceLimitManager).recalculateAccountResourceCount(accountId, type, tag);
+        }
+        List<ResourceCountVO> result = resourceLimitManager.recalculateAccountTaggedResourceCount(accountId, type, hostTags, storageTags);
+        Assert.assertEquals(hostTags.size(), result.size());
+    }
+
+    @Test
+    public void testRecalculateAccountTaggedResourceCountStorageTypes() {
+        long accountId = 1L;
+        Resource.ResourceType type = Resource.ResourceType.volume;
+        for (String tag: storageTags) {
+            Mockito.doReturn(10L).when(resourceLimitManager).recalculateAccountResourceCount(accountId, type, tag);
+        }
+        List<ResourceCountVO> result = resourceLimitManager.recalculateAccountTaggedResourceCount(accountId, type, hostTags, storageTags);
+        Assert.assertEquals(storageTags.size(), result.size());
+    }
+
+    @Test
+    public void testRecalculateDomainTaggedResourceCountNegative() {
+        List<ResourceCountVO> result = resourceLimitManager.recalculateDomainTaggedResourceCount(1L, Resource.ResourceType.network, hostTags, storageTags);
+        CollectionUtils.isEmpty(result);
+        result = resourceLimitManager.recalculateDomainTaggedResourceCount(1L, Resource.ResourceType.cpu, null, storageTags);
+        CollectionUtils.isEmpty(result);
+        result = resourceLimitManager.recalculateDomainTaggedResourceCount(1L, Resource.ResourceType.volume, hostTags, null);
+        CollectionUtils.isEmpty(result);
+    }
+
+    @Test
+    public void testRecalculateDomainTaggedResourceCountHostTypes() {
+        long domainId = 1L;
+        Resource.ResourceType type = Resource.ResourceType.cpu;
+        for (String tag: hostTags) {
+            Mockito.doReturn(10L).when(resourceLimitManager).recalculateDomainResourceCount(domainId, type, tag);
+        }
+        List<ResourceCountVO> result = resourceLimitManager.recalculateDomainTaggedResourceCount(domainId, type, hostTags, storageTags);
+        Assert.assertEquals(hostTags.size(), result.size());
+    }
+
+    @Test
+    public void testRecalculateDomainTaggedResourceCountStorageTypes() {
+        long domainId = 1L;
+        Resource.ResourceType type = Resource.ResourceType.volume;
+        for (String tag: storageTags) {
+            Mockito.doReturn(10L).when(resourceLimitManager).recalculateDomainResourceCount(domainId, type, tag);
         }
+        List<ResourceCountVO> result = resourceLimitManager.recalculateDomainTaggedResourceCount(domainId, type, hostTags, storageTags);
+        Assert.assertEquals(storageTags.size(), result.size());
+    }
+
+    @Test
+    public void testRecalculateResourceCount() {
+        Long accountId = 1L;
+        Long domainId = null;
+        Integer typeId = Resource.ResourceType.user_vm.getOrdinal();
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager).recalculateResourceCount(accountId, domainId, typeId, null);
+        resourceLimitManager.recalculateResourceCount(accountId, domainId, typeId);
+        Mockito.verify(resourceLimitManager, Mockito.times(1)).recalculateResourceCount(accountId, domainId, typeId, null);
+    }
+
+    @Test
+    public void testGetVmsWithAccountAndTagNoTag() throws NoSuchFieldException, IllegalAccessException {
+        overrideDefaultConfigValue(VirtualMachineManager.ResourceCountRunningVMsonly, "_defaultValue", "false");
+        List<VirtualMachine.State> states = Arrays.asList(VirtualMachine.State.Destroyed, VirtualMachine.State.Error, VirtualMachine.State.Expunging);
+        List<UserVmJoinVO> vmList = List.of(Mockito.mock(UserVmJoinVO.class));
+        Mockito.when(userVmJoinDao.listByAccountServiceOfferingTemplateAndNotInState(1L, states, null, null)).thenReturn(vmList);
+        List<UserVmJoinVO> result = resourceLimitManager.getVmsWithAccountAndTag(1L, null);
+        Assert.assertEquals(vmList.size(), result.size());
+    }
+
+    @Test
+    public void testGetVmsWithAccountAndTagNegative() {
+        String tag = hostTags.get(0);
+        Mockito.when(serviceOfferingDao.listByHostTag(tag)).thenReturn(null);
+        Mockito.when(vmTemplateDao.listByTemplateTag(tag)).thenReturn(null);
+        List<UserVmJoinVO> result = resourceLimitManager.getVmsWithAccountAndTag(1L, hostTags.get(0));
+        Assert.assertTrue(CollectionUtils.isEmpty(result));
+    }
+
+    @Test
+    public void testGetVmsWithAccountAndTag() throws NoSuchFieldException, IllegalAccessException {
+        overrideDefaultConfigValue(VirtualMachineManager.ResourceCountRunningVMsonly, "_defaultValue", "true");
+        String tag = hostTags.get(0);
+        ServiceOfferingVO serviceOfferingVO = Mockito.mock(ServiceOfferingVO.class);
+        Mockito.when(serviceOfferingVO.getId()).thenReturn(1L);
+        VMTemplateVO templateVO = Mockito.mock(VMTemplateVO.class);
+        Mockito.when(templateVO.getId()).thenReturn(1L);
+        Mockito.when(serviceOfferingDao.listByHostTag(tag)).thenReturn(List.of(serviceOfferingVO));
+        Mockito.when(vmTemplateDao.listByTemplateTag(tag)).thenReturn(List.of(templateVO));
+        List<UserVmJoinVO> vmList = List.of(Mockito.mock(UserVmJoinVO.class));
+        Mockito.when(userVmJoinDao.listByAccountServiceOfferingTemplateAndNotInState(Mockito.anyLong(), Mockito.anyList(), Mockito.anyList(), Mockito.anyList())).thenReturn(vmList);
+        List<UserVmJoinVO> result = resourceLimitManager.getVmsWithAccountAndTag(1L, tag);
+        Assert.assertEquals(vmList.size(), result.size());
+    }
+
+    @Test
+    public void testGetVmsWithAccount() {
+        long accountId = 1L;
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager).getVmsWithAccountAndTag(accountId, null);
+        resourceLimitManager.getVmsWithAccount(accountId);
+        Mockito.verify(resourceLimitManager, Mockito.times(1)).getVmsWithAccountAndTag(accountId, null);
+    }
+
+    @Test
+    public void testGetVolumesWithAccountAndTag() {
+        long accountId = 1L;
+        String tag = "tag";
+        Mockito.when(diskOfferingDao.listByStorageTag(tag)).thenReturn(new ArrayList<>());
+        Assert.assertTrue(CollectionUtils.isEmpty(resourceLimitManager.getVolumesWithAccountAndTag(accountId, tag)));
+
+        Mockito.when(diskOfferingDao.listByStorageTag(tag)).thenReturn(List.of(Mockito.mock(DiskOfferingVO.class)));
+        Mockito.when(vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId)).thenReturn(List.of(1L));
+        Mockito.when(volumeDao.listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(
+                Mockito.anyLong(), Mockito.anyList(), Mockito.anyList()))
+                .thenReturn(List.of(Mockito.mock(VolumeVO.class)));
+        List<VolumeVO> result = resourceLimitManager.getVolumesWithAccountAndTag(accountId, tag);
+        Assert.assertTrue(CollectionUtils.isNotEmpty(resourceLimitManager.getVolumesWithAccountAndTag(accountId, tag)));
+        Assert.assertEquals(1, result.size());
+    }
+
+    @Test
+    public void testCalculateVmCountForAccount() {
+        long accountId = 1L;
+        String tag = null;
+        Mockito.when(userVmDao.countAllocatedVMsForAccount(Mockito.eq(accountId), Mockito.anyBoolean()))
+                .thenReturn(1L);
+        Assert.assertEquals(1L, resourceLimitManager.calculateVmCountForAccount(accountId, tag));
+
+        tag = "";
+        Mockito.when(userVmDao.countAllocatedVMsForAccount(Mockito.eq(accountId), Mockito.anyBoolean()))
+                .thenReturn(2L);
+        Assert.assertEquals(2L, resourceLimitManager.calculateVmCountForAccount(accountId, tag));
+
+        tag = "tag";
+        Mockito.doReturn(List.of(UserVmJoinVO.class)).when(resourceLimitManager).getVmsWithAccountAndTag(accountId, tag);
+        Assert.assertEquals(1L, resourceLimitManager.calculateVmCountForAccount(accountId, tag));
+    }
+
+    @Test
+    public void testCalculateVolumeCountForAccount() {
+        long accountId = 1L;
+        String tag = null;
+        Mockito.when(vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId))
+                .thenReturn(List.of(1L));
+        Mockito.when(volumeDao.countAllocatedVolumesForAccount(accountId)).thenReturn(3L);
+        Assert.assertEquals(2L, resourceLimitManager.calculateVolumeCountForAccount(accountId, tag));
+
+        tag = "";
+        Mockito.when(volumeDao.countAllocatedVolumesForAccount(accountId)).thenReturn(2L);
+        Assert.assertEquals(1L, resourceLimitManager.calculateVolumeCountForAccount(accountId, tag));
+
+        tag = "tag";
+        Mockito.doReturn(List.of(VolumeVO.class)).when(resourceLimitManager).getVolumesWithAccountAndTag(accountId, tag);
+        Assert.assertEquals(1L, resourceLimitManager.calculateVolumeCountForAccount(accountId, tag));
+    }
+
+    @Test
+    public void testCalculateVmCpuCountForAccount() {
+        long accountId = 1L;
+        String tag = null;
+        Mockito.doReturn(1L).when(resourceLimitManager).countCpusForAccount(accountId);
+        Assert.assertEquals(1L, resourceLimitManager.calculateVmCpuCountForAccount(accountId, tag));
+
+        tag = "";
+        Mockito.doReturn(2L).when(resourceLimitManager).countCpusForAccount(accountId);
+        Assert.assertEquals(2L, resourceLimitManager.calculateVmCpuCountForAccount(accountId, tag));
+
+        tag = "tag";
+        UserVmJoinVO vm = Mockito.mock(UserVmJoinVO.class);
+        int cpu = 2;
+        Mockito.when(vm.getCpu()).thenReturn(cpu);
+        List<UserVmJoinVO> vms = List.of(vm, vm);
+        Mockito.doReturn(vms).when(resourceLimitManager).getVmsWithAccountAndTag(accountId, tag);
+        Assert.assertEquals(vms.size() * cpu, resourceLimitManager.calculateVmCpuCountForAccount(accountId, tag));
+    }
+
+    @Test
+    public void testCalculateVmMemoryCountForAccount() {
+        long accountId = 1L;
+        String tag = null;
+        Mockito.doReturn(1024L).when(resourceLimitManager).calculateMemoryForAccount(accountId);
+        Assert.assertEquals(1024L, resourceLimitManager.calculateVmMemoryCountForAccount(accountId, tag));
+
+        tag = "";
+        Mockito.doReturn(2048L).when(resourceLimitManager).calculateMemoryForAccount(accountId);
+        Assert.assertEquals(2048L, resourceLimitManager.calculateVmMemoryCountForAccount(accountId, tag));
+
+        tag = "tag";
+        UserVmJoinVO vm = Mockito.mock(UserVmJoinVO.class);
+        int memory = 1024;
+        Mockito.when(vm.getRamSize()).thenReturn(memory);
+        List<UserVmJoinVO> vms = List.of(vm, vm);
+        Mockito.doReturn(vms).when(resourceLimitManager).getVmsWithAccountAndTag(accountId, tag);
+        Assert.assertEquals(vms.size() * memory, resourceLimitManager.calculateVmMemoryCountForAccount(accountId, tag));
+    }
+
+    @Test
+    public void testCalculatePrimaryStorageForAccount() {
+        long accountId = 1L;
+        String tag = null;
+        Mockito.when(vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId))
+                .thenReturn(List.of(1L));
+        Mockito.when(volumeDao.primaryStorageUsedForAccount(Mockito.eq(accountId), Mockito.anyList())).thenReturn(100L);
+        Assert.assertEquals(100L, resourceLimitManager.calculatePrimaryStorageForAccount(accountId, tag));
+
+        tag = "";
+        Mockito.when(volumeDao.primaryStorageUsedForAccount(Mockito.eq(accountId), Mockito.anyList())).thenReturn(200L);
+        Assert.assertEquals(200L, resourceLimitManager.calculatePrimaryStorageForAccount(accountId, tag));
+
+        tag = "tag";
+        VolumeVO vol = Mockito.mock(VolumeVO.class);
+        long size = 1024;
+        Mockito.when(vol.getSize()).thenReturn(size);
+        List<VolumeVO> vols = List.of(vol, vol);
+        Mockito.doReturn(vols).when(resourceLimitManager).getVolumesWithAccountAndTag(accountId, tag);
+        Assert.assertEquals(vols.size() * size, resourceLimitManager.calculatePrimaryStorageForAccount(accountId, tag));
+    }
+
+    @Test
+    public void testGetResourceCount() {
+        long accountId = 1L;
+        Account account = Mockito.mock(Account.class);
+        Mockito.when(account.getId()).thenReturn(accountId);
+        resourceLimitManager.getResourceCount(account, Resource.ResourceType.user_vm, "tag");
+        Mockito.verify(resourceCountDao, Mockito.times(1))
+                .getResourceCount(accountId, Resource.ResourceOwnerType.Account, Resource.ResourceType.user_vm, "tag");
+    }
+
+    @Test
+    public void testGetTaggedResourceLimitAndCountResponse() {
+        long accountId = 1L;
+        Account account = Mockito.mock(Account.class);
+        Mockito.when(account.getId()).thenReturn(accountId);
+        Long accountLimit = 10L;
+        Mockito.doReturn(accountLimit).when(resourceLimitManager)
+                .findCorrectResourceLimitForAccount(Mockito.any(Account.class), Mockito.any(Resource.ResourceType.class), Mockito.anyString());
+        Long accountCount = 2L;
+        ResourceCountVO resourceCountVO = Mockito.mock(ResourceCountVO.class);
+        Mockito.when(resourceCountVO.getCount()).thenReturn(accountCount);
+        Mockito.when(resourceCountDao.findByOwnerAndTypeAndTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceOwnerType.Account), Mockito.any(Resource.ResourceType.class),
+                Mockito.anyString())).thenReturn(resourceCountVO);
+
+        TaggedResourceLimitAndCountResponse res = resourceLimitManager.getTaggedResourceLimitAndCountResponse(account,
+                null, Resource.ResourceOwnerType.Account, Resource.ResourceType.user_vm, "tag");
+        Assert.assertEquals(accountLimit, res.getLimit());
+        Assert.assertEquals(accountCount, res.getTotal());
+        Long available = accountLimit - accountCount;
+        Assert.assertEquals(available, res.getAvailable());
+
+
+        long domainId = 1L;
+        Domain domain = Mockito.mock(Domain.class);
+        Mockito.when(domain.getId()).thenReturn(domainId);
+        Long domainLimit = 20L;
+        Mockito.doReturn(domainLimit).when(resourceLimitManager)
+                .findCorrectResourceLimitForDomain(Mockito.any(Domain.class), Mockito.any(Resource.ResourceType.class), Mockito.anyString());
+        Long domainCount = 4L;
+        Mockito.when(resourceCountVO.getCount()).thenReturn(domainCount);
+        Mockito.when(resourceCountDao.findByOwnerAndTypeAndTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceOwnerType.Domain), Mockito.any(Resource.ResourceType.class),
+                Mockito.anyString())).thenReturn(resourceCountVO);
+        res = resourceLimitManager.getTaggedResourceLimitAndCountResponse(null,
+                domain, Resource.ResourceOwnerType.Domain, Resource.ResourceType.user_vm, "tag");
+        Assert.assertEquals(domainLimit, res.getLimit());
+        Assert.assertEquals(domainCount, res.getTotal());
+        available = domainLimit - domainCount;
+        Assert.assertEquals(available, res.getAvailable());
+    }
+
+    @Test
+    public void testUpdateTaggedResourceLimitsAndCountsForAccounts() {
+        String tag = "tag";
+        resourceLimitManager.updateTaggedResourceLimitsAndCountsForAccounts(
+                List.of(Mockito.mock(AccountResponse.class)), "tag");
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .updateTaggedResourceLimitsAndCountsForAccountsOrDomains(Mockito.anyList(),
+                        Mockito.eq(null), Mockito.eq(tag));
+    }
+
+    @Test
+    public void updateTaggedResourceLimitsAndCountsForDomains() {
+        String tag = "tag";
+        resourceLimitManager.updateTaggedResourceLimitsAndCountsForDomains(
+                List.of(Mockito.mock(DomainResponse.class)), "tag");
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .updateTaggedResourceLimitsAndCountsForAccountsOrDomains(Mockito.eq(null),
+                        Mockito.anyList(), Mockito.eq(tag));
+    }
+
+    private void mockCheckResourceLimitWithTag() throws ResourceAllocationException {
+        Mockito.doNothing().when(resourceLimitManager).checkResourceLimitWithTag(
+                Mockito.any(Account.class), Mockito.any(Resource.ResourceType.class), Mockito.anyString());
+        Mockito.doNothing().when(resourceLimitManager).checkResourceLimitWithTag(
+                Mockito.any(Account.class), Mockito.any(Resource.ResourceType.class), Mockito.anyString(), Mockito.anyLong());
+    }
+
+    private void mockIncrementResourceCountWithTag() {
+        Mockito.doNothing().when(resourceLimitManager).incrementResourceCountWithTag(
+                Mockito.anyLong(), Mockito.any(Resource.ResourceType.class), Mockito.anyString());
+        Mockito.doNothing().when(resourceLimitManager).incrementResourceCountWithTag(
+                Mockito.anyLong(), Mockito.any(Resource.ResourceType.class), Mockito.anyString(), Mockito.anyLong());
+    }
+
+    private void mockDecrementResourceCountWithTag() {
+        Mockito.doNothing().when(resourceLimitManager).decrementResourceCountWithTag(
+                Mockito.anyLong(), Mockito.any(Resource.ResourceType.class), Mockito.anyString());
+        Mockito.doNothing().when(resourceLimitManager).decrementResourceCountWithTag(
+                Mockito.anyLong(), Mockito.any(Resource.ResourceType.class), Mockito.anyString(), Mockito.anyLong());
+    }
+
+    @Test
+    public void testCheckVolumeResourceCount() throws ResourceAllocationException {
+        Account account = Mockito.mock(Account.class);
+        String tag = "tag";
+        long delta = 10L;
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        resourceLimitManager.incrementVolumeResourceCount(1L, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.never()).checkResourceLimitWithTag(Mockito.any(Account.class),
+                Mockito.eq(Resource.ResourceType.volume), Mockito.anyString());
+        Mockito.verify(resourceLimitManager, Mockito.never()).checkResourceLimitWithTag(Mockito.any(Account.class),
+                Mockito.eq(Resource.ResourceType.primary_storage), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        mockCheckResourceLimitWithTag();
+        resourceLimitManager.checkVolumeResourceLimit(account, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.times(1)).checkResourceLimitWithTag(
+                account, Resource.ResourceType.volume, tag);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .checkResourceLimitWithTag(account, Resource.ResourceType.primary_storage, tag, 10L);
+    }
+
+    @Test
+    public void testIncrementVolumeResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        long delta = 10L;
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        resourceLimitManager.incrementVolumeResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.volume), Mockito.anyString());
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.primary_storage), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        mockIncrementResourceCountWithTag();
+        resourceLimitManager.incrementVolumeResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.times(1)).incrementResourceCountWithTag(
+                1L, Resource.ResourceType.volume, tag);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .incrementResourceCountWithTag(accountId, Resource.ResourceType.primary_storage, tag, delta);
+    }
+
+    @Test
+    public void testDecrementVolumeResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        long delta = 10L;
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        resourceLimitManager.decrementVolumeResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.volume), Mockito.anyString());
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.primary_storage), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        mockDecrementResourceCountWithTag();
+        resourceLimitManager.decrementVolumeResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.times(1)).decrementResourceCountWithTag(
+                1L, Resource.ResourceType.volume, tag);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .decrementResourceCountWithTag(accountId, Resource.ResourceType.primary_storage, tag, delta);
+    }
+
+    @Test
+    public void testIncrementVolumePrimaryStorageResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        long delta = 10L;
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        resourceLimitManager.incrementVolumePrimaryStorageResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.primary_storage), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        mockIncrementResourceCountWithTag();
+        resourceLimitManager.incrementVolumePrimaryStorageResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .incrementResourceCountWithTag(accountId, Resource.ResourceType.primary_storage, tag, delta);
+    }
+
+    @Test
+    public void testDecrementVolumePrimaryStorageResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        long delta = 10L;
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        resourceLimitManager.decrementVolumePrimaryStorageResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.primary_storage), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitStorageTagsForResourceCountOperation(Mockito.anyBoolean(), Mockito.any(DiskOffering.class));
+        mockDecrementResourceCountWithTag();
+        resourceLimitManager.decrementVolumePrimaryStorageResourceCount(accountId, false, delta, Mockito.mock(DiskOffering.class));
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .decrementResourceCountWithTag(accountId, Resource.ResourceType.primary_storage, tag, delta);
+    }
+
+    @Test
+    public void testIncrementVmResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        resourceLimitManager.incrementVmResourceCount(accountId, false,
+                Mockito.mock(ServiceOffering.class), Mockito.mock(VirtualMachineTemplate.class));
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.user_vm), Mockito.anyString());
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.cpu), Mockito.anyString(), Mockito.anyLong());
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.memory), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        mockIncrementResourceCountWithTag();
+        ServiceOffering offering = Mockito.mock(ServiceOffering.class);
+        int cpu = 1;
+        Mockito.when(offering.getCpu()).thenReturn(cpu);
+        int memory = 1024;
+        Mockito.when(offering.getRamSize()).thenReturn(memory);
+        resourceLimitManager.incrementVmResourceCount(accountId, false,
+                offering, Mockito.mock(VirtualMachineTemplate.class));
+        Mockito.verify(resourceLimitManager, Mockito.times(1)).incrementResourceCountWithTag(
+                1L, Resource.ResourceType.user_vm, tag);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .incrementResourceCountWithTag(accountId, Resource.ResourceType.cpu, tag, Long.valueOf(cpu));
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .incrementResourceCountWithTag(accountId, Resource.ResourceType.memory, tag, Long.valueOf(memory));
+    }
+
+    @Test
+    public void testDecrementVmResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        resourceLimitManager.decrementVmResourceCount(accountId, false,
+                Mockito.mock(ServiceOffering.class), Mockito.mock(VirtualMachineTemplate.class));
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.user_vm), Mockito.anyString());
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.cpu), Mockito.anyString(), Mockito.anyLong());
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.memory), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        mockDecrementResourceCountWithTag();
+        ServiceOffering offering = Mockito.mock(ServiceOffering.class);
+        int cpu = 1;
+        Mockito.when(offering.getCpu()).thenReturn(cpu);
+        int memory = 1024;
+        Mockito.when(offering.getRamSize()).thenReturn(memory);
+        resourceLimitManager.decrementVmResourceCount(accountId, false,
+                offering, Mockito.mock(VirtualMachineTemplate.class));
+        Mockito.verify(resourceLimitManager, Mockito.times(1)).decrementResourceCountWithTag(
+                1L, Resource.ResourceType.user_vm, tag);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .decrementResourceCountWithTag(accountId, Resource.ResourceType.cpu, tag, Long.valueOf(cpu));
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .decrementResourceCountWithTag(accountId, Resource.ResourceType.memory, tag, Long.valueOf(memory));
+    }
+
+    @Test
+    public void testIncrementVmCpuResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        resourceLimitManager.incrementVmCpuResourceCount(accountId, false,
+                Mockito.mock(ServiceOffering.class), Mockito.mock(VirtualMachineTemplate.class), null);
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.cpu), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        mockIncrementResourceCountWithTag();
+        ServiceOffering offering = Mockito.mock(ServiceOffering.class);
+        Long cpu = 2L;
+        resourceLimitManager.incrementVmCpuResourceCount(accountId, false,
+                offering, Mockito.mock(VirtualMachineTemplate.class), cpu);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .incrementResourceCountWithTag(accountId, Resource.ResourceType.cpu, tag, cpu);
+    }
+
+    @Test
+    public void testDecrementVmCpuResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        resourceLimitManager.decrementVmCpuResourceCount(accountId, false,
+                Mockito.mock(ServiceOffering.class), Mockito.mock(VirtualMachineTemplate.class), null);
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.cpu), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        mockDecrementResourceCountWithTag();
+        ServiceOffering offering = Mockito.mock(ServiceOffering.class);
+        int cpu = 1;
+        Mockito.when(offering.getCpu()).thenReturn(cpu);
+        resourceLimitManager.decrementVmCpuResourceCount(accountId, false,
+                offering, Mockito.mock(VirtualMachineTemplate.class), null);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .decrementResourceCountWithTag(accountId, Resource.ResourceType.cpu, tag, Long.valueOf(cpu));
+    }
+
+    @Test
+    public void testIncrementVmMemoryResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        resourceLimitManager.incrementVmMemoryResourceCount(accountId, false,
+                Mockito.mock(ServiceOffering.class), Mockito.mock(VirtualMachineTemplate.class), null);
+        Mockito.verify(resourceLimitManager, Mockito.never()).incrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.cpu), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        mockIncrementResourceCountWithTag();
+        ServiceOffering offering = Mockito.mock(ServiceOffering.class);
+        long memory = 1024L;
+        resourceLimitManager.incrementVmMemoryResourceCount(accountId, false,
+                offering, Mockito.mock(VirtualMachineTemplate.class), memory);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .incrementResourceCountWithTag(accountId, Resource.ResourceType.memory, tag, memory);
+    }
+
+    @Test
+    public void testDecrementVmMemoryResourceCount() {
+        long accountId = 1L;
+        String tag = "tag";
+        Mockito.doReturn(new ArrayList<>()).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        resourceLimitManager.decrementVmMemoryResourceCount(accountId, false,
+                Mockito.mock(ServiceOffering.class), Mockito.mock(VirtualMachineTemplate.class), null);
+        Mockito.verify(resourceLimitManager, Mockito.never()).decrementResourceCountWithTag(Mockito.anyLong(),
+                Mockito.eq(Resource.ResourceType.memory), Mockito.anyString(), Mockito.anyLong());
+
+        Mockito.doReturn(List.of(tag)).when(resourceLimitManager)
+                .getResourceLimitHostTagsForResourceCountOperation(Mockito.anyBoolean(),
+                        Mockito.any(ServiceOffering.class), Mockito.any(VirtualMachineTemplate.class));
+        mockDecrementResourceCountWithTag();
+        ServiceOffering offering = Mockito.mock(ServiceOffering.class);
+        int memory = 1024;
+        Mockito.when(offering.getRamSize()).thenReturn(memory);
+        resourceLimitManager.decrementVmMemoryResourceCount(accountId, false,
+                offering, Mockito.mock(VirtualMachineTemplate.class), null);
+        Mockito.verify(resourceLimitManager, Mockito.times(1))
+                .decrementResourceCountWithTag(accountId, Resource.ResourceType.memory, tag, Long.valueOf(memory));
     }
 }
diff --git a/server/src/test/java/com/cloud/storage/StorageManagerImplTest.java b/server/src/test/java/com/cloud/storage/StorageManagerImplTest.java
index ba5f2baf932..18643d0711a 100644
--- a/server/src/test/java/com/cloud/storage/StorageManagerImplTest.java
+++ b/server/src/test/java/com/cloud/storage/StorageManagerImplTest.java
@@ -16,13 +16,15 @@
 // under the License.
 package com.cloud.storage;
 
-import com.cloud.agent.api.StoragePoolInfo;
-import com.cloud.exception.ConnectionException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.host.Host;
-import com.cloud.storage.dao.VolumeDao;
-import com.cloud.vm.VMInstanceVO;
-import com.cloud.vm.dao.VMInstanceDao;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
+import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.commons.collections.MapUtils;
@@ -34,11 +36,26 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.Spy;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.StoragePoolInfo;
+import com.cloud.capacity.CapacityManager;
+import com.cloud.dc.VsphereStoragePolicyVO;
+import com.cloud.dc.dao.VsphereStoragePolicyDao;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.ConnectionException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.OperationTimedoutException;
+import com.cloud.exception.StorageUnavailableException;
+import com.cloud.host.Host;
+import com.cloud.hypervisor.HypervisorGuruManager;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.utils.Pair;
+import com.cloud.vm.DiskProfile;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.dao.VMInstanceDao;
 
 @RunWith(MockitoJUnitRunner.class)
 public class StorageManagerImplTest {
@@ -48,6 +65,18 @@ public class StorageManagerImplTest {
 
     @Mock
     VMInstanceDao vmInstanceDao;
+    @Mock
+    PrimaryDataStoreDao storagePoolDao;
+    @Mock
+    CapacityManager capacityManager;
+    @Mock
+    DiskOfferingDetailsDao diskOfferingDetailsDao;
+    @Mock
+    VsphereStoragePolicyDao vsphereStoragePolicyDao;
+    @Mock
+    HypervisorGuruManager hvGuruMgr;
+    @Mock
+    AgentManager agentManager;
 
     @Spy
     @InjectMocks
@@ -206,4 +235,224 @@ public class StorageManagerImplTest {
             throw new RuntimeException(e);
         }
     }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsNullPoolIops() {
+        StoragePool pool = Mockito.mock(StoragePool.class);
+        Mockito.when(pool.getCapacityIops()).thenReturn(null);
+        List<Pair<Volume, DiskProfile>> list = List.of(new Pair<>(Mockito.mock(Volume.class), Mockito.mock(DiskProfile.class)));
+        Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughIops(100L, list, pool, false));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsSuccess() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(pool.getId()).thenReturn(1L);
+        Mockito.when(pool.getCapacityIops()).thenReturn(1000L);
+        Mockito.when(storagePoolDao.findById(1L)).thenReturn(pool);
+        Mockito.when(capacityManager.getUsedIops(pool)).thenReturn(500L);
+        List<Pair<Volume, DiskProfile>> list = List.of(new Pair<>(Mockito.mock(Volume.class), Mockito.mock(DiskProfile.class)));
+        Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughIops(100L, list, pool, true));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsNegative() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(pool.getId()).thenReturn(1L);
+        Mockito.when(pool.getCapacityIops()).thenReturn(550L);
+        Mockito.when(storagePoolDao.findById(1L)).thenReturn(pool);
+        Mockito.when(capacityManager.getUsedIops(pool)).thenReturn(500L);
+        List<Pair<Volume, DiskProfile>> list = List.of(new Pair<>(Mockito.mock(Volume.class), Mockito.mock(DiskProfile.class)));
+        Assert.assertFalse(storageManagerImpl.storagePoolHasEnoughIops(100L, list, pool, true));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsNullPool() {
+        Assert.assertFalse(storageManagerImpl.storagePoolHasEnoughIops(100L, null));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsNullRequestedIops() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        List<Long> iopsList = Arrays.asList(null, 0L);
+        for (Long iops : iopsList) {
+            Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughIops(iops, pool));
+        }
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsSuccess1() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.doReturn(true).when(storageManagerImpl).storagePoolHasEnoughIops(
+                Mockito.eq(100L), Mockito.anyList(), Mockito.eq(pool), Mockito.eq(false));
+        Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughIops(100L, pool));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsNoVolumesOrPool() {
+        List<Pair<Volume, DiskProfile>> list = new ArrayList<>();
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Assert.assertFalse(storageManagerImpl.storagePoolHasEnoughIops(list, pool));
+        list = List.of(new Pair<>(Mockito.mock(Volume.class), Mockito.mock(DiskProfile.class)));
+        Assert.assertFalse(storageManagerImpl.storagePoolHasEnoughIops(list, null));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsWithVolPoolNullIops() {
+        List<Pair<Volume, DiskProfile>> list = List.of(
+                new Pair<>(Mockito.mock(Volume.class), Mockito.mock(DiskProfile.class)));
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(pool.getCapacityIops()).thenReturn(null);
+        Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughIops(list, pool));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughIopsWithVolPoolCompare() {
+        Volume volume = Mockito.mock(Volume.class);
+        Mockito.when(volume.getDiskOfferingId()).thenReturn(1L);
+        Mockito.when(volume.getMinIops()).thenReturn(100L);
+        DiskProfile profile = Mockito.mock(DiskProfile.class);
+        Mockito.when(profile.getDiskOfferingId()).thenReturn(1L);
+        List<Pair<Volume, DiskProfile>> list = List.of(new Pair<>(volume, profile));
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.doReturn(true).when(storageManagerImpl)
+                .storagePoolHasEnoughIops(100L, list, pool, true);
+        Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughIops(list, pool));
+
+        Mockito.when(profile.getDiskOfferingId()).thenReturn(2L);
+        Mockito.when(profile.getMinIops()).thenReturn(200L);
+        Mockito.doReturn(false).when(storageManagerImpl)
+                .storagePoolHasEnoughIops(200L, list, pool, true);
+        Assert.assertFalse(storageManagerImpl.storagePoolHasEnoughIops(list, pool));
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughSpaceNullSize() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        List<Long> sizeList = Arrays.asList(null, 0L);
+        for (Long size : sizeList) {
+            Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughSpace(size, pool));
+        }
+    }
+
+    @Test
+    public void testStoragePoolHasEnoughSpaceCompare() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(pool.getId()).thenReturn(1L);
+        Mockito.when(storagePoolDao.findById(1L)).thenReturn(pool);
+        Mockito.when(capacityManager.getAllocatedPoolCapacity(pool, null)).thenReturn(2000L);
+        Mockito.doAnswer((Answer<Boolean>) invocationOnMock -> {
+            long total = invocationOnMock.getArgument(1);
+            long asking = invocationOnMock.getArgument(2);
+            return total > asking;
+        }).when(storageManagerImpl).checkPoolforSpace(Mockito.any(StoragePool.class),
+                Mockito.anyLong(), Mockito.anyLong());
+        Assert.assertTrue(storageManagerImpl.storagePoolHasEnoughSpace(1000L, pool));
+        Assert.assertFalse(storageManagerImpl.storagePoolHasEnoughSpace(2200L, pool));
+    }
+
+    @Test
+    public void testIsStoragePoolCompliantWithStoragePolicy() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(diskOfferingDetailsDao.getDetail(1L, ApiConstants.STORAGE_POLICY))
+                .thenReturn("policy");
+        try {
+            Mockito.doReturn(null)
+                    .when(storageManagerImpl).getCheckDatastorePolicyComplianceAnswer("policy", pool);
+            Assert.assertTrue(storageManagerImpl.isStoragePoolCompliantWithStoragePolicy(1L, pool));
+        } catch (StorageUnavailableException e) {
+            Assert.fail(e.getMessage());
+        }
+        try {
+            Mockito.doReturn(new com.cloud.agent.api.Answer(
+                    Mockito.mock(CheckDataStoreStoragePolicyComplainceCommand.class)))
+                    .when(storageManagerImpl).getCheckDatastorePolicyComplianceAnswer("policy", pool);
+            Assert.assertTrue(storageManagerImpl.isStoragePoolCompliantWithStoragePolicy(1L, pool));
+        } catch (StorageUnavailableException e) {
+            Assert.fail(e.getMessage());
+        }
+        try {
+            com.cloud.agent.api.Answer answer =
+                    new com.cloud.agent.api.Answer(Mockito.mock(CheckDataStoreStoragePolicyComplainceCommand.class),
+                            false, "");
+            Mockito.doReturn(answer)
+                    .when(storageManagerImpl).getCheckDatastorePolicyComplianceAnswer("policy", pool);
+            Assert.assertFalse(storageManagerImpl.isStoragePoolCompliantWithStoragePolicy(1L, pool));
+        } catch (StorageUnavailableException e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testGetCheckDatastorePolicyComplianceAnswerNullAnswer() {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        try {
+            Assert.assertNull(storageManagerImpl.getCheckDatastorePolicyComplianceAnswer(null, pool));
+            Assert.assertNull(storageManagerImpl.getCheckDatastorePolicyComplianceAnswer("", pool));
+        } catch (StorageUnavailableException e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+
+    @Test(expected = StorageUnavailableException.class)
+    public void testGetCheckDatastorePolicyComplianceAnswerNoHost() throws StorageUnavailableException {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(pool.getId()).thenReturn(1L);
+        Mockito.when(vsphereStoragePolicyDao.findById(Mockito.anyLong()))
+                .thenReturn(Mockito.mock(VsphereStoragePolicyVO.class));
+        Mockito.doReturn(new ArrayList<>()).when(storageManagerImpl).getUpHostsInPool(Mockito.anyLong());
+        storageManagerImpl.getCheckDatastorePolicyComplianceAnswer("1", pool);
+    }
+
+    @Test(expected = StorageUnavailableException.class)
+    public void testGetCheckDatastorePolicyComplianceAnswerAgentException() throws StorageUnavailableException {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(pool.getId()).thenReturn(1L);
+        VsphereStoragePolicyVO policy = Mockito.mock(VsphereStoragePolicyVO.class);
+        Mockito.when(policy.getPolicyId()).thenReturn("some");
+        Mockito.when(vsphereStoragePolicyDao.findById(Mockito.anyLong()))
+                .thenReturn(policy);
+        Mockito.doReturn(new ArrayList<>(List.of(1L, 2L)))
+                .when(storageManagerImpl).getUpHostsInPool(Mockito.anyLong());
+        Mockito.when(hvGuruMgr.getGuruProcessedCommandTargetHost(Mockito.anyLong(),
+                Mockito.any(CheckDataStoreStoragePolicyComplainceCommand.class))).thenReturn(1L);
+        try {
+            Mockito.when(agentManager.send(Mockito.anyLong(), Mockito.any(Command.class)))
+                    .thenThrow(AgentUnavailableException.class);
+        } catch (AgentUnavailableException | OperationTimedoutException e) {
+            Assert.fail(e.getMessage());
+        }
+        storageManagerImpl.getCheckDatastorePolicyComplianceAnswer("1", pool);
+        try {
+            Mockito.when(agentManager.send(Mockito.anyLong(), Mockito.any(Command.class)))
+                    .thenThrow(OperationTimedoutException.class);
+        } catch (AgentUnavailableException | OperationTimedoutException e) {
+            Assert.fail(e.getMessage());
+        }
+        storageManagerImpl.getCheckDatastorePolicyComplianceAnswer("1", pool);
+    }
+
+    @Test
+    public void testGetCheckDatastorePolicyComplianceAnswerSuccess() throws StorageUnavailableException {
+        StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
+        Mockito.when(pool.getId()).thenReturn(1L);
+        VsphereStoragePolicyVO policy = Mockito.mock(VsphereStoragePolicyVO.class);
+        Mockito.when(policy.getPolicyId()).thenReturn("some");
+        Mockito.when(vsphereStoragePolicyDao.findById(Mockito.anyLong()))
+                .thenReturn(policy);
+        Mockito.doReturn(new ArrayList<>(List.of(1L, 2L))).when(storageManagerImpl).getUpHostsInPool(Mockito.anyLong());
+        Mockito.when(hvGuruMgr.getGuruProcessedCommandTargetHost(Mockito.anyLong(),
+                Mockito.any(CheckDataStoreStoragePolicyComplainceCommand.class))).thenReturn(1L);
+        try {
+            Mockito.when(agentManager.send(Mockito.anyLong(),
+                            Mockito.any(CheckDataStoreStoragePolicyComplainceCommand.class)))
+                    .thenReturn(new com.cloud.agent.api.Answer(
+                            Mockito.mock(CheckDataStoreStoragePolicyComplainceCommand.class)));
+        } catch (AgentUnavailableException | OperationTimedoutException e) {
+            Assert.fail(e.getMessage());
+        }
+        com.cloud.agent.api.Answer answer =
+                storageManagerImpl.getCheckDatastorePolicyComplianceAnswer("1", pool);
+        Assert.assertTrue(answer.getResult());
+    }
 }
diff --git a/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java b/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java
index 5427e6c839f..4f32d2531a4 100644
--- a/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java
+++ b/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java
@@ -893,8 +893,7 @@ public class VolumeApiServiceImplTest {
 
     private void verifyMocksForTestDestroyVolumeWhenVolumeIsNotInRightState() {
         Mockito.verify(volumeServiceMock, Mockito.times(0)).destroyVolume(volumeMockId);
-        Mockito.verify(resourceLimitServiceMock, Mockito.times(0)).decrementResourceCount(accountMockId, ResourceType.volume, true);
-        Mockito.verify(resourceLimitServiceMock, Mockito.times(0)).decrementResourceCount(accountMockId, ResourceType.primary_storage, true, volumeSizeMock);
+        Mockito.verify(resourceLimitServiceMock, Mockito.times(0)).decrementVolumeResourceCount(accountMockId, true, volumeSizeMock, newDiskOfferingMock);
     }
 
     private void configureMocksForTestDestroyVolumeWhenVolume() {
@@ -902,8 +901,7 @@ public class VolumeApiServiceImplTest {
         Mockito.lenient().doReturn(true).when(volumeVoMock).isDisplayVolume();
 
         Mockito.lenient().doNothing().when(volumeServiceMock).destroyVolume(volumeMockId);
-        Mockito.lenient().doNothing().when(resourceLimitServiceMock).decrementResourceCount(accountMockId, ResourceType.volume, true);
-        Mockito.lenient().doNothing().when(resourceLimitServiceMock).decrementResourceCount(accountMockId, ResourceType.primary_storage, true, volumeSizeMock);
+        Mockito.lenient().doNothing().when(resourceLimitServiceMock).decrementVolumeResourceCount(accountMockId, true, volumeSizeMock, newDiskOfferingMock);
     }
 
     @Test
@@ -1449,22 +1447,21 @@ public class VolumeApiServiceImplTest {
             Account newAccountMock = new AccountVO(accountMockId + 1);
 
             Mockito.doReturn(volumeVoMock).when(volumeDaoMock).persist(volumeVoMock);
+            Mockito.when(_diskOfferingDao.findById(Mockito.anyLong())).thenReturn(newDiskOfferingMock);
 
             volumeApiServiceImpl.updateVolumeAccount(accountMock, volumeVoMock, newAccountMock);
 
             usageEventUtilsMocked.verify(() -> UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volumeVoMock.getAccountId(), volumeVoMock.getDataCenterId(), volumeVoMock.getId(),
                     volumeVoMock.getName(), Volume.class.getName(), volumeVoMock.getUuid(), volumeVoMock.isDisplayVolume()));
 
-            Mockito.verify(resourceLimitServiceMock).decrementResourceCount(accountMock.getAccountId(), ResourceType.volume);
-            Mockito.verify(resourceLimitServiceMock).decrementResourceCount(accountMock.getAccountId(), ResourceType.primary_storage, volumeVoMock.getSize());
+            Mockito.verify(resourceLimitServiceMock).decrementVolumeResourceCount(accountMock.getAccountId(), true, volumeVoMock.getSize(), newDiskOfferingMock);
 
             Mockito.verify(volumeVoMock).setAccountId(newAccountMock.getAccountId());
             Mockito.verify(volumeVoMock).setDomainId(newAccountMock.getDomainId());
 
             Mockito.verify(volumeDaoMock).persist(volumeVoMock);
 
-            Mockito.verify(resourceLimitServiceMock).incrementResourceCount(newAccountMock.getAccountId(), ResourceType.volume);
-            Mockito.verify(resourceLimitServiceMock).incrementResourceCount(newAccountMock.getAccountId(), ResourceType.primary_storage, volumeVoMock.getSize());
+            Mockito.verify(resourceLimitServiceMock).incrementVolumeResourceCount(newAccountMock.getAccountId(), true, volumeVoMock.getSize(), newDiskOfferingMock);
 
             usageEventUtilsMocked.verify(() -> UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volumeVoMock.getAccountId(), volumeVoMock.getDataCenterId(), volumeVoMock.getId(),
                     volumeVoMock.getName(), Volume.class.getName(), volumeVoMock.getUuid(), volumeVoMock.isDisplayVolume()));
diff --git a/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java b/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java
index 2cd6f486943..c4e54b73825 100644
--- a/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java
+++ b/server/src/test/java/com/cloud/user/AccountManagerImplVolumeDeleteEventTest.java
@@ -145,8 +145,6 @@ public class AccountManagerImplVolumeDeleteEventTest extends AccountManagetImplT
         ServiceOfferingVO offering = mock(ServiceOfferingVO.class);
         lenient().when(offering.getCpu()).thenReturn(500);
         lenient().when(offering.getId()).thenReturn(1l);
-        when(offering.getCpu()).thenReturn(500);
-        when(offering.getRamSize()).thenReturn(500);
         when(serviceOfferingDao.findByIdIncludingRemoved(nullable(Long.class), nullable(Long.class))).thenReturn(offering);
 
         lenient().when(_domainMgr.getDomain(nullable(Long.class))).thenReturn(domain);
diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java
index ffd0c407f13..4ed0e5b6250 100644
--- a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java
+++ b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java
@@ -16,6 +16,55 @@
 // under the License.
 package com.cloud.vm;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.api.BaseCmd.HTTPMethod;
+import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
+import org.apache.cloudstack.api.command.user.vm.DeployVnfApplianceCmd;
+import org.apache.cloudstack.api.command.user.vm.ResetVMUserDataCmd;
+import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
+import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
+import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.cloudstack.storage.template.VnfTemplateManager;
+import org.apache.cloudstack.userdata.UserDataManager;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
 import com.cloud.api.query.dao.ServiceOfferingJoinDao;
 import com.cloud.api.query.vo.ServiceOfferingJoinVO;
 import com.cloud.configuration.Resource;
@@ -83,55 +132,6 @@ import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
 
-import org.apache.cloudstack.api.BaseCmd.HTTPMethod;
-import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
-import org.apache.cloudstack.api.command.user.vm.DeployVnfApplianceCmd;
-import org.apache.cloudstack.api.command.user.vm.ResetVMUserDataCmd;
-import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
-import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
-import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
-import org.apache.cloudstack.context.CallContext;
-import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
-import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
-import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.cloudstack.storage.template.VnfTemplateManager;
-import org.apache.cloudstack.userdata.UserDataManager;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
... 2031 lines suppressed ...