cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ro...@apache.org
Subject [cloudstack] branch master updated: Refactoring to remove duplicate code. (#3152)
Date Sat, 27 Jul 2019 14:51:55 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 7a27e35  Refactoring to remove duplicate code. (#3152)
7a27e35 is described below

commit 7a27e35a612f13a0ce43459b22e01d9b69627220
Author: Frank Maximus <frank.maximus@nuagenetworks.net>
AuthorDate: Sat Jul 27 16:51:43 2019 +0200

    Refactoring to remove duplicate code. (#3152)
    
    Make use of Java 8 default implementation in interfaces,
    to remove code duplication between XxxCmd and XxxCmdAsAdmin.
    
    Refactor checkFormat by pre-calculating the supported
    extensions. Also make use of this in ImageStoreUtil.
    Makes it easier to add new file and compression formats.
---
 .../com/cloud/template/VirtualMachineTemplate.java |   2 -
 .../cloudstack/api/BaseListTaggedResourcesCmd.java |  22 +--
 .../api/BaseListTemplateOrIsoPermissionsCmd.java   |   8 +-
 .../org/apache/cloudstack/api/TaggedResources.java |  72 ++++++++++
 ...esCmdByAdmin.java => ResponseViewProvider.java} |  15 +-
 .../ListZonesCmdByAdmin.java => AdminCmd.java}     |  16 ++-
 .../admin/address/AssociateIPAddrCmdByAdmin.java   |  39 +----
 .../address/ListPublicIpAddressesCmdByAdmin.java   |  29 +---
 .../UpdateVMAffinityGroupCmdByAdmin.java           |  34 +----
 .../api/command/admin/domain/ListDomainsCmd.java   |   3 +-
 .../admin/domain/ListDomainsCmdByAdmin.java        |   4 +-
 .../api/command/admin/iso/AttachIsoCmdByAdmin.java |  31 +---
 .../api/command/admin/iso/DetachIsoCmdByAdmin.java |  25 +---
 .../admin/iso/ListIsoPermissionsCmdByAdmin.java    |  14 +-
 .../api/command/admin/iso/ListIsosCmdByAdmin.java  |   3 +-
 .../command/admin/iso/RegisterIsoCmdByAdmin.java   |  30 +---
 .../api/command/admin/iso/UpdateIsoCmdByAdmin.java |  22 +--
 .../ListLoadBalancerRuleInstancesCmdByAdmin.java   |  69 +--------
 .../admin/network/CreateNetworkCmdByAdmin.java     |  25 +---
 .../admin/network/ListNetworksCmdByAdmin.java      |  26 +---
 .../admin/network/UpdateNetworkCmdByAdmin.java     |  29 +---
 .../admin/template/CopyTemplateCmdByAdmin.java     |  48 +------
 .../admin/template/CreateTemplateCmdByAdmin.java   |  41 +-----
 .../ListTemplatePermissionsCmdByAdmin.java         |  10 +-
 .../admin/template/ListTemplatesCmdByAdmin.java    |   3 +-
 .../admin/template/RegisterTemplateCmdByAdmin.java |  37 +----
 .../admin/template/UpdateTemplateCmdByAdmin.java   |  25 +---
 .../api/command/admin/vm/AddNicToVMCmdByAdmin.java |  32 +----
 .../api/command/admin/vm/DeployVMCmdByAdmin.java   |  51 +------
 .../api/command/admin/vm/DestroyVMCmdByAdmin.java  |  34 +----
 .../api/command/admin/vm/ListVMsCmdByAdmin.java    |   3 +-
 .../api/command/admin/vm/RebootVMCmdByAdmin.java   |  28 +---
 .../admin/vm/RemoveNicFromVMCmdByAdmin.java        |  32 +----
 .../admin/vm/ResetVMPasswordCmdByAdmin.java        |  29 +---
 .../command/admin/vm/ResetVMSSHKeyCmdByAdmin.java  |  32 +----
 .../api/command/admin/vm/RestoreVMCmdByAdmin.java  |  31 +---
 .../api/command/admin/vm/ScaleVMCmdByAdmin.java    |  45 +-----
 .../api/command/admin/vm/StartVMCmdByAdmin.java    |  57 +-------
 .../api/command/admin/vm/StopVMCmdByAdmin.java     |  30 +---
 .../admin/vm/UpdateDefaultNicForVMCmdByAdmin.java  |  33 +----
 .../api/command/admin/vm/UpdateVMCmdByAdmin.java   |  27 +---
 .../api/command/admin/vm/UpgradeVMCmdByAdmin.java  |  34 +----
 .../vmsnapshot/RevertToVMSnapshotCmdByAdmin.java   |  36 +----
 .../admin/volume/AttachVolumeCmdByAdmin.java       |  24 +---
 .../admin/volume/CreateVolumeCmdByAdmin.java       |  37 +----
 .../admin/volume/DetachVolumeCmdByAdmin.java       |  25 +---
 .../admin/volume/ListVolumesCmdByAdmin.java        |   5 +-
 .../admin/volume/MigrateVolumeCmdByAdmin.java      |  19 +--
 .../admin/volume/ResizeVolumeCmdByAdmin.java       |  30 +---
 .../admin/volume/UpdateVolumeCmdByAdmin.java       |  21 +--
 .../admin/volume/UploadVolumeCmdByAdmin.java       |  33 +----
 .../api/command/admin/vpc/CreateVPCCmdByAdmin.java |  44 +-----
 .../api/command/admin/vpc/ListVPCsCmdByAdmin.java  |  30 +---
 .../api/command/admin/vpc/UpdateVPCCmdByAdmin.java |  23 +--
 .../command/admin/zone/ListZonesCmdByAdmin.java    |   3 +-
 .../ListZonesCmdByAdmin.java => user/UserCmd.java} |  16 ++-
 .../api/command/user/account/ListAccountsCmd.java  |   3 +-
 .../command/user/address/AssociateIPAddrCmd.java   |   5 +-
 .../user/address/ListPublicIpAddressesCmd.java     |   5 +-
 .../affinitygroup/UpdateVMAffinityGroupCmd.java    |   7 +-
 .../api/command/user/iso/AttachIsoCmd.java         |   5 +-
 .../api/command/user/iso/DetachIsoCmd.java         |   5 +-
 .../command/user/iso/ListIsoPermissionsCmd.java    |   8 +-
 .../api/command/user/iso/ListIsosCmd.java          |   3 +-
 .../api/command/user/iso/RegisterIsoCmd.java       |   5 +-
 .../api/command/user/iso/UpdateIsoCmd.java         |   5 +-
 .../ListLoadBalancerRuleInstancesCmd.java          |   6 +-
 .../api/command/user/network/CreateNetworkCmd.java |   5 +-
 .../api/command/user/network/ListNetworksCmd.java  |   5 +-
 .../api/command/user/network/UpdateNetworkCmd.java |   5 +-
 .../api/command/user/project/ListProjectsCmd.java  |  21 +--
 .../api/command/user/tag/CreateTagsCmd.java        |  18 +--
 .../api/command/user/template/CopyTemplateCmd.java |   5 +-
 .../command/user/template/CreateTemplateCmd.java   |  10 +-
 .../user/template/ListTemplatePermissionsCmd.java  |   8 +-
 .../command/user/template/ListTemplatesCmd.java    |   3 +-
 .../command/user/template/RegisterTemplateCmd.java |   5 +-
 .../command/user/template/UpdateTemplateCmd.java   |   5 +-
 .../api/command/user/vm/AddNicToVMCmd.java         |   5 +-
 .../api/command/user/vm/DeployVMCmd.java           |  74 ++++++----
 .../api/command/user/vm/DestroyVMCmd.java          |   5 +-
 .../cloudstack/api/command/user/vm/ListVMsCmd.java |   3 +-
 .../api/command/user/vm/RebootVMCmd.java           |   5 +-
 .../api/command/user/vm/RemoveNicFromVMCmd.java    |   5 +-
 .../api/command/user/vm/ResetVMPasswordCmd.java    |   5 +-
 .../api/command/user/vm/ResetVMSSHKeyCmd.java      |   5 +-
 .../api/command/user/vm/RestoreVMCmd.java          |   5 +-
 .../cloudstack/api/command/user/vm/ScaleVMCmd.java |   5 +-
 .../cloudstack/api/command/user/vm/StartVMCmd.java |   5 +-
 .../cloudstack/api/command/user/vm/StopVMCmd.java  |   5 +-
 .../command/user/vm/UpdateDefaultNicForVMCmd.java  |   5 +-
 .../api/command/user/vm/UpdateVMCmd.java           |   5 +-
 .../api/command/user/vm/UpgradeVMCmd.java          |   5 +-
 .../user/vmsnapshot/RevertToVMSnapshotCmd.java     |   5 +-
 .../command/user/volume/AddResourceDetailCmd.java  |  21 +--
 .../api/command/user/volume/AttachVolumeCmd.java   |   5 +-
 .../api/command/user/volume/CreateVolumeCmd.java   |   5 +-
 .../api/command/user/volume/DetachVolumeCmd.java   |   5 +-
 .../api/command/user/volume/ListVolumesCmd.java    |   3 +-
 .../api/command/user/volume/MigrateVolumeCmd.java  |   5 +-
 .../api/command/user/volume/ResizeVolumeCmd.java   |   5 +-
 .../api/command/user/volume/UpdateVolumeCmd.java   |   5 +-
 .../api/command/user/volume/UploadVolumeCmd.java   |   5 +-
 .../api/command/user/vpc/CreateVPCCmd.java         |   5 +-
 .../api/command/user/vpc/ListVPCsCmd.java          |   5 +-
 .../api/command/user/vpc/UpdateVPCCmd.java         |   5 +-
 .../api/command/user/zone/ListZonesCmd.java        |  26 +---
 .../api/command/test/AddIpToVmNicTest.java         |   2 -
 .../api/command/test/ListCfgCmdTest.java           |   2 -
 .../api/command/test/UpdateCfgCmdTest.java         |   2 -
 .../api/agent/test/CheckOnHostCommandTest.java     |   2 -
 .../test/HypervDirectConnectResourceTest.java      |   2 -
 .../java/com/cloud/api/query/QueryManagerImpl.java |   6 +-
 utils/src/main/java/com/cloud/utils/UriUtils.java  | 127 ++++++++---------
 .../utils/imagestore/ImageStoreUtil.java           |  30 ++--
 .../com/cloud/utils/UriUtilsParametrizedTest.java  | 158 +++++++++++++++++++++
 116 files changed, 629 insertions(+), 1622 deletions(-)

diff --git a/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java b/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java
index ad2f636..5177e51 100644
--- a/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java
+++ b/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java
@@ -26,8 +26,6 @@ import org.apache.cloudstack.api.InternalIdentity;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.TemplateType;
-import com.cloud.storage.Volume.Event;
-import com.cloud.storage.Volume.State;
 import com.cloud.utils.fsm.StateMachine2;
 import com.cloud.utils.fsm.StateObject;
 
diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java
index 5f17742..0bd3356 100644
--- a/api/src/main/java/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/BaseListTaggedResourcesCmd.java
@@ -16,34 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
-import com.cloud.exception.InvalidParameterValueException;
-
 public abstract class BaseListTaggedResourcesCmd extends BaseListProjectAndAccountResourcesCmd implements IBaseListTaggedResourcesCmd {
     @Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List resources by tags (key/value pairs)")
     private Map tags;
 
     @Override
     public Map<String, String> getTags() {
-        Map<String, String> tagsMap = null;
-        if (tags != null && !tags.isEmpty()) {
-            tagsMap = new HashMap<String, String>();
-            Collection<?> servicesCollection = tags.values();
-            Iterator<?> iter = servicesCollection.iterator();
-            while (iter.hasNext()) {
-                HashMap<String, String> services = (HashMap<String, String>)iter.next();
-                String key = services.get("key");
-                String value = services.get("value");
-                if (value == null) {
-                    throw new InvalidParameterValueException("No value is passed in for key " + key);
-                }
-                tagsMap.put(key, value);
-            }
-        }
-        return tagsMap;
+        return TaggedResources.parseKeyValueMap(tags, false);
     }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
index d149dff..052d7d1 100644
--- a/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java
@@ -21,16 +21,16 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.ResponseViewProvider;
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
 
 import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.Account;
 
-public abstract class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
+public abstract class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd implements ResponseViewProvider {
     public Logger logger = getLogger();
     protected static final String s_name = "listtemplatepermissionsresponse";
 
-
     /////////////////////////////////////////////////////
     //////////////// API parameters /////////////////////
     /////////////////////////////////////////////////////
@@ -76,6 +76,10 @@ public abstract class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd {
         return "templateOrIso";
     }
 
+    @Override
+    public void execute() {
+        executeWithView(getResponseView());
+    }
 
     protected void executeWithView(ResponseView view) {
         List<String> accountNames = _templateService.listTemplatePermissions(this);
diff --git a/api/src/main/java/org/apache/cloudstack/api/TaggedResources.java b/api/src/main/java/org/apache/cloudstack/api/TaggedResources.java
new file mode 100644
index 0000000..26cea9e
--- /dev/null
+++ b/api/src/main/java/org/apache/cloudstack/api/TaggedResources.java
@@ -0,0 +1,72 @@
+// 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;
+
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.mapping;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import javax.annotation.Nullable;
+
+import org.apache.commons.collections.MapUtils;
+
+import com.cloud.exception.InvalidParameterValueException;
+
+public abstract class TaggedResources {
+    @Nullable
+    public static Map<String, String> parseKeyValueMap(Map map, boolean allowNullValues) {
+        Map<String, String> result = null;
+        if (MapUtils.isNotEmpty(map)) {
+            Map<Integer, Map<String, String>> typedMap = map;
+            result = typedMap.values()
+                        .stream()
+                        .collect(toMap(
+                                t -> t.get("key"),
+                                t -> getValue(t, allowNullValues)
+                        ));
+        }
+        return result;
+    }
+
+    @Nullable
+    public static Map<String, List<String>> groupBy(Map map, String keyField, String valueField) {
+        Map<String, List<String>> result = null;
+        if (MapUtils.isNotEmpty(map)) {
+            final Function<Map<String, String>, String> key = entry -> entry.get(keyField);
+            final Function<Map<String, String>, String> value = entry -> entry.get(valueField);
+            Map<Integer, Map<String, String>> typedMap = (Map<Integer, Map<String, String>>) map;
+            result = typedMap.values()
+                             .stream()
+                             .collect(groupingBy(key, mapping(value, toList())));
+        }
+
+        return result;
+    }
+
+    private static String getValue(Map<String, String> tagEntry, boolean allowNullValues) {
+        String value = tagEntry.get("value");
+        if (value == null && !allowNullValues) {
+            throw new InvalidParameterValueException("No value is passed in for key " + tagEntry.get("key"));
+        }
+        return value;
+    }
+}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/ResponseViewProvider.java
similarity index 59%
copy from api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
copy to api/src/main/java/org/apache/cloudstack/api/command/ResponseViewProvider.java
index d0a7707..c191ee9 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/ResponseViewProvider.java
@@ -1,3 +1,4 @@
+///
 // 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
@@ -14,14 +15,12 @@
 // 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.zone;
+///
 
-import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.command.user.zone.ListZonesCmd;
-import org.apache.cloudstack.api.response.ZoneResponse;
+package org.apache.cloudstack.api.command;
 
-@APICommand(name = "listZones", description = "Lists zones", responseObject = ZoneResponse.class, responseView = ResponseView.Full,
-        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListZonesCmdByAdmin extends ListZonesCmd {
+import org.apache.cloudstack.api.ResponseObject;
+
+public interface ResponseViewProvider {
+    ResponseObject.ResponseView getResponseView();
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/AdminCmd.java
similarity index 64%
copy from api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
copy to api/src/main/java/org/apache/cloudstack/api/command/admin/AdminCmd.java
index d0a7707..5238dec 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/AdminCmd.java
@@ -1,3 +1,4 @@
+///
 // 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
@@ -14,14 +15,15 @@
 // 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.zone;
+///
+
+package org.apache.cloudstack.api.command.admin;
 
-import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.command.user.zone.ListZonesCmd;
-import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.cloudstack.api.command.user.UserCmd;
 
-@APICommand(name = "listZones", description = "Lists zones", responseObject = ZoneResponse.class, responseView = ResponseView.Full,
-        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListZonesCmdByAdmin extends ListZonesCmd {
+public interface AdminCmd extends UserCmd {
+    default ResponseView getResponseView() {
+        return ResponseView.Full;
+    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
index e428ac8..56f41b5 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java
@@ -19,48 +19,13 @@ package org.apache.cloudstack.api.command.admin.address;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd;
 import org.apache.cloudstack.api.response.IPAddressResponse;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.IpAddress;
 
 @APICommand(name = "associateIpAddress", description = "Acquires and associates a public IP to an account.", responseObject = IPAddressResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class AssociateIPAddrCmdByAdmin extends AssociateIPAddrCmd {
+public class AssociateIPAddrCmdByAdmin extends AssociateIPAddrCmd implements AdminCmd {
     public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceUnavailableException, ResourceAllocationException,
-                                    ConcurrentOperationException, InsufficientCapacityException {
-        CallContext.current().setEventDetails("Ip Id: " + getEntityId());
-
-        IpAddress result = null;
-
-        if (getVpcId() != null) {
-            result = _vpcService.associateIPToVpc(getEntityId(), getVpcId());
-        } else if (getNetworkId() != null) {
-            result = _networkService.associateIPToNetwork(getEntityId(), getNetworkId());
-        }
-
-        if (result != null) {
-            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full, result);
-            ipResponse.setResponseName(getCommandName());
-            setResponseObject(ipResponse);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign ip address");
-        }
-    }
-
-
-
-
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
index 22627a2..4bd6aa7 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ListPublicIpAddressesCmdByAdmin.java
@@ -16,39 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.address;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
 import org.apache.cloudstack.api.response.IPAddressResponse;
-import org.apache.cloudstack.api.response.ListResponse;
 
 import com.cloud.network.IpAddress;
-import com.cloud.utils.Pair;
 
 @APICommand(name = "listPublicIpAddresses", description = "Lists all public ip addresses", responseObject = IPAddressResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = {IpAddress.class})
-public class ListPublicIpAddressesCmdByAdmin extends ListPublicIpAddressesCmd {
-    public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
-        ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
-        List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
-        for (IpAddress ipAddress : result.first()) {
-            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full, ipAddress);
-            ipResponse.setObjectName("publicipaddress");
-            ipAddrResponses.add(ipResponse);
-        }
-
-        response.setResponses(ipAddrResponses, result.second());
-        response.setResponseName(getCommandName());
-        setResponseObject(response);
-    }
-
-}
+public class ListPublicIpAddressesCmdByAdmin extends ListPublicIpAddressesCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java
index b0a6cae..7bf9b64 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java
@@ -16,23 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.affinitygroup;
 
-import java.util.ArrayList;
-import java.util.EnumSet;
-
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.affinitygroup.UpdateVMAffinityGroupCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 
@@ -41,27 +32,6 @@ import com.cloud.vm.VirtualMachine;
         entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false,
         responseHasSensitiveInfo = true)
-public class UpdateVMAffinityGroupCmdByAdmin extends UpdateVMAffinityGroupCmd {
+public class UpdateVMAffinityGroupCmdByAdmin extends UpdateVMAffinityGroupCmd implements AdminCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateVMAffinityGroupCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceUnavailableException,
-            InsufficientCapacityException, ServerApiException {
-        CallContext.current().setEventDetails("Vm Id: "+getId());
-        UserVm result = _affinityGroupService.updateVMAffinityGroups(getId(), getAffinityGroupIdList());
-        ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
-        dc.add(VMDetails.valueOf("affgrp"));
-        EnumSet<VMDetails> details = EnumSet.copyOf(dc);
-
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", details, result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm's affinity groups");
-        }
-    }
-
-
 }
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 9c1ae22..5e4cda3 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
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.ApiConstants.DomainDetails;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
 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;
 
@@ -36,7 +37,7 @@ import com.cloud.exception.InvalidParameterValueException;
 
 @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)
-public class ListDomainsCmd extends BaseListCmd {
+public class ListDomainsCmd extends BaseListCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListDomainsCmd.class.getName());
 
     private static final String s_name = "listdomainsresponse";
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdByAdmin.java
index bbe75de..02a2b45 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdByAdmin.java
@@ -18,11 +18,11 @@ package org.apache.cloudstack.api.command.admin.domain;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 
 import com.cloud.domain.Domain;
 
 @APICommand(name = "listDomains", description = "Lists domains and provides detailed information for listed domains", responseObject = DomainResponse.class, responseView = ResponseView.Full, entityType = {Domain.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListDomainsCmdByAdmin extends ListDomainsCmd {
-}
+public class ListDomainsCmdByAdmin extends ListDomainsCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/AttachIsoCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/AttachIsoCmdByAdmin.java
index 2a58508..e39107b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/AttachIsoCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/AttachIsoCmdByAdmin.java
@@ -16,39 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.iso;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.iso.AttachIsoCmd;
-import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.uservm.UserVm;
 
 @APICommand(name = "attachIso", description = "Attaches an ISO to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class AttachIsoCmdByAdmin extends AttachIsoCmd {
-    public static final Logger s_logger = Logger.getLogger(AttachIsoCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails("Vm Id: " +getVirtualMachineId()+ " ISO Id: "+getId());
-        boolean result = _templateService.attachIso(id, virtualMachineId);
-        if (result) {
-            UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId);
-            if (userVm != null) {
-                UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
-                response.setResponseName(DeployVMCmd.getResultObjectName());
-                setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach iso");
-            }
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach iso");
-        }
-    }
-}
+public class AttachIsoCmdByAdmin extends AttachIsoCmd implements AdminCmd { }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/DetachIsoCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/DetachIsoCmdByAdmin.java
index 2486680..5eeba2b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/DetachIsoCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/DetachIsoCmdByAdmin.java
@@ -16,33 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.iso;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.iso.DetachIsoCmd;
-import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 
-import com.cloud.uservm.UserVm;
-
 @APICommand(name = "detachIso", description = "Detaches any ISO file (if any) currently attached to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class DetachIsoCmdByAdmin extends DetachIsoCmd {
-    public static final Logger s_logger = Logger.getLogger(DetachIsoCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        boolean result = _templateService.detachIso(virtualMachineId);
-        if (result) {
-            UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
-            response.setResponseName(DeployVMCmd.getResultObjectName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach iso");
-        }
-    }
-}
+public class DetachIsoCmdByAdmin extends DetachIsoCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
index 0b3c9ef..46bd4f3 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsoPermissionsCmdByAdmin.java
@@ -18,16 +18,14 @@ package org.apache.cloudstack.api.command.admin.iso;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.iso.ListIsoPermissionsCmd;
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
 
-@APICommand(name = "listIsoPermissions", description = "List iso visibility and all accounts that have permissions to view this iso.", responseObject = TemplatePermissionsResponse.class, responseView = ResponseView.Full,
+@APICommand(name = "listIsoPermissions",
+        description = "List iso visibility and all accounts that have permissions to view this iso.",
+        responseObject = TemplatePermissionsResponse.class,
+        responseView = ResponseView.Full,
         requestHasSensitiveInfo = false,
         responseHasSensitiveInfo = false)
-public class ListIsoPermissionsCmdByAdmin extends ListIsoPermissionsCmd {
-
-    @Override
-    public void execute() {
-        executeWithView(ResponseView.Full);
-    }
-}
+public class ListIsoPermissionsCmdByAdmin extends ListIsoPermissionsCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsosCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsosCmdByAdmin.java
index 621fe01..4b6d4c0 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsosCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/ListIsosCmdByAdmin.java
@@ -18,10 +18,11 @@ package org.apache.cloudstack.api.command.admin.iso;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
 @APICommand(name = "listIsos", description = "Lists all available ISO files.", responseObject = TemplateResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListIsosCmdByAdmin extends ListIsosCmd {
+public class ListIsosCmdByAdmin extends ListIsosCmd implements AdminCmd {
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/RegisterIsoCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/RegisterIsoCmdByAdmin.java
index daae959..754c945 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/RegisterIsoCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/RegisterIsoCmdByAdmin.java
@@ -16,39 +16,11 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.iso;
 
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
-import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.template.VirtualMachineTemplate;
-
 @APICommand(name = "registerIso", responseObject = TemplateResponse.class, description = "Registers an existing ISO into the CloudStack Cloud.", responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class RegisterIsoCmdByAdmin extends RegisterIsoCmd {
-    public static final Logger s_logger = Logger.getLogger(RegisterIsoCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceAllocationException{
-        VirtualMachineTemplate template = _templateService.registerIso(this);
-        if (template != null) {
-            ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-            List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(ResponseView.Full, template, zoneId, false);
-            response.setResponses(templateResponses);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register iso");
-        }
-
-    }
-}
+public class RegisterIsoCmdByAdmin extends RegisterIsoCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/UpdateIsoCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/UpdateIsoCmdByAdmin.java
index d3ec820..58a57f0 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/UpdateIsoCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/iso/UpdateIsoCmdByAdmin.java
@@ -16,31 +16,11 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.iso;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
-import com.cloud.template.VirtualMachineTemplate;
-
 @APICommand(name = "updateIso", description = "Updates an ISO file.", responseObject = TemplateResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateIsoCmdByAdmin extends UpdateIsoCmd {
-    public static final Logger s_logger = Logger.getLogger(UpdateIsoCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        VirtualMachineTemplate result = _templateService.updateTemplate(this);
-        if (result != null) {
-            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Full, result);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update iso");
-        }
-    }
-}
+public class UpdateIsoCmdByAdmin extends UpdateIsoCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
index 1bece18..b11988b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
@@ -16,79 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.loadbalancer;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import com.cloud.vm.VirtualMachine;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse;
-import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleInstancesCmd;
-import org.apache.cloudstack.api.response.ListResponse;
-import org.apache.cloudstack.api.response.UserVmResponse;
-
-import com.cloud.uservm.UserVm;
-import com.cloud.utils.Pair;
 
 @APICommand(name = "listLoadBalancerRuleInstances", description = "List all virtual machine instances that are assigned to a load balancer rule.", responseObject = LoadBalancerRuleVmMapResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false,
         responseHasSensitiveInfo = true)
-public class ListLoadBalancerRuleInstancesCmdByAdmin extends ListLoadBalancerRuleInstancesCmd {
-    public static final Logger s_logger = Logger.getLogger (ListLoadBalancerRuleInstancesCmdByAdmin.class.getName());
-
-
-
-    @Override
-    public void execute(){
-        Pair<List<? extends UserVm>, List<String>> vmServiceMap =  _lbService.listLoadBalancerInstances(this);
-        List<? extends UserVm> result = vmServiceMap.first();
-        List<String> serviceStates  = vmServiceMap.second();
-
-
-        if (!isListLbVmip()) {
-            // list lb instances
-            ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
-            List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
-            if (result != null) {
-                vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
-
-
-                for (int i = 0; i < result.size(); i++) {
-                    vmResponses.get(i).setServiceState(serviceStates.get(i));
-                }
-            }
-            response.setResponses(vmResponses);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-
-        } else {
-            ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<LoadBalancerRuleVmMapResponse>();
-
-            List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
-            List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
-
-            if (result != null) {
-                vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
-
-                List<String> ipaddr = null;
-
-                for (int i=0;i<result.size(); i++) {
-                    LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
-                    vmResponses.get(i).setServiceState(serviceStates.get(i));
-                    lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
-                    //get vm id from the uuid
-                    VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
-                    lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
-                    lbRuleVmIpResponse.setObjectName("lbrulevmidip");
-                    listlbVmRes.add(lbRuleVmIpResponse);
-                }
-            }
-
-            lbRes.setResponseName(getCommandName());
-            lbRes.setResponses(listlbVmRes);
-            setResponseObject(lbRes);
-        }
-    }
-}
+public class ListLoadBalancerRuleInstancesCmdByAdmin extends ListLoadBalancerRuleInstancesCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java
index 7a60940..1f32f62 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java
@@ -20,21 +20,17 @@ import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
 import org.apache.cloudstack.api.response.NetworkResponse;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceAllocationException;
 import com.cloud.network.Network;
 
 @APICommand(name = "createNetwork", description = "Creates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Full, entityType = {Network.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateNetworkCmdByAdmin extends CreateNetworkCmd {
+public class CreateNetworkCmdByAdmin extends CreateNetworkCmd implements AdminCmd {
     public static final Logger s_logger = Logger.getLogger(CreateNetworkCmdByAdmin.class.getName());
 
     @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network")
@@ -67,21 +63,4 @@ public class CreateNetworkCmdByAdmin extends CreateNetworkCmd {
         }
         return false;
     }
-
-    /////////////////////////////////////////////////////
-    /////////////// API Implementation///////////////////
-    /////////////////////////////////////////////////////
-
-    @Override
-    // an exception thrown by createNetwork() will be caught by the dispatcher.
-    public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
-        Network result = _networkService.createGuestNetwork(this);
-        if (result != null) {
-            NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        }else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network");
-        }
-    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworksCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworksCmdByAdmin.java
index 244352f..a234ff0 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworksCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworksCmdByAdmin.java
@@ -16,36 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.network;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.network.ListNetworksCmd;
-import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.NetworkResponse;
 
 import com.cloud.network.Network;
-import com.cloud.utils.Pair;
 
 @APICommand(name = "listNetworks", description = "Lists all available networks.", responseObject = NetworkResponse.class, responseView = ResponseView.Full, entityType = {Network.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListNetworksCmdByAdmin extends ListNetworksCmd {
-    public static final Logger s_logger = Logger.getLogger(ListNetworksCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        Pair<List<? extends Network>, Integer> networks = _networkService.searchForNetworks(this);
-        ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
-        List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
-        for (Network network : networks.first()) {
-            NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Full, network);
-            networkResponses.add(networkResponse);
-        }
-        response.setResponses(networkResponses, networks.second());
-        response.setResponseName(getCommandName());
-        setResponseObject(response);
-    }
-}
+public class ListNetworksCmdByAdmin extends ListNetworksCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
index 487ed14..b3088a4 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkCmdByAdmin.java
@@ -18,24 +18,17 @@ package org.apache.cloudstack.api.command.admin.network;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.network.UpdateNetworkCmd;
 import org.apache.cloudstack.api.response.NetworkResponse;
-import org.apache.log4j.Logger;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.network.Network;
 
 @APICommand(name = "updateNetwork", description = "Updates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Full, entityType = {Network.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateNetworkCmdByAdmin extends UpdateNetworkCmd {
-    public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmdByAdmin.class.getName());
-
+public class UpdateNetworkCmdByAdmin extends UpdateNetworkCmd implements AdminCmd {
     @Parameter(name= ApiConstants.HIDE_IP_ADDRESS_USAGE, type=CommandType.BOOLEAN, description="when true ip address usage for the network will not be exported by the listUsageRecords API")
     private Boolean hideIpAddressUsage;
 
@@ -45,22 +38,4 @@ public class UpdateNetworkCmdByAdmin extends UpdateNetworkCmd {
         }
         return hideIpAddressUsage;
     }
-
-    @Override
-    public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
-        Network network = _networkService.getNetwork(id);
-        if (network == null) {
-            throw new InvalidParameterValueException("Couldn't find network by id");
-        }
-
-        Network result = _networkService.updateGuestNetwork(this);
-        if (result != null) {
-            NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
-        }
-    }
-
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CopyTemplateCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CopyTemplateCmdByAdmin.java
index e0c798c..75061ab 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CopyTemplateCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CopyTemplateCmdByAdmin.java
@@ -16,58 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.template;
 
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.command.user.template.CopyTemplateCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.StorageUnavailableException;
-import com.cloud.template.VirtualMachineTemplate;
 
 @APICommand(name = "copyTemplate", description = "Copies a template from one zone to another.", responseObject = TemplateResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CopyTemplateCmdByAdmin extends CopyTemplateCmd {
-    public static final Logger s_logger = Logger.getLogger(CopyTemplateCmdByAdmin.class.getName());
-
-    @Override
-    public void execute() throws ResourceAllocationException{
-        try {
-            if (destZoneId == null && (destZoneIds == null || destZoneIds.size() == 0))
-                throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
-                        "Either destzoneid or destzoneids parameters have to be specified.");
-
-            if (destZoneId != null && destZoneIds != null && destZoneIds.size() != 0)
-                throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
-                        "Both destzoneid and destzoneids cannot be specified at the same time.");
-
-            CallContext.current().setEventDetails(getEventDescription());
-            VirtualMachineTemplate template = _templateService.copyTemplate(this);
-
-            if (template != null){
-                List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(ResponseView.Full, template,
-                        getDestinationZoneIds(), false);
-                TemplateResponse response = new TemplateResponse();
-                if (listResponse != null && !listResponse.isEmpty()) {
-                    response = listResponse.get(0);
-                }
-
-                response.setResponseName(getCommandName());
-                setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template");
-            }
-        } catch (StorageUnavailableException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
-        }
-    }
-}
+public class CopyTemplateCmdByAdmin extends CopyTemplateCmd {}
 
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CreateTemplateCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CreateTemplateCmdByAdmin.java
index 865bc15..1260949 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CreateTemplateCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/CreateTemplateCmdByAdmin.java
@@ -16,50 +16,13 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.template;
 
-import java.util.List;
-
-import com.cloud.storage.Snapshot;
-import com.cloud.storage.Volume;
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.template.CreateTemplateCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.template.VirtualMachineTemplate;
 
 @APICommand(name = "createTemplate", responseObject = TemplateResponse.class, description = "Creates a template of a virtual machine. " + "The virtual machine must be in a STOPPED state. "
         + "A template created from this command is automatically designated as a private template visible to the account that created it.", responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateTemplateCmdByAdmin extends CreateTemplateCmd {
-    public static final Logger s_logger = Logger.getLogger(CreateTemplateCmdByAdmin.class.getName());
-
-    @Override
-    public void execute() {
-        CallContext.current().setEventDetails("Template Id: " + getEntityUuid()+((getSnapshotId() == null) ? " from volume Id: " + this._uuidMgr.getUuid(Volume.class, getVolumeId()) : " from snapshot Id: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId())));
-        VirtualMachineTemplate template = null;
-        template = _templateService.createPrivateTemplate(this);
-
-        if (template != null){
-            List<TemplateResponse> templateResponses;
-            if (isBareMetal()) {
-                templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template.getId(), vmId);
-            } else {
-                templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template.getId(), snapshotId, volumeId, false);
-            }
-            TemplateResponse response = new TemplateResponse();
-            if (templateResponses != null && !templateResponses.isEmpty()) {
-                response = templateResponses.get(0);
-            }
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private template");
-        }
-
-    }
-}
+public class CreateTemplateCmdByAdmin extends CreateTemplateCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
index 08e2ee8..ae0e220 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatePermissionsCmdByAdmin.java
@@ -18,17 +18,11 @@ package org.apache.cloudstack.api.command.admin.template;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.template.ListTemplatePermissionsCmd;
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
 
 @APICommand(name = "listTemplatePermissions", description = "List template visibility and all accounts that have permissions to view this template.", responseObject = TemplatePermissionsResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false,
         responseHasSensitiveInfo = false)
-public class ListTemplatePermissionsCmdByAdmin extends ListTemplatePermissionsCmd {
-
-    @Override
-    public void execute() {
-        executeWithView(ResponseView.Full);
-    }
-
-}
+public class ListTemplatePermissionsCmdByAdmin extends ListTemplatePermissionsCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatesCmdByAdmin.java
index 1469fe2..2f57783 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/ListTemplatesCmdByAdmin.java
@@ -18,6 +18,7 @@ package org.apache.cloudstack.api.command.admin.template;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
@@ -25,6 +26,6 @@ import com.cloud.template.VirtualMachineTemplate;
 
 @APICommand(name = "listTemplates", description = "List all public, private, and privileged templates.", responseObject = TemplateResponse.class, entityType = {VirtualMachineTemplate.class}, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListTemplatesCmdByAdmin extends ListTemplatesCmd {
+public class ListTemplatesCmdByAdmin extends ListTemplatesCmd implements AdminCmd {
 
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/RegisterTemplateCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/RegisterTemplateCmdByAdmin.java
index ba4772b..2859375 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/RegisterTemplateCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/RegisterTemplateCmdByAdmin.java
@@ -16,46 +16,11 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.template;
 
-import java.net.URISyntaxException;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
-import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.template.VirtualMachineTemplate;
-
 @APICommand(name = "registerTemplate", description = "Registers an existing template into the CloudStack cloud.", responseObject = TemplateResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class RegisterTemplateCmdByAdmin extends RegisterTemplateCmd {
-    public static final Logger s_logger = Logger.getLogger(RegisterTemplateCmdByAdmin.class.getName());
-
-    @Override
-    public void execute() throws ResourceAllocationException{
-        try {
-            validateParameters();
-
-            VirtualMachineTemplate template = _templateService.registerTemplate(this);
-            if (template != null){
-                ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-                List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full, template,
-                        zoneIds, false);
-                response.setResponses(templateResponses);
-                response.setResponseName(getCommandName());
-                setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template");
-            }
-        } catch (URISyntaxException ex1) {
-            s_logger.info(ex1);
-            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage());
-        }
-    }
-}
+public class RegisterTemplateCmdByAdmin extends RegisterTemplateCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/UpdateTemplateCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/UpdateTemplateCmdByAdmin.java
index 94f8ff2..09591c8 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/UpdateTemplateCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/UpdateTemplateCmdByAdmin.java
@@ -16,33 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.template;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.template.UpdateTemplateCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
-import com.cloud.template.VirtualMachineTemplate;
-
 @APICommand(name = "updateTemplate", description = "Updates attributes of a template.", responseObject = TemplateResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateTemplateCmdByAdmin extends UpdateTemplateCmd {
-    public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        VirtualMachineTemplate result = _templateService.updateTemplate(this);
-        if (result != null) {
-            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Full, result);
-            response.setObjectName("template");
-            response.setTemplateType(result.getTemplateType().toString());//Template can be either USER or ROUTING type
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update template");
-        }
-    }
-}
+public class UpdateTemplateCmdByAdmin extends UpdateTemplateCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AddNicToVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AddNicToVMCmdByAdmin.java
index da0a087..7a8c409 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AddNicToVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AddNicToVMCmdByAdmin.java
@@ -16,43 +16,15 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import java.util.ArrayList;
-import java.util.EnumSet;
-
-import com.cloud.network.Network;
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.AddNicToVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 
 @APICommand(name = "addNicToVirtualMachine", description = "Adds VM to specified network by creating a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class AddNicToVMCmdByAdmin extends AddNicToVMCmd {
-    public static final Logger s_logger = Logger.getLogger(AddNicToVMCmdByAdmin.class);
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVmId()) + " Network Id: " + this._uuidMgr.getUuid(Network.class, getNetworkId()));
-        UserVm result = _userVmService.addNicToVirtualMachine(this);
-        ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
-        dc.add(VMDetails.valueOf("nics"));
-        EnumSet<VMDetails> details = EnumSet.copyOf(dc);
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", details, result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add NIC to vm. Refer to server logs for details.");
-        }
-    }
-}
+public class AddNicToVMCmdByAdmin extends AddNicToVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java
index b94fc0c..acdc0e0 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java
@@ -23,26 +23,20 @@ import org.apache.cloudstack.api.response.PodResponse;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InsufficientServerCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 
 @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class DeployVMCmdByAdmin extends DeployVMCmd {
+public class DeployVMCmdByAdmin extends DeployVMCmd implements AdminCmd {
     public static final Logger s_logger = Logger.getLogger(DeployVMCmdByAdmin.class.getName());
 
+
     @Parameter(name = ApiConstants.POD_ID, type = CommandType.UUID, entityType = PodResponse.class, description = "destination Pod ID to deploy the VM to - parameter available for root admin only", since = "4.13")
     private Long podId;
 
@@ -56,43 +50,4 @@ public class DeployVMCmdByAdmin extends DeployVMCmd {
     public Long getClusterId() {
         return clusterId;
     }
-
-    @Override
-    public void execute(){
-        UserVm result;
-
-        if (getStartVm()) {
-            try {
-                CallContext.current().setEventDetails("Vm Id: " + getEntityUuid());
-                result = _userVmService.startVirtualMachine(this);
-            } catch (ResourceUnavailableException ex) {
-                s_logger.warn("Exception: ", ex);
-                throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
-            } catch (ConcurrentOperationException ex) {
-                s_logger.warn("Exception: ", ex);
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-            } catch (InsufficientCapacityException ex) {
-                StringBuilder message = new StringBuilder(ex.getMessage());
-                if (ex instanceof InsufficientServerCapacityException) {
-                    if(((InsufficientServerCapacityException)ex).isAffinityApplied()){
-                        message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
-                    }
-                }
-                s_logger.info(ex);
-                s_logger.info(message.toString(), ex);
-                throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
-            }
-        } else {
-            result = _userVmService.getUserVm(getEntityId());
-        }
-
-        if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm");
-        }
-    }
-
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DestroyVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DestroyVMCmdByAdmin.java
index bb59a17..08a1364 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DestroyVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DestroyVMCmdByAdmin.java
@@ -16,45 +16,15 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.DestroyVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "destroyVirtualMachine", description = "Destroys a virtual machine. Once destroyed, only the administrator can recover it.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false,
         responseHasSensitiveInfo = true)
-public class DestroyVMCmdByAdmin extends DestroyVMCmd {
-    public static final Logger s_logger = Logger.getLogger(DestroyVMCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceUnavailableException, ConcurrentOperationException{
-        CallContext.current().setEventDetails("Vm Id: "+this._uuidMgr.getUuid(VirtualMachine.class, getId()));
-        UserVm result = _userVmService.destroyVm(this);
-
-        UserVmResponse response = new UserVmResponse();
-        if (result != null) {
-            List<UserVmResponse> responses = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result);
-            if (responses != null && !responses.isEmpty()) {
-                response = responses.get(0);
-            }
-            response.setResponseName("virtualmachine");
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy vm");
-        }
-    }
-}
+public class DestroyVMCmdByAdmin extends DestroyVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java
index f41e196..fbcedaa 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java
@@ -22,6 +22,7 @@ import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
 import org.apache.cloudstack.api.response.HostResponse;
 import org.apache.cloudstack.api.response.PodResponse;
@@ -32,7 +33,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class ListVMsCmdByAdmin extends ListVMsCmd {
+public class ListVMsCmdByAdmin extends ListVMsCmd implements AdminCmd {
     public static final Logger s_logger = Logger.getLogger(ListVMsCmdByAdmin.class.getName());
 
     /////////////////////////////////////////////////////
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RebootVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RebootVMCmdByAdmin.java
index c32f9ac..5f6a7ab 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RebootVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RebootVMCmdByAdmin.java
@@ -16,38 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.RebootVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "rebootVirtualMachine", description = "Reboots a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class RebootVMCmdByAdmin extends RebootVMCmd {
-    public static final Logger s_logger = Logger.getLogger(RebootVMCmdByAdmin.class.getName());
-
-    @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException{
-        CallContext.current().setEventDetails("Vm Id: "+this._uuidMgr.getUuid(VirtualMachine.class, getId()));
-        UserVm result;
-        result = _userVmService.rebootVirtualMachine(this);
-
-        if (result !=null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reboot vm instance");
-        }
-    }
-}
+public class RebootVMCmdByAdmin extends RebootVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RemoveNicFromVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RemoveNicFromVMCmdByAdmin.java
index 08c56df..89726af 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RemoveNicFromVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RemoveNicFromVMCmdByAdmin.java
@@ -16,42 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import java.util.ArrayList;
-import java.util.EnumSet;
-
-import com.cloud.vm.Nic;
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.RemoveNicFromVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "removeNicFromVirtualMachine", description = "Removes VM from specified network by deleting a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class RemoveNicFromVMCmdByAdmin extends RemoveNicFromVMCmd {
-    public static final Logger s_logger = Logger.getLogger(RemoveNicFromVMCmdByAdmin.class);
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails("Vm Id: "+this._uuidMgr.getUuid(VirtualMachine.class, getVmId()) + " Nic Id: " + this._uuidMgr.getUuid(Nic.class, getNicId()));
-        UserVm result = _userVmService.removeNicFromVirtualMachine(this);
-        ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
-        dc.add(VMDetails.valueOf("nics"));
-        EnumSet<VMDetails> details = EnumSet.copyOf(dc);
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", details, result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove NIC from vm, see error log for details");
-        }
-    }
-}
+public class RemoveNicFromVMCmdByAdmin extends RemoveNicFromVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMPasswordCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMPasswordCmdByAdmin.java
index a53e61a..d7ab0c6 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMPasswordCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMPasswordCmdByAdmin.java
@@ -16,41 +16,16 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.ResetVMPasswordCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "resetPasswordForVirtualMachine", responseObject=UserVmResponse.class, description="Resets the password for virtual machine. " +
                     "The virtual machine must be in a \"Stopped\" state and the template must already " +
         "support this feature for this command to take effect. [async]", responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class ResetVMPasswordCmdByAdmin extends ResetVMPasswordCmd {
-    public static final Logger s_logger = Logger.getLogger(ResetVMPasswordCmdByAdmin.class.getName());
-
-
-
-    @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException{
-        password = _mgr.generateRandomPassword();
-        CallContext.current().setEventDetails("Vm Id: "+getId());
-        UserVm result = _userVmService.resetVMPassword(this, password);
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset vm password");
-        }
-    }
-}
+public class ResetVMPasswordCmdByAdmin extends ResetVMPasswordCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMSSHKeyCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMSSHKeyCmdByAdmin.java
index 35c47ed..ed9cc11 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMSSHKeyCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ResetVMSSHKeyCmdByAdmin.java
@@ -17,43 +17,15 @@
 
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.ResetVMSSHKeyCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "resetSSHKeyForVirtualMachine", responseObject = UserVmResponse.class, description = "Resets the SSH Key for virtual machine. " +
         "The virtual machine must be in a \"Stopped\" state. [async]", responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class ResetVMSSHKeyCmdByAdmin extends ResetVMSSHKeyCmd {
-
-    public static final Logger s_logger = Logger.getLogger(ResetVMSSHKeyCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceUnavailableException,
-            InsufficientCapacityException {
-
-        CallContext.current().setEventDetails("Vm Id: " + getId());
-        UserVm result = _userVmService.resetVMSSHKey(this);
-
-        if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset vm SSHKey");
-        }
-    }
-
-}
+public class ResetVMSSHKeyCmdByAdmin extends ResetVMSSHKeyCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RestoreVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RestoreVMCmdByAdmin.java
index f607faf..b3ee398 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RestoreVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RestoreVMCmdByAdmin.java
@@ -16,42 +16,15 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "restoreVirtualMachine", description = "Restore a VM to original template/ISO or new template/ISO", responseObject = UserVmResponse.class, since = "3.0.0", responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false,
         responseHasSensitiveInfo = true)
-public class RestoreVMCmdByAdmin extends RestoreVMCmd {
-    public static final Logger s_logger = Logger.getLogger(RestoreVMCmdByAdmin.class);
-
-    @Override
-    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
-            ResourceAllocationException {
-        UserVm result;
-        CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVmId()));
-        result = _userVmService.restoreVM(this);
-        if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restore vm " + getVmId());
-        }
-    }
-
-}
+public class RestoreVMCmdByAdmin extends RestoreVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ScaleVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ScaleVMCmdByAdmin.java
index f434fdf..869b45b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ScaleVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ScaleVMCmdByAdmin.java
@@ -16,56 +16,15 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.ScaleVMCmd;
 import org.apache.cloudstack.api.response.SuccessResponse;
-import org.apache.cloudstack.api.response.UserVmResponse;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.ManagementServerException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.exception.VirtualMachineMigrationException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 
 @APICommand(name = "scaleVirtualMachine", description = "Scales the virtual machine to a new service offering.", responseObject = SuccessResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ScaleVMCmdByAdmin extends ScaleVMCmd {
-    public static final Logger s_logger = Logger.getLogger(ScaleVMCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        UserVm result;
-        try {
-            result = _userVmService.upgradeVirtualMachine(this);
-        } catch (ResourceUnavailableException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
-        } catch (ConcurrentOperationException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        } catch (ManagementServerException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        } catch (VirtualMachineMigrationException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        }
-        if (result != null){
-            List<UserVmResponse> responseList = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result);
-            UserVmResponse response = responseList.get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to scale vm");
-        }
-    }
-}
\ No newline at end of file
+public class ScaleVMCmdByAdmin extends ScaleVMCmd implements AdminCmd {}
\ No newline at end of file
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StartVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StartVMCmdByAdmin.java
index 1230547..f87622c 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StartVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StartVMCmdByAdmin.java
@@ -16,67 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InsufficientServerCapacityException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.exception.StorageUnavailableException;
-import com.cloud.uservm.UserVm;
-import com.cloud.utils.exception.ExecutionException;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "startVirtualMachine", responseObject = UserVmResponse.class, description = "Starts a virtual machine.", responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class StartVMCmdByAdmin extends StartVMCmd {
-    public static final Logger s_logger = Logger.getLogger(StartVMCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceUnavailableException, ResourceAllocationException {
-        try {
-            CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
-
-            UserVm result ;
-            result = _userVmService.startVirtualMachine(this);
-
-            if (result != null) {
-                UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-                response.setResponseName(getCommandName());
-                setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
-            }
-        } catch (ConcurrentOperationException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        } catch (StorageUnavailableException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
-        } catch (ExecutionException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        } catch (InsufficientCapacityException ex) {
-            StringBuilder message = new StringBuilder(ex.getMessage());
-            if (ex instanceof InsufficientServerCapacityException) {
-                if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
-                    message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
-                }
-            }
-            s_logger.info(ex);
-            s_logger.info(message.toString(), ex);
-            throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
-        }
-    }
-
-}
+public class StartVMCmdByAdmin extends StartVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StopVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StopVMCmdByAdmin.java
index ca85dfa..2f7cc21 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StopVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/StopVMCmdByAdmin.java
@@ -16,40 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.StopVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "stopVirtualMachine", responseObject = UserVmResponse.class, description = "Stops a virtual machine.", responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class StopVMCmdByAdmin extends StopVMCmd {
-    public static final Logger s_logger = Logger.getLogger(StopVMCmdByAdmin.class.getName());
-
-
-
-    @Override
-    public void execute() throws ServerApiException, ConcurrentOperationException {
-        CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
-        UserVm result;
-
-        result = _userVmService.stopVirtualMachine(getId(), isForced());
-
-        if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop vm");
-        }
-    }
-}
+public class StopVMCmdByAdmin extends StopVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateDefaultNicForVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateDefaultNicForVMCmdByAdmin.java
index d666ae4..1c4dde9 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateDefaultNicForVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateDefaultNicForVMCmdByAdmin.java
@@ -16,43 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import java.util.ArrayList;
-import java.util.EnumSet;
-
-import com.cloud.vm.Nic;
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.UpdateDefaultNicForVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "updateDefaultNicForVirtualMachine", description = "Changes the default NIC on a VM", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class UpdateDefaultNicForVMCmdByAdmin extends UpdateDefaultNicForVMCmd {
-    public static final Logger s_logger = Logger.getLogger(UpdateDefaultNicForVMCmdByAdmin.class);
-
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails("Vm Id: "+this._uuidMgr.getUuid(VirtualMachine.class, getVmId()) + " Nic Id: " + this._uuidMgr.getUuid(Nic.class, getNicId()));
-        UserVm result = _userVmService.updateDefaultNicForVirtualMachine(this);
-        ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
-        dc.add(VMDetails.valueOf("nics"));
-        EnumSet<VMDetails> details = EnumSet.copyOf(dc);
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", details, result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to set default nic for VM. Refer to server logs for details.");
-        }
-    }
-}
+public class UpdateDefaultNicForVMCmdByAdmin extends UpdateDefaultNicForVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateVMCmdByAdmin.java
index 5d2b2b7..cb4bb04 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpdateVMCmdByAdmin.java
@@ -16,19 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.UpdateVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 
@@ -36,20 +29,4 @@ import com.cloud.vm.VirtualMachine;
         "new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. " +
         "Therefore, stop the VM manually before issuing this call.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class UpdateVMCmdByAdmin extends UpdateVMCmd {
-    public static final Logger s_logger = Logger.getLogger(UpdateVMCmdByAdmin.class.getName());
-
-    @Override
-    public void execute() throws ResourceUnavailableException,
-            InsufficientCapacityException, ServerApiException {
-        CallContext.current().setEventDetails("Vm Id: "+this._uuidMgr.getUuid(VirtualMachine.class, getId()));
-        UserVm result = _userVmService.updateVirtualMachine(this);
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm");
-        }
-    }
-}
+public class UpdateVMCmdByAdmin extends UpdateVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpgradeVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpgradeVMCmdByAdmin.java
index 6e3261a..7291fe9 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpgradeVMCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UpgradeVMCmdByAdmin.java
@@ -16,46 +16,16 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vm;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.offering.ServiceOffering;
-import com.cloud.uservm.UserVm;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "changeServiceForVirtualMachine", responseObject=UserVmResponse.class, description="Changes the service offering for a virtual machine. " +
                                             "The virtual machine must be in a \"Stopped\" state for " +
         "this command to take effect.", responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class UpgradeVMCmdByAdmin extends UpgradeVMCmd {
-    public static final Logger s_logger = Logger.getLogger(UpgradeVMCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceAllocationException{
-        CallContext.current().setEventDetails("Vm Id: "+this._uuidMgr.getUuid(VirtualMachine.class, getId()));
-
-        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
-        if (serviceOffering == null) {
-            throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
-        }
-
-        UserVm result = _userVmService.upgradeVirtualMachine(this);
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
-        }
-    }
-}
+public class UpgradeVMCmdByAdmin extends UpgradeVMCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vmsnapshot/RevertToVMSnapshotCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vmsnapshot/RevertToVMSnapshotCmdByAdmin.java
index 47cb99b..8f28662 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vmsnapshot/RevertToVMSnapshotCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vmsnapshot/RevertToVMSnapshotCmdByAdmin.java
@@ -16,44 +16,12 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vmsnapshot;
 
-import java.util.logging.Logger;
-
-import com.cloud.vm.snapshot.VMSnapshot;
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vmsnapshot.RevertToVMSnapshotCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.context.CallContext;
-
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.uservm.UserVm;
 
 @APICommand(name = "revertToVMSnapshot", description = "Revert VM from a vmsnapshot.", responseObject = UserVmResponse.class, since = "4.2.0", responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class RevertToVMSnapshotCmdByAdmin extends RevertToVMSnapshotCmd {
-    public static final Logger s_logger = Logger
-            .getLogger(RevertToVMSnapshotCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws  ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, ConcurrentOperationException {
-        CallContext.current().setEventDetails(
-                "vmsnapshot id: " + this._uuidMgr.getUuid(VMSnapshot.class, getVmSnapShotId()));
-        UserVm result = _vmSnapshotService.revertToSnapshot(getVmSnapShotId());
-        if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full,
-                    "virtualmachine", result).get(0);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,"Failed to revert VM snapshot");
-        }
-    }
-
-
-}
+public class RevertToVMSnapshotCmdByAdmin extends RevertToVMSnapshotCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java
index f70b410..6f31df7 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java
@@ -16,34 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.volume;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.storage.Volume;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "attachVolume", description = "Attaches a disk volume to a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class AttachVolumeCmdByAdmin extends AttachVolumeCmd {
-    public static final Logger s_logger = Logger.getLogger(AttachVolumeCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails("Volume Id: "+this._uuidMgr.getUuid(Volume.class, getId())+" VmId: "+this._uuidMgr.getUuid(VirtualMachine.class, getVirtualMachineId()));
-        Volume result = _volumeService.attachVolumeToVM(this);
-        if (result != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach volume");
-        }
-    }
-}
+public class AttachVolumeCmdByAdmin extends AttachVolumeCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java
index 1dc4721..c0dfe42 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java
@@ -16,49 +16,16 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.volume;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.storage.Snapshot;
 import com.cloud.storage.Volume;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Full, entityType = {
         Volume.class, VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateVolumeCmdByAdmin extends CreateVolumeCmd {
-    public static final Logger s_logger = Logger.getLogger(CreateVolumeCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails("Volume Id: "+ getEntityUuid() + ((getSnapshotId() == null) ? "" : " from snapshot: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId())));
-        Volume volume = _volumeService.createVolume(this);
-        if (volume != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
-            //FIXME - have to be moved to ApiResponseHelper
-            if (getSnapshotId() != null) {
-                Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
-                if (snap != null) {
-                    response.setSnapshotId(snap.getUuid()); // if the volume was
-                    // created from a
-                    // snapshot,
-                    // snapshotId will
-                    // be set so we pass
-                    // it back in the
-                    // response
-                }
-            }
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
-        }
-    }
-}
+public class CreateVolumeCmdByAdmin extends CreateVolumeCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java
index f9d9cbd..36a183b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java
@@ -16,35 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.volume;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.storage.Volume;
 import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "detachVolume", description = "Detaches a disk volume from a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class DetachVolumeCmdByAdmin extends DetachVolumeCmd {
-    public static final Logger s_logger = Logger.getLogger(DetachVolumeCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails(getEventDescription());
-        Volume result = _volumeService.detachVolumeFromVM(this);
-        if (result != null){
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
-            response.setResponseName("volume");
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach volume");
-        }
-    }
-}
+public class DetachVolumeCmdByAdmin extends DetachVolumeCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java
index add2271..371db31 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java
@@ -18,6 +18,7 @@ package org.apache.cloudstack.api.command.admin.volume;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
 
@@ -25,6 +26,4 @@ import com.cloud.storage.Volume;
 
 @APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {
         Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListVolumesCmdByAdmin extends ListVolumesCmd {
-
-}
+public class ListVolumesCmdByAdmin extends ListVolumesCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java
index 1a18b95..135c8fc 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java
@@ -17,9 +17,8 @@
 package org.apache.cloudstack.api.command.admin.volume;
 
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
 
@@ -27,18 +26,4 @@ import com.cloud.storage.Volume;
 
 @APICommand(name = "migrateVolume", description = "Migrate volume", responseObject = VolumeResponse.class, since = "3.0.0", responseView = ResponseView.Full, entityType = {
         Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class MigrateVolumeCmdByAdmin extends MigrateVolumeCmd {
-
-    @Override
-    public void execute() {
-        Volume result = _volumeService.migrateVolume(this);
-        if (result != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume");
-        }
-    }
-
-}
+public class MigrateVolumeCmdByAdmin extends MigrateVolumeCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java
index 689e779..73c0984 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java
@@ -17,40 +17,14 @@
 package org.apache.cloudstack.api.command.admin.volume;
 
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.context.CallContext;
 
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
 import com.cloud.storage.Volume;
 
 
 @APICommand(name = "resizeVolume", description = "Resizes a volume", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {Volume.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ResizeVolumeCmdByAdmin extends ResizeVolumeCmd {
-
-    @Override
-    public void execute() throws ResourceAllocationException{
-        Volume volume = null;
-        try {
-            CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId()) + " to size " + getSize() + "G");
-            volume = _volumeService.resizeVolume(this);
-        } catch (InvalidParameterValueException ex) {
-            s_logger.info(ex.getMessage());
-            throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage());
-        }
-
-        if (volume != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
-            //FIXME - have to be moved to ApiResponseHelper
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume");
-        }
-    }
-}
+public class ResizeVolumeCmdByAdmin extends ResizeVolumeCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java
index b683435..5e0f06a 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java
@@ -17,30 +17,13 @@
 package org.apache.cloudstack.api.command.admin.volume;
 
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.UpdateVolumeCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.context.CallContext;
 
 import com.cloud.storage.Volume;
 
 @APICommand(name = "updateVolume", description = "Updates the volume.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {Volume.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateVolumeCmdByAdmin extends UpdateVolumeCmd {
-
-    @Override
-    public void execute(){
-        CallContext.current().setEventDetails("Volume Id: "+this._uuidMgr.getUuid(Volume.class, getId()));
-        Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(),
-                getCustomId(), getEntityOwnerId(), getChainInfo());
-        if (result != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update volume");
-        }
-    }
-}
+public class UpdateVolumeCmdByAdmin extends UpdateVolumeCmd  implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java
index f26e465..6140db57 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java
@@ -16,43 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.volume;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
 import org.apache.cloudstack.api.response.VolumeResponse;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.storage.Volume;
 
 @APICommand(name = "uploadVolume", description = "Uploads a data disk.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {Volume.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UploadVolumeCmdByAdmin extends UploadVolumeCmd {
-    public static final Logger s_logger = Logger.getLogger(UploadVolumeCmdByAdmin.class.getName());
-
-
-    @Override
-    public void execute() throws ResourceUnavailableException,
-            InsufficientCapacityException, ServerApiException,
-            ConcurrentOperationException, ResourceAllocationException,
-            NetworkRuleConflictException {
-
-            Volume volume = _volumeService.uploadVolume(this);
-            if (volume != null){
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
-                response.setResponseName(getCommandName());
-                setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upload volume");
-            }
-    }
-
-
-}
+public class UploadVolumeCmdByAdmin extends UploadVolumeCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java
index a84a3aa5..bd00876 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java
@@ -16,54 +16,14 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vpc;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd;
 import org.apache.cloudstack.api.response.VpcResponse;
 
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.vpc.Vpc;
 
 @APICommand(name = "createVPC", description = "Creates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Full, entityType = {Vpc.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateVPCCmdByAdmin extends CreateVPCCmd {
-    public static final Logger s_logger = Logger.getLogger(CreateVPCCmdByAdmin.class.getName());
-
-    @Override
-    public void execute() {
-        Vpc vpc = null;
-        try {
-            if (isStart()) {
-                _vpcService.startVpc(getEntityId(), true);
-            } else {
-                s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
-             }
-            vpc = _entityMgr.findById(Vpc.class, getEntityId());
-        } catch (ResourceUnavailableException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
-        } catch (ConcurrentOperationException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
-        } catch (InsufficientCapacityException ex) {
-            s_logger.info(ex);
-            s_logger.trace(ex);
-            throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
-        }
-
-        if (vpc != null) {
-            VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, vpc);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC");
-        }
-    }
-}
+public class CreateVPCCmdByAdmin extends CreateVPCCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListVPCsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListVPCsCmdByAdmin.java
index 20d77a7..efd2f9e 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListVPCsCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListVPCsCmdByAdmin.java
@@ -16,41 +16,15 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vpc;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vpc.ListVPCsCmd;
-import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.VpcResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.network.vpc.Vpc;
-import com.cloud.utils.Pair;
 
 
 @APICommand(name = "listVPCs", description = "Lists VPCs", responseObject = VpcResponse.class, responseView = ResponseView.Full, entityType = {Vpc.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListVPCsCmdByAdmin extends ListVPCsCmd {
-    public static final Logger s_logger = Logger.getLogger(ListVPCsCmdByAdmin.class.getName());
-
-    @Override
-    public void execute() {
-        Pair<List<? extends Vpc>, Integer> vpcs =
-                _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(), getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(),
-                        getKeyword(), getStartIndex(), getPageSizeVal(), getZoneId(), isRecursive(), listAll(), getRestartRequired(), getTags(),
-                        getProjectId(), getDisplay());
-        ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
-        List<VpcResponse> vpcResponses = new ArrayList<VpcResponse>();
-        for (Vpc vpc : vpcs.first()) {
-            VpcResponse offeringResponse = _responseGenerator.createVpcResponse(ResponseView.Full, vpc);
-            vpcResponses.add(offeringResponse);
-        }
-
-        response.setResponses(vpcResponses, vpcs.second());
-        response.setResponseName(getCommandName());
-        setResponseObject(response);
-    }
-
-}
+public class ListVPCsCmdByAdmin extends ListVPCsCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
index d7761de..5fb2461 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCCmdByAdmin.java
@@ -16,12 +16,9 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.vpc;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.vpc.UpdateVPCCmd;
 import org.apache.cloudstack.api.response.VpcResponse;
 
@@ -29,20 +26,4 @@ import com.cloud.network.vpc.Vpc;
 
 @APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Full, entityType = {Vpc.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateVPCCmdByAdmin extends UpdateVPCCmd {
-    public static final Logger s_logger = Logger.getLogger(UpdateVPCCmdByAdmin.class.getName());
-
-    @Override
-    public void execute(){
-        Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), isDisplayVpc());
-        if (result != null) {
-            VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, result);
-            response.setResponseName(getCommandName());
-            setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
-        }
-    }
-
-
-}
+public class UpdateVPCCmdByAdmin extends UpdateVPCCmd implements AdminCmd {}
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
index d0a7707..a8896df 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
@@ -18,10 +18,11 @@ package org.apache.cloudstack.api.command.admin.zone;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.admin.AdminCmd;
 import org.apache.cloudstack.api.command.user.zone.ListZonesCmd;
 import org.apache.cloudstack.api.response.ZoneResponse;
 
 @APICommand(name = "listZones", description = "Lists zones", responseObject = ZoneResponse.class, responseView = ResponseView.Full,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListZonesCmdByAdmin extends ListZonesCmd {
+public class ListZonesCmdByAdmin extends ListZonesCmd implements AdminCmd {
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/user/UserCmd.java
similarity index 64%
copy from api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
copy to api/src/main/java/org/apache/cloudstack/api/command/user/UserCmd.java
index d0a7707..f78f0c0 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListZonesCmdByAdmin.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/UserCmd.java
@@ -1,3 +1,4 @@
+///
 // 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
@@ -14,14 +15,15 @@
 // 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.zone;
+///
+
+package org.apache.cloudstack.api.command.user;
 
-import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
-import org.apache.cloudstack.api.command.user.zone.ListZonesCmd;
-import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.cloudstack.api.command.ResponseViewProvider;
 
-@APICommand(name = "listZones", description = "Lists zones", responseObject = ZoneResponse.class, responseView = ResponseView.Full,
-        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListZonesCmdByAdmin extends ListZonesCmd {
+public interface UserCmd extends ResponseViewProvider {
+    default ResponseView getResponseView() {
+        return ResponseView.Restricted;
+    }
 }
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 0d33352..29f86c8 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
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.ApiConstants.DomainDetails;
 import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.AccountResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 
@@ -36,7 +37,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Restricted, entityType = {Account.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class ListAccountsCmd extends BaseListDomainResourcesCmd {
+public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName());
     private static final String s_name = "listaccountsresponse";
 
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
index fea7f20..5b662b7 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java
@@ -31,6 +31,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.IPAddressResponse;
 import org.apache.cloudstack.api.response.NetworkResponse;
@@ -63,7 +64,7 @@ import com.cloud.user.Account;
         responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false,
         responseHasSensitiveInfo = false)
-public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
+public class AssociateIPAddrCmd extends BaseAsyncCreateCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmd.class.getName());
     private static final String s_name = "associateipaddressresponse";
 
@@ -339,7 +340,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
         }
 
         if (result != null) {
-            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, result);
+            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(getResponseView(), result);
             ipResponse.setResponseName(getCommandName());
             setResponseObject(ipResponse);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
index d25d167..a9b3bf8 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.IPAddressResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.NetworkResponse;
@@ -41,7 +42,7 @@ import com.cloud.utils.Pair;
 
 @APICommand(name = "listPublicIpAddresses", description = "Lists all public IP addresses", responseObject = IPAddressResponse.class, responseView = ResponseView.Restricted,
  requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = { IpAddress.class })
-public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
+public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName());
 
     private static final String s_name = "listpublicipaddressesresponse";
@@ -194,7 +195,7 @@ public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
         ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
         List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
         for (IpAddress ipAddress : result.first()) {
-            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, ipAddress);
+            IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(getResponseView(), ipAddress);
             ipResponse.setObjectName("publicipaddress");
             ipAddrResponses.add(ipResponse);
         }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
index 7085000..c798b18 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java
@@ -34,6 +34,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
 
@@ -53,7 +54,7 @@ import com.cloud.vm.VirtualMachine;
         entityType = {VirtualMachine.class},
             requestHasSensitiveInfo = false,
             responseHasSensitiveInfo = true)
-public class UpdateVMAffinityGroupCmd extends BaseAsyncCmd {
+public class UpdateVMAffinityGroupCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateVMAffinityGroupCmd.class.getName());
     private static final String s_name = "updatevirtualmachineresponse";
 
@@ -148,8 +149,8 @@ public class UpdateVMAffinityGroupCmd extends BaseAsyncCmd {
         dc.add(VMDetails.valueOf("affgrp"));
         EnumSet<VMDetails> details = EnumSet.copyOf(dc);
 
-        if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, result).get(0);
+        if (result != null) {
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", details, result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java
index c1d67e5..2458400 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
@@ -36,7 +37,7 @@ import com.cloud.uservm.UserVm;
 
 @APICommand(name = "attachIso", description = "Attaches an ISO to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class AttachIsoCmd extends BaseAsyncCmd {
+public class AttachIsoCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(AttachIsoCmd.class.getName());
 
     private static final String s_name = "attachisoresponse";
@@ -101,7 +102,7 @@ public class AttachIsoCmd extends BaseAsyncCmd {
         if (result) {
             UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId);
             if (userVm != null) {
-                UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm).get(0);
+                UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", userVm).get(0);
                 response.setResponseName(DeployVMCmd.getResultObjectName());
                 setResponseObject(response);
             } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java
index 9ee8ef5..ae86e2f 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 
@@ -34,7 +35,7 @@ import com.cloud.uservm.UserVm;
 
 @APICommand(name = "detachIso", description = "Detaches any ISO file (if any) currently attached to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class DetachIsoCmd extends BaseAsyncCmd {
+public class DetachIsoCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(DetachIsoCmd.class.getName());
 
     private static final String s_name = "detachisoresponse";
@@ -89,7 +90,7 @@ public class DetachIsoCmd extends BaseAsyncCmd {
         boolean result = _templateService.detachIso(virtualMachineId);
         if (result) {
             UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", userVm).get(0);
             response.setResponseName(DeployVMCmd.getResultObjectName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
index 9a3db43..fbbe088 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java
@@ -21,6 +21,7 @@ import org.apache.log4j.Logger;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
 
 import com.cloud.storage.Storage.ImageFormat;
@@ -29,7 +30,7 @@ import com.cloud.template.VirtualMachineTemplate;
 @APICommand(name = "listIsoPermissions", description = "List ISO visibility and all accounts that have permissions to view this ISO.", responseObject = TemplatePermissionsResponse.class, responseView = ResponseView.Restricted,
             requestHasSensitiveInfo = false,
             responseHasSensitiveInfo = false)
-public class ListIsoPermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd {
+public class ListIsoPermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd implements UserCmd {
     protected String getResponseName() {
         return "listisopermissionsresponse";
     }
@@ -48,9 +49,4 @@ public class ListIsoPermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd {
     protected boolean templateIsCorrectType(VirtualMachineTemplate template) {
         return template.getFormat().equals(ImageFormat.ISO);
     }
-
-    @Override
-    public void execute() {
-        executeWithView(ResponseView.Restricted);
-    }
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
index dee60f4..80d46de 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
@@ -24,6 +24,7 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
@@ -34,7 +35,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "listIsos", description = "Lists all available ISO files.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListIsosCmd extends BaseListTaggedResourcesCmd {
+public class ListIsosCmd extends BaseListTaggedResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListIsosCmd.class.getName());
 
     private static final String s_name = "listisosresponse";
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java
index f3e884c..a06b54f 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.GuestOSResponse;
 import org.apache.cloudstack.api.response.ListResponse;
@@ -39,7 +40,7 @@ import com.cloud.template.VirtualMachineTemplate;
 
 @APICommand(name = "registerIso", responseObject = TemplateResponse.class, description = "Registers an existing ISO into the CloudStack Cloud.", responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class RegisterIsoCmd extends BaseCmd {
+public class RegisterIsoCmd extends BaseCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(RegisterIsoCmd.class.getName());
 
     private static final String s_name = "registerisoresponse";
@@ -210,7 +211,7 @@ public class RegisterIsoCmd extends BaseCmd {
         VirtualMachineTemplate template = _templateService.registerIso(this);
         if (template != null) {
             ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-            List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(ResponseView.Restricted, template, zoneId, false);
+            List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(getResponseView(), template, zoneId, false);
             response.setResponses(templateResponses);
             response.setResponseName(getCommandName());
             setResponseObject(response);
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java
index 0d3c962..36e9b53 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java
@@ -23,6 +23,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
 import com.cloud.template.VirtualMachineTemplate;
@@ -30,7 +31,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "updateIso", description = "Updates an ISO file.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd {
+public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName());
     private static final String s_name = "updateisoresponse";
 
@@ -71,7 +72,7 @@ public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd {
     public void execute() {
         VirtualMachineTemplate result = _templateService.updateTemplate(this);
         if (result != null) {
-            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Restricted, result);
+            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(getResponseView(), result);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
index e3cde0b..77aaa6b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.List;
 
 import com.cloud.vm.VirtualMachine;
+
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse;
 import org.apache.log4j.Logger;
 
@@ -38,7 +40,7 @@ import com.cloud.utils.Pair;
 @APICommand(name = "listLoadBalancerRuleInstances", description = "List all virtual machine instances that are assigned to a load balancer rule.", responseObject = LoadBalancerRuleVmMapResponse.class, responseView = ResponseView.Restricted,
             requestHasSensitiveInfo = false,
             responseHasSensitiveInfo = true)
-public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
+public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListLoadBalancerRuleInstancesCmd.class.getName());
 
     private static final String s_name = "listloadbalancerruleinstancesresponse";
@@ -121,7 +123,7 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
             List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
 
             if (result != null) {
-                vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
+                vmResponses = _responseGenerator.createUserVmResponse(getResponseView(), "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
 
 
                 List<String> ipaddr = null;
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java
index befef99..d89205e 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java
@@ -26,6 +26,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.NetworkACLResponse;
 import org.apache.cloudstack.api.response.NetworkOfferingResponse;
@@ -47,7 +48,7 @@ import com.cloud.utils.net.NetUtils;
 
 @APICommand(name = "createNetwork", description = "Creates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateNetworkCmd extends BaseCmd {
+public class CreateNetworkCmd extends BaseCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(CreateNetworkCmd.class.getName());
 
     private static final String s_name = "createnetworkresponse";
@@ -310,7 +311,7 @@ public class CreateNetworkCmd extends BaseCmd {
         void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
         Network result = _networkService.createGuestNetwork(this);
         if (result != null) {
-            NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Restricted, result);
+            NetworkResponse response = _responseGenerator.createNetworkResponse(getResponseView(), result);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java
index a61c597..b737212 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java
@@ -27,6 +27,7 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.NetworkResponse;
 import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
@@ -38,7 +39,7 @@ import com.cloud.utils.Pair;
 
 @APICommand(name = "listNetworks", description = "Lists all available networks.", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListNetworksCmd extends BaseListTaggedResourcesCmd {
+public class ListNetworksCmd extends BaseListTaggedResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListNetworksCmd.class.getName());
     private static final String s_name = "listnetworksresponse";
 
@@ -164,7 +165,7 @@ public class ListNetworksCmd extends BaseListTaggedResourcesCmd {
         ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
         List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
         for (Network network : networks.first()) {
-            NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Restricted, network);
+            NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(getResponseView(), network);
             networkResponses.add(networkResponse);
         }
         response.setResponses(networkResponses, networks.second());
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java
index 3e93e5e..2ffa52b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java
@@ -27,6 +27,7 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.NetworkOfferingResponse;
 import org.apache.cloudstack.api.response.NetworkResponse;
 import org.apache.log4j.Logger;
@@ -40,7 +41,7 @@ import com.cloud.offering.NetworkOffering;
 
 @APICommand(name = "updateNetwork", description = "Updates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd {
+public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmd.class.getName());
 
     private static final String s_name = "updatenetworkresponse";
@@ -162,7 +163,7 @@ public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd {
 
         Network result = _networkService.updateGuestNetwork(this);
         if (result != null) {
-            NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Restricted, result);
+            NetworkResponse response = _responseGenerator.createNetworkResponse(getResponseView(), result);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java
index 3b17c34..db77916 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java
@@ -17,10 +17,7 @@
 package org.apache.cloudstack.api.command.user.project;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -31,6 +28,7 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiConstants.DomainDetails;
 import org.apache.cloudstack.api.BaseListAccountResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.TaggedResources;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.ProjectResponse;
 
@@ -97,22 +95,7 @@ public class ListProjectsCmd extends BaseListAccountResourcesCmd {
     }
 
     public Map<String, String> getTags() {
-        Map<String, String> tagsMap = null;
-        if (tags != null && !tags.isEmpty()) {
-            tagsMap = new HashMap<String, String>();
-            Collection<?> servicesCollection = tags.values();
-            Iterator<?> iter = servicesCollection.iterator();
-            while (iter.hasNext()) {
-                HashMap<String, String> services = (HashMap<String, String>)iter.next();
-                String key = services.get("key");
-                String value = services.get("value");
-                if (value == null) {
-                    throw new InvalidParameterValueException("No value is passed in for key " + key);
-                }
-                tagsMap.put(key, value);
-            }
-        }
-        return tagsMap;
+        return TaggedResources.parseKeyValueMap(tags, false);
     }
 
     public EnumSet<DomainDetails> getDetails() throws InvalidParameterValueException {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java
index 6aecc05..cde31cd 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java
@@ -17,9 +17,6 @@
 
 package org.apache.cloudstack.api.command.user.tag;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -31,6 +28,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.TaggedResources;
 import org.apache.cloudstack.api.response.SuccessResponse;
 
 import com.cloud.event.EventTypes;
@@ -74,19 +72,7 @@ public class CreateTagsCmd extends BaseAsyncCmd {
     }
 
     public Map<String, String> getTags() {
-        Map<String, String> tagsMap = null;
-        if (!tag.isEmpty()) {
-            tagsMap = new HashMap<String, String>();
-            Collection<?> servicesCollection = tag.values();
-            Iterator<?> iter = servicesCollection.iterator();
-            while (iter.hasNext()) {
-                HashMap<String, String> services = (HashMap<String, String>)iter.next();
-                String key = services.get("key");
-                String value = services.get("value");
-                tagsMap.put(key, value);
-            }
-        }
-        return tagsMap;
+        return TaggedResources.parseKeyValueMap(tag, true);
     }
 
     public List<String> getResourceIds() {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java
index db45f75..5490097 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java
@@ -30,6 +30,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -42,7 +43,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "copyTemplate", description = "Copies a template from one zone to another.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CopyTemplateCmd extends BaseAsyncCmd {
+public class CopyTemplateCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(CopyTemplateCmd.class.getName());
     private static final String s_name = "copytemplateresponse";
 
@@ -178,7 +179,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
             VirtualMachineTemplate template = _templateService.copyTemplate(this);
 
             if (template != null){
-                List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(ResponseView.Restricted,
+                List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(getResponseView(),
                                                             template, getDestinationZoneIds(), false);
                 TemplateResponse response = new TemplateResponse();
                 if (listResponse != null && !listResponse.isEmpty()) {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java
index aa8ecee..d598531 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java
@@ -21,6 +21,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.GuestOSResponse;
 import org.apache.cloudstack.api.response.SnapshotResponse;
 import org.apache.cloudstack.api.response.TemplateResponse;
@@ -53,7 +54,7 @@ import com.cloud.user.Account;
 @APICommand(name = "createTemplate", responseObject = TemplateResponse.class, description = "Creates a template of a virtual machine. " + "The virtual machine must be in a STOPPED state. "
         + "A template created from this command is automatically designated as a private template visible to the account that created it.", responseView = ResponseView.Restricted,
     requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateTemplateCmd extends BaseAsyncCreateCmd {
+public class CreateTemplateCmd extends BaseAsyncCreateCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(CreateTemplateCmd.class.getName());
     private static final String s_name = "createtemplateresponse";
 
@@ -301,15 +302,14 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
     public void execute() {
         CallContext.current().setEventDetails(
             "Template Id: " + getEntityUuid() + ((getSnapshotId() == null) ? " from volume Id: " + this._uuidMgr.getUuid(Volume.class, getVolumeId()) : " from snapshot Id: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId())));
-        VirtualMachineTemplate template = null;
-        template = _templateService.createPrivateTemplate(this);
+        VirtualMachineTemplate template = _templateService.createPrivateTemplate(this);
 
         if (template != null) {
             List<TemplateResponse> templateResponses;
             if (isBareMetal()) {
-                templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Restricted, template.getId(), vmId);
+                templateResponses = _responseGenerator.createTemplateResponses(getResponseView(), template.getId(), vmId);
             } else {
-                templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Restricted, template.getId(), snapshotId, volumeId, false);
+                templateResponses = _responseGenerator.createTemplateResponses(getResponseView(), template.getId(), snapshotId, volumeId, false);
             }
             TemplateResponse response = new TemplateResponse();
             if (templateResponses != null && !templateResponses.isEmpty()) {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
index 48f8fff..970c6b3 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java
@@ -21,6 +21,7 @@ import org.apache.log4j.Logger;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
 
 import com.cloud.storage.Storage.ImageFormat;
@@ -29,7 +30,7 @@ import com.cloud.template.VirtualMachineTemplate;
 @APICommand(name = "listTemplatePermissions", description = "List template visibility and all accounts that have permissions to view this template.", responseObject = TemplatePermissionsResponse.class, responseView = ResponseView.Restricted,
             requestHasSensitiveInfo = false,
             responseHasSensitiveInfo = false)
-public class ListTemplatePermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd {
+public class ListTemplatePermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd implements UserCmd {
     protected String getResponseName() {
         return "listtemplatepermissionsresponse";
     }
@@ -49,9 +50,4 @@ public class ListTemplatePermissionsCmd extends BaseListTemplateOrIsoPermissions
         return !template.getFormat().equals(ImageFormat.ISO);
     }
 
-    @Override
-    public void execute() {
-        executeWithView(ResponseView.Restricted);
-    }
-
 }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
index e7d3284..11e1425 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
@@ -36,7 +37,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "listTemplates", description = "List all public, private, and privileged templates.", responseObject = TemplateResponse.class, entityType = {VirtualMachineTemplate.class}, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
+public class ListTemplatesCmd extends BaseListTaggedResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListTemplatesCmd.class.getName());
 
     private static final String s_name = "listtemplatesresponse";
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
index 333b363..7e0002d 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
@@ -31,6 +31,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.GuestOSResponse;
 import org.apache.cloudstack.api.response.ListResponse;
@@ -45,7 +46,7 @@ import com.cloud.template.VirtualMachineTemplate;
 
 @APICommand(name = "registerTemplate", description = "Registers an existing template into the CloudStack cloud. ", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class RegisterTemplateCmd extends BaseCmd {
+public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(RegisterTemplateCmd.class.getName());
 
     private static final String s_name = "registertemplateresponse";
@@ -304,7 +305,7 @@ public class RegisterTemplateCmd extends BaseCmd {
             VirtualMachineTemplate template = _templateService.registerTemplate(this);
             if (template != null) {
                 ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-                List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Restricted,
+                List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(getResponseView(),
                         template, getZoneIds(), false);
                 response.setResponses(templateResponses);
                 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 0a01e48..ee60ad5 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
@@ -23,6 +23,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 
 import com.cloud.template.VirtualMachineTemplate;
@@ -30,7 +31,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "updateTemplate", description = "Updates attributes of a template.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd {
+public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName());
     private static final String s_name = "updatetemplateresponse";
 
@@ -70,7 +71,7 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd {
     public void execute() {
         VirtualMachineTemplate result = _templateService.updateTemplate(this);
         if (result != null) {
-            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Restricted, result);
+            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(getResponseView(), result);
             response.setObjectName("template");
             response.setTemplateType(result.getTemplateType().toString());//Template can be either USER or ROUTING type
             response.setResponseName(getCommandName());
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java
index a5a3f6e..454ca6d 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java
@@ -35,6 +35,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.NetworkResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -49,7 +50,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "addNicToVirtualMachine", description = "Adds VM to specified network by creating a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class AddNicToVMCmd extends BaseAsyncCmd {
+public class AddNicToVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(AddNicToVMCmd.class);
     private static final String s_name = "addnictovirtualmachineresponse";
 
@@ -164,7 +165,7 @@ public class AddNicToVMCmd extends BaseAsyncCmd {
         dc.add(VMDetails.valueOf("nics"));
         EnumSet<VMDetails> details = EnumSet.copyOf(dc);
         if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", details, result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
index 06acc32..8f137f7 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -24,6 +24,10 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.annotation.Nonnull;
+
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.acl.RoleType;
 import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.ACL;
@@ -35,6 +39,7 @@ import org.apache.cloudstack.api.BaseAsyncCreateCustomIdCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DiskOfferingResponse;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.HostResponse;
@@ -47,7 +52,6 @@ import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
 import org.apache.cloudstack.context.CallContext;
 import org.apache.commons.collections.MapUtils;
-import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.exception.ConcurrentOperationException;
@@ -68,7 +72,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction {
+public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd {
     public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName());
 
     private static final String s_name = "deployvirtualmachineresponse";
@@ -341,32 +345,8 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
             Iterator iter = ipsCollection.iterator();
             while (iter.hasNext()) {
                 HashMap<String, String> ips = (HashMap<String, String>)iter.next();
-                Long networkId;
-                Network network = _networkService.getNetwork(ips.get("networkid"));
-                if (network != null) {
-                    networkId = network.getId();
-                } else {
-                    try {
-                        networkId = Long.parseLong(ips.get("networkid"));
-                    } catch (NumberFormatException e) {
-                        throw new InvalidParameterValueException("Unable to translate and find entity with networkId: " + ips.get("networkid"));
-                    }
-                }
-                String requestedIp = ips.get("ip");
-                String requestedIpv6 = ips.get("ipv6");
-                String requestedMac = ips.get("mac");
-                if (requestedIpv6 != null) {
-                    requestedIpv6 = NetUtils.standardizeIp6Address(requestedIpv6);
-                }
-                if (requestedMac != null) {
-                    if(!NetUtils.isValidMac(requestedMac)) {
-                        throw new InvalidParameterValueException("Mac address is not valid: " + requestedMac);
-                    } else if(!NetUtils.isUnicastMac(requestedMac)) {
-                        throw new InvalidParameterValueException("Mac address is not unicast: " + requestedMac);
-                    }
-                    requestedMac = NetUtils.standardizeMacAddress(requestedMac);
-                }
-                IpAddresses addrs = new IpAddresses(requestedIp, requestedIpv6, requestedMac);
+                Long networkId = getNetworkIdFomIpMap(ips);
+                IpAddresses addrs = getIpAddressesFromIpMap(ips);
                 ipToNetworkMap.put(networkId, addrs);
             }
         }
@@ -374,6 +354,42 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
         return ipToNetworkMap;
     }
 
+    @Nonnull
+    private IpAddresses getIpAddressesFromIpMap(HashMap<String, String> ips) {
+        String requestedIp = ips.get("ip");
+        String requestedIpv6 = ips.get("ipv6");
+        String requestedMac = ips.get("mac");
+        if (requestedIpv6 != null) {
+            requestedIpv6 = NetUtils.standardizeIp6Address(requestedIpv6);
+        }
+        if (requestedMac != null) {
+            if(!NetUtils.isValidMac(requestedMac)) {
+                throw new InvalidParameterValueException("Mac address is not valid: " + requestedMac);
+            } else if(!NetUtils.isUnicastMac(requestedMac)) {
+                throw new InvalidParameterValueException("Mac address is not unicast: " + requestedMac);
+            }
+            requestedMac = NetUtils.standardizeMacAddress(requestedMac);
+        }
+        return new IpAddresses(requestedIp, requestedIpv6, requestedMac);
+    }
+
+    @Nonnull
+    private Long getNetworkIdFomIpMap(HashMap<String, String> ips) {
+        Long networkId;
+        final String networkid = ips.get("networkid");
+        Network network = _networkService.getNetwork(networkid);
+        if (network != null) {
+            networkId = network.getId();
+        } else {
+            try {
+                networkId = Long.parseLong(networkid);
+            } catch (NumberFormatException e) {
+                throw new InvalidParameterValueException("Unable to translate and find entity with networkId: " + networkid);
+            }
+        }
+        return networkId;
+    }
+
     public String getIpAddress() {
         return ipAddress;
     }
@@ -573,7 +589,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
         }
 
         if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java
index 7b359b7..30ab5b5 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java
@@ -30,6 +30,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -44,7 +45,7 @@ import com.cloud.vm.VirtualMachine;
 @APICommand(name = "destroyVirtualMachine", description = "Destroys a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
             requestHasSensitiveInfo = false,
             responseHasSensitiveInfo = true)
-public class DestroyVMCmd extends BaseAsyncCmd {
+public class DestroyVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(DestroyVMCmd.class.getName());
 
     private static final String s_name = "destroyvirtualmachineresponse";
@@ -137,7 +138,7 @@ public class DestroyVMCmd extends BaseAsyncCmd {
 
         UserVmResponse response = new UserVmResponse();
         if (result != null) {
-            List<UserVmResponse> responses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result);
+            List<UserVmResponse> responses = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result);
             if (responses != null && !responses.isEmpty()) {
                 response = responses.get(0);
             }
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java
index ff6acde..d468578 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
 
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserResponse;
 import org.apache.log4j.Logger;
 
@@ -51,7 +52,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class ListVMsCmd extends BaseListTaggedResourcesCmd {
+public class ListVMsCmd extends BaseListTaggedResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName());
 
     private static final String s_name = "listvirtualmachinesresponse";
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java
index b524257..6011bdb 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
 
@@ -40,7 +41,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "rebootVirtualMachine", description = "Reboots a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class RebootVMCmd extends BaseAsyncCmd {
+public class RebootVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(RebootVMCmd.class.getName());
     private static final String s_name = "rebootvirtualmachineresponse";
 
@@ -105,7 +106,7 @@ public class RebootVMCmd extends BaseAsyncCmd {
         UserVm result;
         result = _userVmService.rebootVirtualMachine(this);
         if (result !=null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java
index 677b482..5fd016c 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java
@@ -32,6 +32,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.NicResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -43,7 +44,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "removeNicFromVirtualMachine", description = "Removes VM from specified network by deleting a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class RemoveNicFromVMCmd extends BaseAsyncCmd {
+public class RemoveNicFromVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(RemoveNicFromVMCmd.class);
     private static final String s_name = "removenicfromvirtualmachineresponse";
 
@@ -110,7 +111,7 @@ public class RemoveNicFromVMCmd extends BaseAsyncCmd {
         dc.add(VMDetails.valueOf("nics"));
         EnumSet<VMDetails> details = EnumSet.copyOf(dc);
         if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", details, result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java
index 365f3ed..e9a2503 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
 
@@ -42,7 +43,7 @@ import com.cloud.vm.VirtualMachine;
                     "The virtual machine must be in a \"Stopped\" state and the template must already " +
         "support this feature for this command to take effect. [async]", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
     requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class ResetVMPasswordCmd extends BaseAsyncCmd {
+public class ResetVMPasswordCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ResetVMPasswordCmd.class.getName());
 
     private static final String s_name = "resetpasswordforvirtualmachineresponse";
@@ -121,7 +122,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd {
         CallContext.current().setEventDetails("Vm Id: " + getId());
         UserVm result = _userVmService.resetVMPassword(this, password);
         if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java
index db2c7ff..ce481d8 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java
@@ -29,6 +29,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.ProjectResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
@@ -44,7 +45,7 @@ import com.cloud.vm.VirtualMachine;
 @APICommand(name = "resetSSHKeyForVirtualMachine", responseObject = UserVmResponse.class, description = "Resets the SSH Key for virtual machine. " +
         "The virtual machine must be in a \"Stopped\" state. [async]", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
     requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class ResetVMSSHKeyCmd extends BaseAsyncCmd {
+public class ResetVMSSHKeyCmd extends BaseAsyncCmd implements UserCmd {
 
     public static final Logger s_logger = Logger.getLogger(ResetVMSSHKeyCmd.class.getName());
 
@@ -143,7 +144,7 @@ public class ResetVMSSHKeyCmd extends BaseAsyncCmd {
         UserVm result = _userVmService.resetVMSSHKey(this);
 
         if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java
index b2b4d03..2439a26 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java
@@ -27,6 +27,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -43,7 +44,7 @@ import com.cloud.vm.VirtualMachine;
 @APICommand(name = "restoreVirtualMachine", description = "Restore a VM to original template/ISO or new template/ISO", responseObject = UserVmResponse.class, since = "3.0.0", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
             requestHasSensitiveInfo = false,
             responseHasSensitiveInfo = true)
-public class RestoreVMCmd extends BaseAsyncCmd {
+public class RestoreVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(RestoreVMCmd.class);
     private static final String s_name = "restorevmresponse";
 
@@ -75,7 +76,7 @@ public class RestoreVMCmd extends BaseAsyncCmd {
         CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVmId()));
         result = _userVmService.restoreVM(this);
         if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java
index 631cef2..f7caf56 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java
@@ -35,6 +35,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.ServiceOfferingResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
@@ -51,7 +52,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "scaleVirtualMachine", description = "Scales the virtual machine to a new service offering.", responseObject = SuccessResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ScaleVMCmd extends BaseAsyncCmd {
+public class ScaleVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ScaleVMCmd.class.getName());
     private static final String s_name = "scalevirtualmachineresponse";
 
@@ -152,7 +153,7 @@ public class ScaleVMCmd extends BaseAsyncCmd {
             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
         }
         if (result != null){
-            List<UserVmResponse> responseList = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result);
+            List<UserVmResponse> responseList = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result);
             UserVmResponse response = responseList.get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java
index 5b3db85..365d406 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java
@@ -31,6 +31,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.HostResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -49,7 +50,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "startVirtualMachine", responseObject = UserVmResponse.class, description = "Starts a virtual machine.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class StartVMCmd extends BaseAsyncCmd {
+public class StartVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName());
 
     private static final String s_name = "startvirtualmachineresponse";
@@ -161,7 +162,7 @@ public class StartVMCmd extends BaseAsyncCmd {
             result = _userVmService.startVirtualMachine(this);
 
             if (result != null) {
-                UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+                UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
                 response.setResponseName(getCommandName());
                 setResponseObject(response);
             } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java
index bab8552..8e1c3cb 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
 
@@ -39,7 +40,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "stopVirtualMachine", responseObject = UserVmResponse.class, description = "Stops a virtual machine.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class StopVMCmd extends BaseAsyncCmd {
+public class StopVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName());
 
     private static final String s_name = "stopvirtualmachineresponse";
@@ -121,7 +122,7 @@ public class StopVMCmd extends BaseAsyncCmd {
         result = _userVmService.stopVirtualMachine(getId(), isForced());
 
         if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java
index 7262e23..ff533f8 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java
@@ -32,6 +32,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.NicResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -43,7 +44,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "updateDefaultNicForVirtualMachine", description = "Changes the default NIC on a VM", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class UpdateDefaultNicForVMCmd extends BaseAsyncCmd {
+public class UpdateDefaultNicForVMCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateDefaultNicForVMCmd.class);
     private static final String s_name = "updatedefaultnicforvirtualmachineresponse";
 
@@ -111,7 +112,7 @@ public class UpdateDefaultNicForVMCmd extends BaseAsyncCmd {
         dc.add(VMDetails.valueOf("nics"));
         EnumSet<VMDetails> details = EnumSet.copyOf(dc);
         if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", details, result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
index b040f79..2fdfd75 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
@@ -33,6 +33,7 @@ import org.apache.cloudstack.api.BaseCustomIdCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.GuestOSResponse;
 import org.apache.cloudstack.api.response.SecurityGroupResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
@@ -49,7 +50,7 @@ import com.cloud.vm.VirtualMachine;
         "new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. " +
         "Therefore, stop the VM manually before issuing this call.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
     requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction {
+public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction, UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateVMCmd.class.getName());
     private static final String s_name = "updatevirtualmachineresponse";
 
@@ -259,7 +260,7 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction
         CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
         UserVm result = _userVmService.updateVirtualMachine(this);
         if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java
index 216833b..8dc8f44 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java
@@ -32,6 +32,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.ServiceOfferingResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -47,7 +48,7 @@ import com.cloud.vm.VirtualMachine;
                                             "The virtual machine must be in a \"Stopped\" state for " +
         "this command to take effect.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class UpgradeVMCmd extends BaseCmd {
+public class UpgradeVMCmd extends BaseCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpgradeVMCmd.class.getName());
     private static final String s_name = "changeserviceforvirtualmachineresponse";
 
@@ -129,7 +130,7 @@ public class UpgradeVMCmd extends BaseCmd {
         UserVm result = _userVmService.upgradeVirtualMachine(this);
 
         if (result != null){
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java
index 8c3510b..9076ac2 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java
@@ -27,6 +27,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.VMSnapshotResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -42,7 +43,7 @@ import com.cloud.vm.snapshot.VMSnapshot;
 
 @APICommand(name = "revertToVMSnapshot", description = "Revert VM from a vmsnapshot.", responseObject = UserVmResponse.class, since = "4.2.0", responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
-public class RevertToVMSnapshotCmd extends BaseAsyncCmd {
+public class RevertToVMSnapshotCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(RevertToVMSnapshotCmd.class.getName());
     private static final String s_name = "reverttovmsnapshotresponse";
 
@@ -77,7 +78,7 @@ public class RevertToVMSnapshotCmd extends BaseAsyncCmd {
         CallContext.current().setEventDetails("vmsnapshot id: " + this._uuidMgr.getUuid(VMSnapshot.class, getVmSnapShotId()));
         UserVm result = _vmSnapshotService.revertToSnapshot(getVmSnapShotId());
         if (result != null) {
-            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted,
+            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(),
                     "virtualmachine", result).get(0);
             response.setResponseName(getCommandName());
             setResponseObject(response);
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java
index d53059e..a8a3a75 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java
@@ -16,17 +16,16 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.volume;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.TaggedResources;
 import org.apache.cloudstack.api.response.SuccessResponse;
-import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
 import com.cloud.server.ResourceTag;
@@ -58,19 +57,7 @@ public class AddResourceDetailCmd extends BaseAsyncCmd {
     /////////////////////////////////////////////////////
 
     public Map getDetails() {
-        Map<String, String> detailsMap = null;
-        if (!details.isEmpty()) {
-            detailsMap = new HashMap<String, String>();
-            Collection<?> servicesCollection = details.values();
-            Iterator<?> iter = servicesCollection.iterator();
-            while (iter.hasNext()) {
-                HashMap<String, String> services = (HashMap<String, String>)iter.next();
-                String key = services.get("key");
-                String value = services.get("value");
-                detailsMap.put(key, value);
-            }
-        }
-        return detailsMap;
+        return TaggedResources.parseKeyValueMap(details, true);
     }
 
     public ResourceTag.ResourceObjectType getResourceType() {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java
index 7e2b155..18770b2 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -39,7 +40,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "attachVolume", description = "Attaches a disk volume to a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class AttachVolumeCmd extends BaseAsyncCmd {
+public class AttachVolumeCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(AttachVolumeCmd.class.getName());
     private static final String s_name = "attachvolumeresponse";
 
@@ -119,7 +120,7 @@ public class AttachVolumeCmd extends BaseAsyncCmd {
         CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId()) + " VmId: " + this._uuidMgr.getUuid(VirtualMachine.class, getVirtualMachineId()));
         Volume result = _volumeService.attachVolumeToVM(this);
         if (result != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
+            VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), result);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java
index 6528109..a54bda1 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DiskOfferingResponse;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.ProjectResponse;
@@ -46,7 +47,7 @@ import com.cloud.vm.VirtualMachine;
 @APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Restricted, entityType = {
         Volume.class, VirtualMachine.class},
             requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd {
+public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(CreateVolumeCmd.class.getName());
     private static final String s_name = "createvolumeresponse";
 
@@ -223,7 +224,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd {
         CallContext.current().setEventDetails("Volume Id: " + getEntityUuid() + ((getSnapshotId() == null) ? "" : " from snapshot: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId())));
         Volume volume = _volumeService.createVolume(this);
         if (volume != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
+            VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), volume);
             //FIXME - have to be moved to ApiResponseHelper
             if (getSnapshotId() != null) {
                 Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java
index 55d30e3..1e38ca2 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -40,7 +41,7 @@ import com.cloud.vm.VirtualMachine;
 
 @APICommand(name = "detachVolume", description = "Detaches a disk volume from a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class DetachVolumeCmd extends BaseAsyncCmd {
+public class DetachVolumeCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(DetachVolumeCmd.class.getName());
     private static final String s_name = "detachvolumeresponse";
 
@@ -143,7 +144,7 @@ public class DetachVolumeCmd extends BaseAsyncCmd {
         CallContext.current().setEventDetails(getEventDescription());
         Volume result = _volumeService.detachVolumeFromVM(this);
         if (result != null){
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
+            VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), result);
             response.setResponseName("volume");
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java
index c858f49..aa40a24 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.ClusterResponse;
 import org.apache.cloudstack.api.response.DiskOfferingResponse;
 import org.apache.cloudstack.api.response.HostResponse;
@@ -40,7 +41,7 @@ import com.cloud.storage.Volume;
 
 @APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {
         Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListVolumesCmd extends BaseListTaggedResourcesCmd {
+public class ListVolumesCmd extends BaseListTaggedResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName());
 
     private static final String s_name = "listvolumesresponse";
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java
index f5d5e8c..44dd4bf 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java
@@ -24,6 +24,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.StoragePoolResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
 
@@ -33,7 +34,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "migrateVolume", description = "Migrate volume", responseObject = VolumeResponse.class, since = "3.0.0", responseView = ResponseView.Restricted, entityType = {
         Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class MigrateVolumeCmd extends BaseAsyncCmd {
+public class MigrateVolumeCmd extends BaseAsyncCmd implements UserCmd {
     private static final String s_name = "migratevolumeresponse";
 
     /////////////////////////////////////////////////////
@@ -112,7 +113,7 @@ public class MigrateVolumeCmd extends BaseAsyncCmd {
 
         result = _volumeService.migrateVolume(this);
         if (result != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
+            VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), result);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java
index 21127a7..304bb25 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java
@@ -27,6 +27,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DiskOfferingResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -42,7 +43,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "resizeVolume", description = "Resizes a volume", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ResizeVolumeCmd extends BaseAsyncCmd {
+public class ResizeVolumeCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ResizeVolumeCmd.class.getName());
 
     private static final String s_name = "resizevolumeresponse";
@@ -178,7 +179,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd {
         }
 
         if (volume != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
+            VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), volume);
             //FIXME - have to be moved to ApiResponseHelper
             response.setResponseName(getCommandName());
             setResponseObject(response);
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
index b4f8642..71fb576 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
@@ -29,6 +29,7 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.StoragePoolResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
 import org.apache.cloudstack.context.CallContext;
@@ -39,7 +40,7 @@ import com.cloud.storage.Volume;
 
 @APICommand(name = "updateVolume", description = "Updates the volume.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd {
+public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateVolumeCmd.class.getName());
     private static final String s_name = "updatevolumeresponse";
 
@@ -158,7 +159,7 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd {
         Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(),
                 getCustomId(), getEntityOwnerId(), getChainInfo());
         if (result != null) {
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
+            VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), result);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java
index 2802c00..236a4c8 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java
@@ -26,6 +26,7 @@ import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DiskOfferingResponse;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.ProjectResponse;
@@ -43,7 +44,7 @@ import com.cloud.storage.Volume;
 
 @APICommand(name = "uploadVolume", description = "Uploads a data disk.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UploadVolumeCmd extends BaseAsyncCmd {
+public class UploadVolumeCmd extends BaseAsyncCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UploadVolumeCmd.class.getName());
     private static final String s_name = "uploadvolumeresponse";
 
@@ -145,7 +146,7 @@ public class UploadVolumeCmd extends BaseAsyncCmd {
 
             Volume volume = _volumeService.uploadVolume(this);
             if (volume != null){
-            VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
+            VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), volume);
                 response.setResponseName(getCommandName());
                 setResponseObject(response);
             } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java
index e5e5017..8f6568f 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java
@@ -26,6 +26,7 @@ import org.apache.cloudstack.api.BaseAsyncCreateCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.ProjectResponse;
 import org.apache.cloudstack.api.response.VpcOfferingResponse;
@@ -42,7 +43,7 @@ import com.cloud.network.vpc.Vpc;
 
 @APICommand(name = "createVPC", description = "Creates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class CreateVPCCmd extends BaseAsyncCreateCmd {
+public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(CreateVPCCmd.class.getName());
     private static final String s_name = "createvpcresponse";
 
@@ -175,7 +176,7 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd {
         }
 
         if (vpc != null) {
-            VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Restricted, vpc);
+            VpcResponse response = _responseGenerator.createVpcResponse(getResponseView(), vpc);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java
index 9531b81..adcbf8b 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.VpcOfferingResponse;
 import org.apache.cloudstack.api.response.VpcResponse;
@@ -37,7 +38,7 @@ import com.cloud.utils.Pair;
 
 @APICommand(name = "listVPCs", description = "Lists VPCs", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListVPCsCmd extends BaseListTaggedResourcesCmd {
+public class ListVPCsCmd extends BaseListTaggedResourcesCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName());
     private static final String s_name = "listvpcsresponse";
 
@@ -136,7 +137,7 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd {
         ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
         List<VpcResponse> vpcResponses = new ArrayList<VpcResponse>();
         for (Vpc vpc : vpcs.first()) {
-            VpcResponse offeringResponse = _responseGenerator.createVpcResponse(ResponseView.Restricted, vpc);
+            VpcResponse offeringResponse = _responseGenerator.createVpcResponse(getResponseView(), vpc);
             vpcResponses.add(offeringResponse);
         }
 
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
index 1309334..92f02ca 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
@@ -29,6 +29,7 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.user.UserCmd;
 import org.apache.cloudstack.api.response.VpcResponse;
 
 import com.cloud.event.EventTypes;
@@ -37,7 +38,7 @@ import com.cloud.user.Account;
 
 @APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class},
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class UpdateVPCCmd extends BaseAsyncCustomIdCmd {
+public class UpdateVPCCmd extends BaseAsyncCustomIdCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName());
     private static final String s_name = "updatevpcresponse";
 
@@ -99,7 +100,7 @@ public class UpdateVPCCmd extends BaseAsyncCustomIdCmd {
     public void execute() {
         Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), isDisplayVpc());
         if (result != null) {
-            VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Restricted, result);
+            VpcResponse response = _responseGenerator.createVpcResponse(getResponseView(), result);
             response.setResponseName(getCommandName());
             setResponseObject(response);
         } else {
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java
index 34a5440..f7e3155 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java
@@ -16,9 +16,6 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.zone;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
@@ -28,15 +25,15 @@ import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
+import org.apache.cloudstack.api.TaggedResources;
+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.ZoneResponse;
 
-import com.cloud.exception.InvalidParameterValueException;
-
 @APICommand(name = "listZones", description = "Lists zones", responseObject = ZoneResponse.class, responseView = ResponseView.Restricted,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
-public class ListZonesCmd extends BaseListCmd {
+public class ListZonesCmd extends BaseListCmd implements UserCmd {
     public static final Logger s_logger = Logger.getLogger(ListZonesCmd.class.getName());
 
     private static final String s_name = "listzonesresponse";
@@ -97,22 +94,7 @@ public class ListZonesCmd extends BaseListCmd {
     }
 
     public Map<String, String> getTags() {
-        Map<String, String> tagsMap = null;
-        if (tags != null && !tags.isEmpty()) {
-            tagsMap = new HashMap<String, String>();
-            Collection<?> servicesCollection = tags.values();
-            Iterator<?> iter = servicesCollection.iterator();
-            while (iter.hasNext()) {
-                HashMap<String, String> services = (HashMap<String, String>)iter.next();
-                String key = services.get("key");
-                String value = services.get("value");
-                if (value == null) {
-                    throw new InvalidParameterValueException("No value is passed in for key " + key);
-                }
-                tagsMap.put(key, value);
-            }
-        }
-        return tagsMap;
+        return TaggedResources.parseKeyValueMap(tags, false);
     }
 
     /////////////////////////////////////////////////////
diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java
index 8a28305..d0cc8be 100644
--- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java
@@ -20,9 +20,7 @@ import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.apache.cloudstack.api.ResponseGenerator;
diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/ListCfgCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/ListCfgCmdTest.java
index 7911943..bb38189 100644
--- a/api/src/test/java/org/apache/cloudstack/api/command/test/ListCfgCmdTest.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/test/ListCfgCmdTest.java
@@ -23,9 +23,7 @@ import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
 import org.apache.cloudstack.api.ResponseGenerator;
diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateCfgCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateCfgCmdTest.java
index 65b9330..7e24f88 100644
--- a/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateCfgCmdTest.java
+++ b/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateCfgCmdTest.java
@@ -21,9 +21,7 @@ import junit.framework.TestCase;
 
 import org.apache.cloudstack.acl.RoleService;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
 import org.apache.cloudstack.api.ResponseGenerator;
diff --git a/core/src/test/java/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java b/core/src/test/java/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java
index 3cba492..f7d7562 100644
--- a/core/src/test/java/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java
+++ b/core/src/test/java/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java
@@ -27,8 +27,6 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
-import org.apache.cloudstack.ha.HAResource;
-import org.apache.cloudstack.kernel.Partition;
 import org.junit.Test;
 
 import com.cloud.agent.api.CheckOnHostCommand;
diff --git a/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java b/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java
index 75a864b..bf06918 100644
--- a/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java
+++ b/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java
@@ -29,7 +29,6 @@ import java.net.URL;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -57,7 +56,6 @@ import com.cloud.agent.api.GetStorageStatsAnswer;
 import com.cloud.agent.api.GetStorageStatsCommand;
 import com.cloud.agent.api.GetVmStatsAnswer;
 import com.cloud.agent.api.GetVmStatsCommand;
-import com.cloud.agent.api.HostVmStateReportEntry;
 import com.cloud.agent.api.ModifyStoragePoolCommand;
 import com.cloud.agent.api.StartAnswer;
 import com.cloud.agent.api.StartCommand;
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 ee56cbb..70f866d 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -1681,11 +1681,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
         Pair<List<VolumeJoinVO>, Integer> result = searchForVolumesInternal(cmd);
         ListResponse<VolumeResponse> response = new ListResponse<VolumeResponse>();
 
-        ResponseView respView = ResponseView.Restricted;
-        Account account = CallContext.current().getCallingAccount();
-        if (_accountMgr.isAdmin(account.getAccountId())) {
-            respView = ResponseView.Full;
-        }
+        ResponseView respView = cmd.getResponseView();
 
         List<VolumeResponse> volumeResponses = ViewResponseHelper.createVolumeResponse(respView, result.first().toArray(new VolumeJoinVO[result.first().size()]));
 
diff --git a/utils/src/main/java/com/cloud/utils/UriUtils.java b/utils/src/main/java/com/cloud/utils/UriUtils.java
index 6a580ca..14dce40 100644
--- a/utils/src/main/java/com/cloud/utils/UriUtils.java
+++ b/utils/src/main/java/com/cloud/utils/UriUtils.java
@@ -36,7 +36,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.function.Predicate;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -62,9 +64,12 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
 import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.exception.CloudRuntimeException;
-import com.google.common.base.Strings;
 
 public class UriUtils {
 
@@ -484,75 +489,65 @@ public class UriUtils {
         }
     }
 
-    // verify if a URI path is compliance with the file format given
-    private static void checkFormat(String format, String uripath) {
-        if ((!uripath.toLowerCase().endsWith("vhd")) && (!uripath.toLowerCase().endsWith("vhd.zip")) && (!uripath.toLowerCase().endsWith("vhd.bz2")) &&
-                (!uripath.toLowerCase().endsWith("vhdx")) && (!uripath.toLowerCase().endsWith("vhdx.gz")) &&
-                (!uripath.toLowerCase().endsWith("vhdx.bz2")) && (!uripath.toLowerCase().endsWith("vhdx.zip")) &&
-                (!uripath.toLowerCase().endsWith("vhd.gz")) && (!uripath.toLowerCase().endsWith("qcow2")) && (!uripath.toLowerCase().endsWith("qcow2.zip")) &&
-                (!uripath.toLowerCase().endsWith("qcow2.bz2")) && (!uripath.toLowerCase().endsWith("qcow2.gz")) && (!uripath.toLowerCase().endsWith("ova")) &&
-                (!uripath.toLowerCase().endsWith("ova.zip")) && (!uripath.toLowerCase().endsWith("ova.bz2")) && (!uripath.toLowerCase().endsWith("ova.gz")) &&
-                (!uripath.toLowerCase().endsWith("tar")) && (!uripath.toLowerCase().endsWith("tar.zip")) && (!uripath.toLowerCase().endsWith("tar.bz2")) &&
-                (!uripath.toLowerCase().endsWith("tar.gz")) && (!uripath.toLowerCase().endsWith("vmdk")) && (!uripath.toLowerCase().endsWith("vmdk.gz")) &&
-                (!uripath.toLowerCase().endsWith("vmdk.zip")) && (!uripath.toLowerCase().endsWith("vmdk.bz2")) && (!uripath.toLowerCase().endsWith("img")) &&
-                (!uripath.toLowerCase().endsWith("img.gz")) && (!uripath.toLowerCase().endsWith("img.zip")) && (!uripath.toLowerCase().endsWith("img.bz2")) &&
-                (!uripath.toLowerCase().endsWith("raw")) && (!uripath.toLowerCase().endsWith("raw.gz")) && (!uripath.toLowerCase().endsWith("raw.bz2")) &&
-                (!uripath.toLowerCase().endsWith("raw.zip")) && (!uripath.toLowerCase().endsWith("iso")) && (!uripath.toLowerCase().endsWith("iso.zip"))
-                && (!uripath.toLowerCase().endsWith("iso.bz2")) && (!uripath.toLowerCase().endsWith("iso.gz"))
-                && (!uripath.toLowerCase().endsWith("metalink"))) {
-            throw new IllegalArgumentException("Please specify a valid " + format.toLowerCase());
+    public static final Set<String> COMMPRESSION_FORMATS = ImmutableSet.of("zip", "bz2", "gz");
+
+    public static final Set<String> buildExtensionSet(boolean metalink, String... baseExtensions) {
+        final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+
+        for (String baseExtension : baseExtensions) {
+            builder.add("." + baseExtension);
+            for (String format : COMMPRESSION_FORMATS) {
+                builder.add("." + baseExtension + "." + format);
+            }
         }
 
-        if ((format.equalsIgnoreCase("vhd")
-                && (!uripath.toLowerCase().endsWith("vhd")
-                && !uripath.toLowerCase().endsWith("vhd.zip")
-                && !uripath.toLowerCase().endsWith("vhd.bz2")
-                && !uripath.toLowerCase().endsWith("vhd.gz")))
-                || (format.equalsIgnoreCase("vhdx")
-                && (!uripath.toLowerCase().endsWith("vhdx")
-                        && !uripath.toLowerCase().endsWith("vhdx.zip")
-                        && !uripath.toLowerCase().endsWith("vhdx.bz2")
-                        && !uripath.toLowerCase().endsWith("vhdx.gz")))
-                || (format.equalsIgnoreCase("qcow2")
-                && (!uripath.toLowerCase().endsWith("qcow2")
-                        && !uripath.toLowerCase().endsWith("qcow2.zip")
-                        && !uripath.toLowerCase().endsWith("qcow2.bz2")
-                        && !uripath.toLowerCase().endsWith("qcow2.gz"))
-                        && !uripath.toLowerCase().endsWith("metalink"))
-                || (format.equalsIgnoreCase("ova")
-                && (!uripath.toLowerCase().endsWith("ova")
-                        && !uripath.toLowerCase().endsWith("ova.zip")
-                        && !uripath.toLowerCase().endsWith("ova.bz2")
-                        && !uripath.toLowerCase().endsWith("ova.gz")
-                        && !uripath.toLowerCase().endsWith("metalink")))
-                || (format.equalsIgnoreCase("tar")
-                && (!uripath.toLowerCase().endsWith("tar")
-                        && !uripath.toLowerCase().endsWith("tar.zip")
-                        && !uripath.toLowerCase().endsWith("tar.bz2")
-                        && !uripath.toLowerCase().endsWith("tar.gz")))
-                || (format.equalsIgnoreCase("raw")
-                && (!uripath.toLowerCase().endsWith("img")
-                        && !uripath.toLowerCase().endsWith("img.zip")
-                        && !uripath.toLowerCase().endsWith("img.bz2")
-                        && !uripath.toLowerCase().endsWith("img.gz")
-                        && !uripath.toLowerCase().endsWith("raw")
-                        && !uripath.toLowerCase().endsWith("raw.bz2")
-                        && !uripath.toLowerCase().endsWith("raw.zip")
-                        && !uripath.toLowerCase().endsWith("raw.gz")))
-                || (format.equalsIgnoreCase("vmdk")
-                && (!uripath.toLowerCase().endsWith("vmdk")
-                        && !uripath.toLowerCase().endsWith("vmdk.zip")
-                        && !uripath.toLowerCase().endsWith("vmdk.bz2")
-                        && !uripath.toLowerCase().endsWith("vmdk.gz")))
-                || (format.equalsIgnoreCase("iso")
-                && (!uripath.toLowerCase().endsWith("iso")
-                        && !uripath.toLowerCase().endsWith("iso.zip")
-                        && !uripath.toLowerCase().endsWith("iso.bz2")
-                        && !uripath.toLowerCase().endsWith("iso.gz"))
-                        && !uripath.toLowerCase().endsWith("metalink"))) {
-            throw new IllegalArgumentException("Please specify a valid URL. URL:" + uripath + " is an invalid for the format " + format.toLowerCase());
+        if (metalink) {
+            builder.add(".metalink");
         }
 
+        return builder.build();
+    }
+
+    private final static Map<String, Set<String>> SUPPORTED_EXTENSIONS_BY_FORMAT =
+            ImmutableMap.<String, Set<String>>builder()
+                        .put("vhd", buildExtensionSet(false, "vhd"))
+                        .put("vhdx", buildExtensionSet(false, "vhdx"))
+                        .put("qcow2", buildExtensionSet(true, "qcow2"))
+                        .put("ova", buildExtensionSet(true, "ova"))
+                        .put("tar", buildExtensionSet(false, "tar"))
+                        .put("raw", buildExtensionSet(false, "img", "raw"))
+                        .put("vmdk", buildExtensionSet(false, "vmdk"))
+                        .put("iso", buildExtensionSet(true, "iso"))
+            .build();
+
+    public final static Set<String> getSupportedExtensions(String format) {
+        return SUPPORTED_EXTENSIONS_BY_FORMAT.get(format);
+    }
+
+    // verify if a URI path is compliance with the file format given
+    private static void checkFormat(String format, String uripath) {
+        final String lowerCaseUri = uripath.toLowerCase();
+
+        final boolean unknownExtensionForFormat = SUPPORTED_EXTENSIONS_BY_FORMAT.get(format.toLowerCase())
+                                                                                .stream()
+                                                                                .noneMatch(lowerCaseUri::endsWith);
+
+        if (unknownExtensionForFormat) {
+            final Predicate<Set<String>> uriMatchesAnyExtension =
+                    supportedExtensions -> supportedExtensions.stream()
+                                                              .anyMatch(lowerCaseUri::endsWith);
+
+            boolean unknownExtension = SUPPORTED_EXTENSIONS_BY_FORMAT.values()
+                                                                     .stream()
+                                                                     .noneMatch(uriMatchesAnyExtension);
+
+            if (unknownExtension) {
+                throw new IllegalArgumentException("Please specify a valid " + format.toLowerCase());
+            }
+
+            throw new IllegalArgumentException("Please specify a valid URL. "
+                                                       + "URL:" + uripath + " is an invalid for the format " + format.toLowerCase());
+        }
     }
 
     public static InputStream getInputStreamFromUrl(String url, String user, String password) {
diff --git a/utils/src/main/java/org/apache/cloudstack/utils/imagestore/ImageStoreUtil.java b/utils/src/main/java/org/apache/cloudstack/utils/imagestore/ImageStoreUtil.java
index f87669b..e0d84a6 100644
--- a/utils/src/main/java/org/apache/cloudstack/utils/imagestore/ImageStoreUtil.java
+++ b/utils/src/main/java/org/apache/cloudstack/utils/imagestore/ImageStoreUtil.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cloudstack.utils.imagestore;
 
+import com.cloud.utils.UriUtils;
 import com.cloud.utils.script.Script;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
@@ -57,7 +58,7 @@ public class ImageStoreUtil {
             return "";
         }
         // raw
-        if ((output.contains("x86 boot") || output.contains("data")) && (isCorrectExtension(uripath, "raw") || isCorrectExtension(uripath, "img"))) {
+        if ((output.contains("x86 boot") || output.contains("data")) && (isCorrectExtension(uripath, "raw"))) {
             s_logger.debug("File at path " + path + " looks like a raw image :" + output);
             return "";
         }
@@ -90,23 +91,20 @@ public class ImageStoreUtil {
         return output;
     }
 
-    private static boolean isCorrectExtension(String path, String ext) {
-        if (path.toLowerCase().endsWith(ext)
-            || path.toLowerCase().endsWith(ext + ".gz")
-            || path.toLowerCase().endsWith(ext + ".bz2")
-            || path.toLowerCase().endsWith(ext + ".zip")) {
-            return true;
-        }
-        return false;
+    public static boolean isCorrectExtension(String path, String format) {
+        final String lowerCasePath = path.toLowerCase();
+        return UriUtils.getSupportedExtensions(format)
+                .stream()
+                .filter(ext -> !ext.equals(".metalink"))
+                .anyMatch(lowerCasePath::endsWith);
     }
 
-    private static boolean isCompressedExtension(String path) {
-        if (path.toLowerCase().endsWith(".gz")
-            || path.toLowerCase().endsWith(".bz2")
-            || path.toLowerCase().endsWith(".zip")) {
-            return true;
-        }
-        return false;
+    public static boolean isCompressedExtension(String path) {
+        final String lowerCasePath = path.toLowerCase();
+        return UriUtils.COMMPRESSION_FORMATS
+                       .stream()
+                       .map(extension -> "." + extension)
+                       .anyMatch(lowerCasePath::endsWith);
     }
 }
 
diff --git a/utils/src/test/java/com/cloud/utils/UriUtilsParametrizedTest.java b/utils/src/test/java/com/cloud/utils/UriUtilsParametrizedTest.java
new file mode 100644
index 0000000..398eee6
--- /dev/null
+++ b/utils/src/test/java/com/cloud/utils/UriUtilsParametrizedTest.java
@@ -0,0 +1,158 @@
+//
+// 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.utils;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Set;
+
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.mockito.internal.matchers.InstanceOf;
+
+import com.google.common.collect.ImmutableSet;
+
+import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
+
+@RunWith(Parameterized.class)
+public class UriUtilsParametrizedTest {
+    @FunctionalInterface
+    public interface ThrowingBlock<E extends Exception> {
+        void execute() throws E;
+    }
+
+    private static final Set<String> COMMPRESSION_FORMATS = ImmutableSet.of("",".zip", ".bz2", ".gz");
+    private static final Set<String> ILLEGAL_COMMPRESSION_FORMATS = ImmutableSet.of(".7z", ".xz");
+    private final static Set<String> FORMATS = ImmutableSet.of(
+            "vhd",
+            "vhdx",
+            "qcow2",
+            "ova",
+            "tar",
+            "raw",
+            "img",
+            "vmdk",
+            "iso"
+    );
+    private final static Set<String> METALINK_FORMATS = ImmutableSet.of(
+            "qcow2",
+            "ova",
+            "iso"
+    );
+
+    private final static Set<String> ILLEGAL_EXTENSIONS = ImmutableSet.of(
+            "rar",
+            "supernova",
+            "straw",
+            "miso",
+            "tartar"
+    );
+
+    private String format;
+    private String url;
+    private boolean expectSuccess;
+    private boolean isMetalink;
+    private boolean isValidCompression;
+
+    private <E extends Exception> void assertThrows(ThrowingBlock<E> consumer, Class<E> exceptionClass) {
+        try {
+            consumer.execute();
+            Assert.fail("Expected " + exceptionClass.getName());
+        } catch(Exception e) {
+            Assert.assertThat(e, new InstanceOf(exceptionClass));
+        }
+    }
+
+    public UriUtilsParametrizedTest(String format, String url, boolean expectSuccess, boolean isMetalink, boolean isValidCompression) {
+        this.format = format;
+        this.url = url;
+        this.expectSuccess = expectSuccess;
+        this.isMetalink = isMetalink;
+        this.isValidCompression = isValidCompression;
+    }
+
+    @Parameterized.Parameters(name = "{index}: validateUrl(\"{0}\", \"{1}\") = {2}")
+    public static Collection<Object[]> data() {
+        String validBaseUri = "http://cloudstack.apache.org/images/image.";
+
+        LinkedList<Object[]> data = new LinkedList<>();
+
+        for (String format : FORMATS) {
+            if (format.equals("img")) continue;
+
+            final String realFormat = format;
+
+            for (String extension : FORMATS) {
+                final boolean expectSuccess = format.equals(extension.replace("img", "raw"));
+
+                for (String commpressionFormat : COMMPRESSION_FORMATS) {
+                    final String url = validBaseUri + extension + commpressionFormat;
+                    data.add(new Object[]{realFormat, url, expectSuccess, false, commpressionFormat.length() > 0});
+                }
+
+                for (String commpressionFormat : ILLEGAL_COMMPRESSION_FORMATS) {
+                    final String url = validBaseUri + extension + commpressionFormat;
+                    data.add(new Object[]{realFormat, url, false, false, false});
+                }
+            }
+
+            for (String illegalExtension : ILLEGAL_EXTENSIONS) {
+                data.add(new Object[]{format, validBaseUri + illegalExtension, false, false, false});
+
+                for (String commpressionFormat : COMMPRESSION_FORMATS) {
+                    final String url = validBaseUri + illegalExtension + commpressionFormat;
+                    data.add(new Object[]{realFormat, url, false, false, commpressionFormat.length() > 0});
+                }
+
+                for (String commpressionFormat : ILLEGAL_COMMPRESSION_FORMATS) {
+                    final String url = validBaseUri + illegalExtension + commpressionFormat;
+                    data.add(new Object[]{realFormat, url, false, false, false});
+                }
+            }
+
+            data.add(new Object[]{realFormat, validBaseUri + "metalink", METALINK_FORMATS.contains(realFormat), true, false});
+
+        }
+
+        return data;
+    }
+
+    @Test
+    public void validateUrl() {
+        if (expectSuccess) {
+            UriUtils.validateUrl(format, url);
+        } else {
+            assertThrows(() -> UriUtils.validateUrl(format, url), IllegalArgumentException.class);
+        }
+    }
+
+    @Test
+    public void isCorrectExtension() {
+        Assert.assertThat(ImageStoreUtil.isCorrectExtension(url, format), Matchers.is(expectSuccess && !isMetalink));
+    }
+
+    @Test
+    public void isCompressedExtension() {
+        Assert.assertThat(ImageStoreUtil.isCompressedExtension(url), Matchers.is(isValidCompression));
+    }
+}


Mime
View raw message