You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/07/06 21:03:38 UTC

[3/30] git commit: Resource tags: 1) Remove tag records when correspdonding cloudStack object gets removed 2) added "tags" request parameter to the banch of list* Api commands (listVirtualMachines, listSnapshots - all commands are listed in the resource

Resource tags: 1) Remove tag records when correspdonding cloudStack object gets removed
2) added "tags" request parameter to the banch of list* Api commands (listVirtualMachines, listSnapshots - all commands are listed in the resource tags functional spec)

Conflicts:

	api/src/com/cloud/api/commands/ListFirewallRulesCmd.java
	api/src/com/cloud/api/commands/ListPortForwardingRulesCmd.java
	api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java
	api/src/com/cloud/api/commands/ListSecurityGroupsCmd.java
	api/src/com/cloud/api/commands/ListSnapshotsCmd.java
	api/src/com/cloud/api/commands/ListVolumesCmd.java
	api/src/com/cloud/api/response/FirewallResponse.java
	api/src/com/cloud/api/response/IPAddressResponse.java
	api/src/com/cloud/api/response/VolumeResponse.java
	server/src/com/cloud/api/ApiDBUtils.java
	server/src/com/cloud/api/ApiResponseHelper.java
	server/src/com/cloud/network/NetworkManagerImpl.java
	server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
	server/src/com/cloud/network/security/dao/SecurityGroupDaoImpl.java
	server/src/com/cloud/server/ManagementServerImpl.java
	server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
	server/src/com/cloud/vm/dao/UserVmDaoImpl.java


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

Branch: refs/heads/vpc
Commit: 7acf8585b1c54f372ad76383cd8f6e0ad5f212dd
Parents: 7349842
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Tue Jul 3 14:43:52 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Fri Jul 6 11:43:31 2012 -0700

----------------------------------------------------------------------
 .../com/cloud/api/BaseListDomainResourcesCmd.java  |    9 +-
 .../api/BaseListProjectAndAccountResourcesCmd.java |    2 +-
 .../com/cloud/api/BaseListTaggedResourcesCmd.java  |   47 +
 api/src/com/cloud/api/ResponseGenerator.java       |    3 +-
 .../cloud/api/commands/ListFirewallRulesCmd.java   |    5 +-
 api/src/com/cloud/api/commands/ListIsosCmd.java    |    4 +-
 .../api/commands/ListLoadBalancerRulesCmd.java     |    5 +-
 .../com/cloud/api/commands/ListNetworksCmd.java    |    4 +-
 .../api/commands/ListPortForwardingRulesCmd.java   |   14 +-
 .../api/commands/ListPublicIpAddressesCmd.java     |   13 +-
 .../cloud/api/commands/ListSecurityGroupsCmd.java  |   30 +-
 .../com/cloud/api/commands/ListSnapshotsCmd.java   |   13 +-
 api/src/com/cloud/api/commands/ListTagsCmd.java    |    2 +-
 .../com/cloud/api/commands/ListTemplatesCmd.java   |    5 +-
 api/src/com/cloud/api/commands/ListVMsCmd.java     |    4 +-
 api/src/com/cloud/api/commands/ListVolumesCmd.java |   13 +-
 .../com/cloud/api/response/FirewallResponse.java   |   12 +-
 .../cloud/api/response/FirewallRuleResponse.java   |   11 +-
 .../com/cloud/api/response/IPAddressResponse.java  |   10 +-
 .../cloud/api/response/LoadBalancerResponse.java   |   11 +-
 .../com/cloud/api/response/NetworkResponse.java    |    7 +
 .../cloud/api/response/SecurityGroupResponse.java  |    9 +-
 .../com/cloud/api/response/SnapshotResponse.java   |   10 +-
 .../com/cloud/api/response/TemplateResponse.java   |    8 +
 api/src/com/cloud/api/response/UserVmResponse.java |    9 +-
 api/src/com/cloud/api/response/VolumeResponse.java |   12 +-
 .../com/cloud/server/TaggedResourceService.java    |    2 +
 .../src/com/cloud/netapp/dao/VolumeDaoImpl.java    |    1 +
 server/src/com/cloud/api/ApiDBUtils.java           |    6 +-
 server/src/com/cloud/api/ApiResponseHelper.java    |  171 +++-
 .../src/com/cloud/network/NetworkManagerImpl.java  |   49 +-
 .../cloud/network/dao/FirewallRulesDaoImpl.java    |   25 +-
 .../com/cloud/network/dao/IPAddressDaoImpl.java    |   17 +
 .../com/cloud/network/dao/LoadBalancerDaoImpl.java |    2 +-
 .../src/com/cloud/network/dao/NetworkDaoImpl.java  |   17 +-
 .../network/firewall/FirewallManagerImpl.java      |   30 +
 .../network/lb/LoadBalancingRulesManagerImpl.java  |   29 +
 .../com/cloud/network/rules/RulesManagerImpl.java  |   30 +-
 .../network/security/SecurityGroupManagerImpl.java |   29 +
 .../network/security/dao/SecurityGroupDaoImpl.java |   40 +-
 .../src/com/cloud/server/ManagementServerImpl.java |   48 +-
 .../src/com/cloud/storage/StorageManagerImpl.java  |   28 +
 .../src/com/cloud/storage/dao/SnapshotDaoImpl.java |   19 +-
 .../com/cloud/storage/dao/VMTemplateDaoImpl.java   |   35 +-
 .../src/com/cloud/storage/dao/VolumeDaoImpl.java   |   18 +
 .../storage/snapshot/SnapshotManagerImpl.java      |   30 +
 .../com/cloud/tags/TaggedResourceManagerImpl.java  |    6 +
 server/src/com/cloud/tags/dao/ResourceTagDao.java  |   13 +
 .../com/cloud/tags/dao/ResourceTagsDaoImpl.java    |   31 +-
 server/src/com/cloud/vm/UserVmManager.java         |    3 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java     |   33 +-
 server/src/com/cloud/vm/dao/UserVmDao.java         |    1 +
 server/src/com/cloud/vm/dao/UserVmDaoImpl.java     | 1008 ++++++++-------
 server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java |   18 +
 .../test/com/cloud/vm/MockUserVmManagerImpl.java   |    2 +-
 55 files changed, 1380 insertions(+), 633 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/BaseListDomainResourcesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/BaseListDomainResourcesCmd.java b/api/src/com/cloud/api/BaseListDomainResourcesCmd.java
index f301d9b..9571e12 100644
--- a/api/src/com/cloud/api/BaseListDomainResourcesCmd.java
+++ b/api/src/com/cloud/api/BaseListDomainResourcesCmd.java
@@ -18,14 +18,17 @@ package com.cloud.api;
 
 public abstract class BaseListDomainResourcesCmd extends BaseListCmd {
 
-    @Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "If set to false, list only resources belonging to the command's caller; if set to true - list resources that the caller is authorized to see. Default value is false")
+    @Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "If set to false, " +
+    		"list only resources belonging to the command's caller; if set to true - list resources that the caller is authorized to see. Default value is false")
     private Boolean listAll;
 
     @IdentityMapper(entityTableName = "domain")
-    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "list only resources belonging to the domain specified")
+    @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "list only resources" +
+    		" belonging to the domain specified")
     private Long domainId;
 
-    @Parameter(name = ApiConstants.IS_RECURSIVE, type = CommandType.BOOLEAN, description = "defaults to false, but if true, lists all resources from the parent specified by the domainId till leaves.")
+    @Parameter(name = ApiConstants.IS_RECURSIVE, type = CommandType.BOOLEAN, description = "defaults to false," +
+    		" but if true, lists all resources from the parent specified by the domainId till leaves.")
     private Boolean recursive;
 
     public boolean listAll() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/BaseListProjectAndAccountResourcesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/BaseListProjectAndAccountResourcesCmd.java b/api/src/com/cloud/api/BaseListProjectAndAccountResourcesCmd.java
index 8120ad1..78e7001 100644
--- a/api/src/com/cloud/api/BaseListProjectAndAccountResourcesCmd.java
+++ b/api/src/com/cloud/api/BaseListProjectAndAccountResourcesCmd.java
@@ -19,7 +19,7 @@ package com.cloud.api;
 public abstract class BaseListProjectAndAccountResourcesCmd extends BaseListAccountResourcesCmd {
 
     @IdentityMapper(entityTableName = "projects")
-    @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "list firewall rules by project")
+    @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "list objects by project")
     private Long projectId;
 
     public Long getProjectId() {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/BaseListTaggedResourcesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/BaseListTaggedResourcesCmd.java b/api/src/com/cloud/api/BaseListTaggedResourcesCmd.java
new file mode 100644
index 0000000..9a70b10
--- /dev/null
+++ b/api/src/com/cloud/api/BaseListTaggedResourcesCmd.java
@@ -0,0 +1,47 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.api;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import com.cloud.exception.InvalidParameterValueException;
+
+/**
+ * @author Alena Prokharchyk
+ */
+public abstract class BaseListTaggedResourcesCmd extends BaseListProjectAndAccountResourcesCmd{
+    @Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List resources by tags (key/value pairs)")
+    private Map tags;
+    
+    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;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java
index 864a9e6..92b1fb3 100755
--- a/api/src/com/cloud/api/ResponseGenerator.java
+++ b/api/src/com/cloud/api/ResponseGenerator.java
@@ -285,9 +285,10 @@ public interface ResponseGenerator {
 
     /**
      * @param resourceTag
+     * @param keyValueOnly TODO
      * @return
      */
-    ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag);
+    ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag, boolean keyValueOnly);
 
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java b/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java
index f0bbba6..d0729b6 100644
--- a/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java
+++ b/api/src/com/cloud/api/commands/ListFirewallRulesCmd.java
@@ -22,8 +22,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseCmd.CommandType;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -32,7 +31,7 @@ import com.cloud.api.response.ListResponse;
 import com.cloud.network.rules.FirewallRule;
 
 @Implementation(description="Lists all firewall rules for an IP address.", responseObject=FirewallResponse.class)
-public class ListFirewallRulesCmd extends BaseListProjectAndAccountResourcesCmd {
+public class ListFirewallRulesCmd extends BaseListTaggedResourcesCmd {
     public static final Logger s_logger = Logger.getLogger(ListFirewallRulesCmd.class.getName());
 
     private static final String s_name = "listfirewallrulesresponse";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListIsosCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListIsosCmd.java b/api/src/com/cloud/api/commands/ListIsosCmd.java
index 93ef1f1..35a996e 100755
--- a/api/src/com/cloud/api/commands/ListIsosCmd.java
+++ b/api/src/com/cloud/api/commands/ListIsosCmd.java
@@ -24,7 +24,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
 import com.cloud.api.BaseCmd.CommandType;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -37,7 +37,7 @@ import com.cloud.user.UserContext;
 import com.cloud.utils.Pair;
 
 @Implementation(description="Lists all available ISO files.", responseObject=TemplateResponse.class)
-public class ListIsosCmd extends BaseListProjectAndAccountResourcesCmd {
+public class ListIsosCmd extends BaseListTaggedResourcesCmd {
     public static final Logger s_logger = Logger.getLogger(ListIsosCmd.class.getName());
 
     private static final String s_name = "listisosresponse";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListLoadBalancerRulesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListLoadBalancerRulesCmd.java b/api/src/com/cloud/api/commands/ListLoadBalancerRulesCmd.java
index d30abdf..43b0540 100644
--- a/api/src/com/cloud/api/commands/ListLoadBalancerRulesCmd.java
+++ b/api/src/com/cloud/api/commands/ListLoadBalancerRulesCmd.java
@@ -22,8 +22,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseCmd.CommandType;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -32,7 +31,7 @@ import com.cloud.api.response.LoadBalancerResponse;
 import com.cloud.network.rules.LoadBalancer;
 
 @Implementation(description = "Lists load balancer rules.", responseObject = LoadBalancerResponse.class)
-public class ListLoadBalancerRulesCmd extends BaseListProjectAndAccountResourcesCmd {
+public class ListLoadBalancerRulesCmd extends BaseListTaggedResourcesCmd {
     public static final Logger s_logger = Logger.getLogger(ListLoadBalancerRulesCmd.class.getName());
 
     private static final String s_name = "listloadbalancerrulesresponse";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListNetworksCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java
index 8f665b9..63ed95b 100644
--- a/api/src/com/cloud/api/commands/ListNetworksCmd.java
+++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -32,7 +32,7 @@ import com.cloud.network.Network;
 
 
 @Implementation(description="Lists all available networks.", responseObject=NetworkResponse.class)
-public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd {
+public class ListNetworksCmd extends BaseListTaggedResourcesCmd {
     public static final Logger s_logger = Logger.getLogger(ListNetworksCmd.class.getName());
     private static final String _name = "listnetworksresponse";
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListPortForwardingRulesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListPortForwardingRulesCmd.java b/api/src/com/cloud/api/commands/ListPortForwardingRulesCmd.java
index e75fae5..499a574 100644
--- a/api/src/com/cloud/api/commands/ListPortForwardingRulesCmd.java
+++ b/api/src/com/cloud/api/commands/ListPortForwardingRulesCmd.java
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -30,12 +30,12 @@ import com.cloud.api.response.FirewallRuleResponse;
 import com.cloud.api.response.ListResponse;
 import com.cloud.network.rules.PortForwardingRule;
 
-@Implementation(description="Lists all port forwarding rules for an IP address.", responseObject=FirewallRuleResponse.class)
-public class ListPortForwardingRulesCmd extends BaseListProjectAndAccountResourcesCmd {
-    public static final Logger s_logger = Logger.getLogger(ListPortForwardingRulesCmd.class.getName());
-
-    private static final String s_name = "listportforwardingrulesresponse";
-
+@Implementation(description="Lists all port forwarding rules for an IP address.", responseObject=FirewallRuleResponse.class)
+public class ListPortForwardingRulesCmd extends BaseListTaggedResourcesCmd {
+    public static final Logger s_logger = Logger.getLogger(ListPortForwardingRulesCmd.class.getName());
+
+    private static final String s_name = "listportforwardingrulesresponse";
+
     /////////////////////////////////////////////////////
     //////////////// API parameters /////////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java b/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java
index 9ca8a95..0fecc0e 100644
--- a/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java
+++ b/api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -31,12 +31,13 @@ import com.cloud.api.response.ListResponse;
 import com.cloud.async.AsyncJob;
 import com.cloud.network.IpAddress;
 
-@Implementation(description="Lists all public ip addresses", responseObject=IPAddressResponse.class)
-public class ListPublicIpAddressesCmd extends BaseListProjectAndAccountResourcesCmd {
-    public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName());
-
-    private static final String s_name = "listpublicipaddressesresponse";
 
+@Implementation(description="Lists all public ip addresses", responseObject=IPAddressResponse.class)
+public class ListPublicIpAddressesCmd extends BaseListTaggedResourcesCmd {
+    public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName());
+
+    private static final String s_name = "listpublicipaddressesresponse";
+
     /////////////////////////////////////////////////////
     //////////////// API parameters /////////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListSecurityGroupsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListSecurityGroupsCmd.java b/api/src/com/cloud/api/commands/ListSecurityGroupsCmd.java
index 5891ada..6da023a 100644
--- a/api/src/com/cloud/api/commands/ListSecurityGroupsCmd.java
+++ b/api/src/com/cloud/api/commands/ListSecurityGroupsCmd.java
@@ -21,8 +21,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseCmd.CommandType;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -31,19 +30,20 @@ import com.cloud.api.response.SecurityGroupResponse;
 import com.cloud.async.AsyncJob;
 import com.cloud.network.security.SecurityGroupRules;
 
-@Implementation(description="Lists security groups", responseObject=SecurityGroupResponse.class)
-public class ListSecurityGroupsCmd extends BaseListProjectAndAccountResourcesCmd {
-	public static final Logger s_logger = Logger.getLogger(ListSecurityGroupsCmd.class.getName());
-
-    private static final String s_name = "listsecuritygroupsresponse";
-
-    /////////////////////////////////////////////////////
-    //////////////// API parameters /////////////////////
-    /////////////////////////////////////////////////////
-
-    @Parameter(name=ApiConstants.SECURITY_GROUP_NAME, type=CommandType.STRING, description="lists security groups by name")
-    private String securityGroupName;
-
+
+@Implementation(description="Lists security groups", responseObject=SecurityGroupResponse.class)
+public class ListSecurityGroupsCmd extends BaseListTaggedResourcesCmd {
+	public static final Logger s_logger = Logger.getLogger(ListSecurityGroupsCmd.class.getName());
+
+    private static final String s_name = "listsecuritygroupsresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name=ApiConstants.SECURITY_GROUP_NAME, type=CommandType.STRING, description="lists security groups by name")
+    private String securityGroupName;
+
     @IdentityMapper(entityTableName="vm_instance")
     @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, description="lists security groups by virtual machine id")
     private Long virtualMachineId;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListSnapshotsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListSnapshotsCmd.java b/api/src/com/cloud/api/commands/ListSnapshotsCmd.java
index 67ea187..d7b2c9e 100644
--- a/api/src/com/cloud/api/commands/ListSnapshotsCmd.java
+++ b/api/src/com/cloud/api/commands/ListSnapshotsCmd.java
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -31,12 +31,13 @@ import com.cloud.api.response.SnapshotResponse;
 import com.cloud.async.AsyncJob;
 import com.cloud.storage.Snapshot;
 
-@Implementation(description="Lists all available snapshots for the account.", responseObject=SnapshotResponse.class)
-public class ListSnapshotsCmd extends BaseListProjectAndAccountResourcesCmd {
-	public static final Logger s_logger = Logger.getLogger(ListSnapshotsCmd.class.getName());
-
-    private static final String s_name = "listsnapshotsresponse";
 
+@Implementation(description="Lists all available snapshots for the account.", responseObject=SnapshotResponse.class)
+public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd {
+	public static final Logger s_logger = Logger.getLogger(ListSnapshotsCmd.class.getName());
+
+    private static final String s_name = "listsnapshotsresponse";
+
     /////////////////////////////////////////////////////
     //////////////// API parameters /////////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListTagsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListTagsCmd.java b/api/src/com/cloud/api/commands/ListTagsCmd.java
index 5e7acb5..2c22679 100644
--- a/api/src/com/cloud/api/commands/ListTagsCmd.java
+++ b/api/src/com/cloud/api/commands/ListTagsCmd.java
@@ -63,7 +63,7 @@ public class ListTagsCmd extends BaseListProjectAndAccountResourcesCmd{
       ListResponse<ResourceTagResponse> response = new ListResponse<ResourceTagResponse>();
       List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
       for (ResourceTag tag : tags) {
-          ResourceTagResponse tagResponse = _responseGenerator.createResourceTagResponse(tag);
+          ResourceTagResponse tagResponse = _responseGenerator.createResourceTagResponse(tag, false);
           tagResponses.add(tagResponse);
       }
       response.setResponses(tagResponses);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListTemplatesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListTemplatesCmd.java b/api/src/com/cloud/api/commands/ListTemplatesCmd.java
index 8286492..c1002b8 100755
--- a/api/src/com/cloud/api/commands/ListTemplatesCmd.java
+++ b/api/src/com/cloud/api/commands/ListTemplatesCmd.java
@@ -23,7 +23,8 @@ import java.util.Set;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseCmd.CommandType;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -36,7 +37,7 @@ import com.cloud.user.UserContext;
 import com.cloud.utils.Pair;
 
 @Implementation(description="List all public, private, and privileged templates.", responseObject=TemplateResponse.class)
-public class ListTemplatesCmd extends BaseListProjectAndAccountResourcesCmd {
+public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
     public static final Logger s_logger = Logger.getLogger(ListTemplatesCmd.class.getName());
 
     private static final String s_name = "listtemplatesresponse";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListVMsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListVMsCmd.java b/api/src/com/cloud/api/commands/ListVMsCmd.java
index 402cd1b..acc459b 100755
--- a/api/src/com/cloud/api/commands/ListVMsCmd.java
+++ b/api/src/com/cloud/api/commands/ListVMsCmd.java
@@ -24,7 +24,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
 import com.cloud.api.ApiConstants.VMDetails;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -35,7 +35,7 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.uservm.UserVm;
 
 @Implementation(description="List the virtual machines owned by the account.", responseObject=UserVmResponse.class)
-public class ListVMsCmd extends BaseListProjectAndAccountResourcesCmd {
+public class ListVMsCmd extends BaseListTaggedResourcesCmd {
     public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName());
 
     private static final String s_name = "listvirtualmachinesresponse";

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/commands/ListVolumesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListVolumesCmd.java b/api/src/com/cloud/api/commands/ListVolumesCmd.java
index 2f07ea2..e0393a9 100755
--- a/api/src/com/cloud/api/commands/ListVolumesCmd.java
+++ b/api/src/com/cloud/api/commands/ListVolumesCmd.java
@@ -22,7 +22,7 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
+import com.cloud.api.BaseListTaggedResourcesCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
@@ -31,12 +31,13 @@ import com.cloud.api.response.VolumeResponse;
 import com.cloud.async.AsyncJob;
 import com.cloud.storage.Volume;
 
-@Implementation(description="Lists all volumes.", responseObject=VolumeResponse.class)
-public class ListVolumesCmd extends BaseListProjectAndAccountResourcesCmd {
-    public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName());
-
-    private static final String s_name = "listvolumesresponse";
 
+@Implementation(description="Lists all volumes.", responseObject=VolumeResponse.class)
+public class ListVolumesCmd extends BaseListTaggedResourcesCmd {
+    public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName());
+
+    private static final String s_name = "listvolumesresponse";
+
     /////////////////////////////////////////////////////
     //////////////// API parameters /////////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/FirewallResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/FirewallResponse.java b/api/src/com/cloud/api/response/FirewallResponse.java
index 0aa5989..6b68f3a 100644
--- a/api/src/com/cloud/api/response/FirewallResponse.java
+++ b/api/src/com/cloud/api/response/FirewallResponse.java
@@ -16,9 +16,11 @@
 // under the License.
 package com.cloud.api.response;
 
+import java.util.List;
+
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
 public class FirewallResponse extends BaseResponse {
@@ -51,6 +53,9 @@ public class FirewallResponse extends BaseResponse {
 
     @SerializedName(ApiConstants.ICMP_CODE) @Param(description = "error code for this icmp message")
     private Integer icmpCode;
+    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with the rule", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
 
     public void setId(Long id) {
         this.id.setValue(id);
@@ -91,7 +96,8 @@ public class FirewallResponse extends BaseResponse {
     public void setIcmpCode(Integer icmpCode) {
         this.icmpCode = icmpCode;
     }
-
- 
     
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/FirewallRuleResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/FirewallRuleResponse.java b/api/src/com/cloud/api/response/FirewallRuleResponse.java
index fe1e4aa..252ad0d 100644
--- a/api/src/com/cloud/api/response/FirewallRuleResponse.java
+++ b/api/src/com/cloud/api/response/FirewallRuleResponse.java
@@ -16,11 +16,14 @@
 // under the License.
 package com.cloud.api.response;
 
+import java.util.List;
+
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
+@SuppressWarnings("unused")
 public class FirewallRuleResponse extends BaseResponse{
     @SerializedName(ApiConstants.ID) @Param(description="the ID of the port forwarding rule")
     private IdentityProxy id = new IdentityProxy("firewall_rules");
@@ -61,7 +64,8 @@ public class FirewallRuleResponse extends BaseResponse{
     @SerializedName(ApiConstants.CIDR_LIST) @Param(description="the cidr list to forward traffic from")
     private String cidrList;
     
-    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with the rule", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
     
     public Long getId() {
         return id.getValue();
@@ -167,4 +171,7 @@ public class FirewallRuleResponse extends BaseResponse{
         this.cidrList = cidrs;
     }
     
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/IPAddressResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/IPAddressResponse.java b/api/src/com/cloud/api/response/IPAddressResponse.java
index f61494c..c1f080c 100644
--- a/api/src/com/cloud/api/response/IPAddressResponse.java
+++ b/api/src/com/cloud/api/response/IPAddressResponse.java
@@ -17,10 +17,11 @@
 package com.cloud.api.response;
 
 import java.util.Date;
+import java.util.List;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
@@ -96,6 +97,9 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR
     
     @SerializedName(ApiConstants.PURPOSE) @Param(description="purpose of the IP address. In Acton this value is not null for Ips with isSystem=true, and can have either StaticNat or LB value")
     private String purpose;
+    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with ip address", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
 
 /*    
     @SerializedName(ApiConstants.JOB_ID) @Param(description="shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the volume")
@@ -216,4 +220,8 @@ public class IPAddressResponse extends BaseResponse implements ControlledEntityR
     public void setPurpose(String purpose) {
         this.purpose = purpose;
     }
+    
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/LoadBalancerResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/LoadBalancerResponse.java b/api/src/com/cloud/api/response/LoadBalancerResponse.java
index ab1d679..016bccc 100644
--- a/api/src/com/cloud/api/response/LoadBalancerResponse.java
+++ b/api/src/com/cloud/api/response/LoadBalancerResponse.java
@@ -16,9 +16,11 @@
 // under the License.
 package com.cloud.api.response;
 
+import java.util.List;
+
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
@@ -83,6 +85,9 @@ public class LoadBalancerResponse extends BaseResponse implements ControlledEnti
     @SerializedName(ApiConstants.ZONE_ID)
     @Param(description = "the id of the zone the rule belongs to")
     private IdentityProxy zoneId = new IdentityProxy("data_center");
+    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with load balancer", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
 
     public void setId(Long id) {
         this.id.setValue(id);
@@ -149,5 +154,9 @@ public class LoadBalancerResponse extends BaseResponse implements ControlledEnti
     public void setProjectName(String projectName) {
         this.projectName = projectName;
     }
+    
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
    
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/NetworkResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/NetworkResponse.java b/api/src/com/cloud/api/response/NetworkResponse.java
index 4c16240..17b84b8 100644
--- a/api/src/com/cloud/api/response/NetworkResponse.java
+++ b/api/src/com/cloud/api/response/NetworkResponse.java
@@ -134,6 +134,9 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
     @SerializedName(ApiConstants.CAN_USE_FOR_DEPLOY) @Param(description="list networks available for vm deployment")
     private Boolean canUseForDeploy;
     
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with network", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
+    
     public void setId(Long id) {
         this.id.setValue(id);
     }
@@ -279,4 +282,8 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
     public void setCanUseForDeploy(Boolean canUseForDeploy) {
         this.canUseForDeploy = canUseForDeploy;
     }
+    
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/SecurityGroupResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/SecurityGroupResponse.java b/api/src/com/cloud/api/response/SecurityGroupResponse.java
index 862b0fe..5c6deed 100644
--- a/api/src/com/cloud/api/response/SecurityGroupResponse.java
+++ b/api/src/com/cloud/api/response/SecurityGroupResponse.java
@@ -19,8 +19,8 @@ package com.cloud.api.response;
 import java.util.List;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
@@ -55,6 +55,9 @@ public class SecurityGroupResponse extends BaseResponse implements ControlledEnt
     @SerializedName("egressrule")  @Param(description="the list of egress rules associated with the security group", responseObject = SecurityGroupRuleResponse.class)
     private List<SecurityGroupRuleResponse> egressRules;
     
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with the rule", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
+    
     public void setId(Long id) {
         this.id.setValue(id);
     }
@@ -130,4 +133,8 @@ public class SecurityGroupResponse extends BaseResponse implements ControlledEnt
     public void setProjectName(String projectName) {
         this.projectName = projectName;
     }
+    
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/SnapshotResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/SnapshotResponse.java b/api/src/com/cloud/api/response/SnapshotResponse.java
index d945e36..71b1b14 100644
--- a/api/src/com/cloud/api/response/SnapshotResponse.java
+++ b/api/src/com/cloud/api/response/SnapshotResponse.java
@@ -17,11 +17,12 @@
 package com.cloud.api.response;
 
 import java.util.Date;
+import java.util.List;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
 import com.cloud.storage.Snapshot;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
@@ -79,6 +80,9 @@ public class SnapshotResponse extends BaseResponse implements ControlledEntityRe
     @SerializedName(ApiConstants.STATE)
     @Param(description = "the state of the snapshot. BackedUp means that snapshot is ready to be used; Creating - the snapshot is being allocated on the primary storage; BackingUp - the snapshot is being backed up on secondary storage")
     private Snapshot.Status state;
+    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with snapshot", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
 
     @Override
     public Long getObjectId() {
@@ -154,4 +158,8 @@ public class SnapshotResponse extends BaseResponse implements ControlledEntityRe
     public void setProjectName(String projectName) {
         this.projectName = projectName;
     }
+    
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/TemplateResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/TemplateResponse.java b/api/src/com/cloud/api/response/TemplateResponse.java
index 8a4456c..5c3d339 100755
--- a/api/src/com/cloud/api/response/TemplateResponse.java
+++ b/api/src/com/cloud/api/response/TemplateResponse.java
@@ -17,6 +17,7 @@
 package com.cloud.api.response;
 
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 import com.cloud.api.ApiConstants;
@@ -128,6 +129,9 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
     @SerializedName(ApiConstants.DETAILS) @Param(description="additional key/value details tied with template")
     private Map details;
     
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with tempate", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
+    
 
     @Override
     public Long getObjectId() {
@@ -277,4 +281,8 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
     public void setDetails(Map details) {
     	this.details = details;
     }
+    
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/UserVmResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/UserVmResponse.java b/api/src/com/cloud/api/response/UserVmResponse.java
index e3ec3a3..652e026 100755
--- a/api/src/com/cloud/api/response/UserVmResponse.java
+++ b/api/src/com/cloud/api/response/UserVmResponse.java
@@ -20,8 +20,8 @@ import java.util.Date;
 import java.util.List;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
@@ -154,6 +154,9 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
     
     @SerializedName(ApiConstants.INSTANCE_NAME) @Param(description="instance name of the user vm; this parameter is returned to the ROOT admin only", since="3.0.1")
     private String instanceName;
+    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with vm", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
 
 	public void setHypervisor(String hypervisor) {
 		this.hypervisor = hypervisor;
@@ -341,4 +344,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
     public void setInstanceName(String instanceName) {
         this.instanceName = instanceName;
     }
+
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/api/response/VolumeResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/VolumeResponse.java b/api/src/com/cloud/api/response/VolumeResponse.java
index 8659525..b563390 100755
--- a/api/src/com/cloud/api/response/VolumeResponse.java
+++ b/api/src/com/cloud/api/response/VolumeResponse.java
@@ -17,10 +17,11 @@
 package com.cloud.api.response;
 
 import java.util.Date;
+import java.util.List;
 
 import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
 import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
@@ -150,6 +151,9 @@ public class VolumeResponse extends BaseResponse implements ControlledEntityResp
     @SerializedName(ApiConstants.STATUS)
     @Param(description="the status of the volume")
     private String status;
+    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with volume", responseObject = ResourceTagResponse.class)
+    private List<ResourceTagResponse> tags;
 
     @Override
     public Long getObjectId() {
@@ -292,5 +296,9 @@ public class VolumeResponse extends BaseResponse implements ControlledEntityResp
     @Override
     public void setProjectName(String projectName) {
         this.projectName = projectName;
-    }   
+    }
+    
+    public void setTags(List<ResourceTagResponse> tags) {
+        this.tags = tags;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/api/src/com/cloud/server/TaggedResourceService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/server/TaggedResourceService.java b/api/src/com/cloud/server/TaggedResourceService.java
index e57b884..51a4779 100644
--- a/api/src/com/cloud/server/TaggedResourceService.java
+++ b/api/src/com/cloud/server/TaggedResourceService.java
@@ -60,4 +60,6 @@ public interface TaggedResourceService {
      * @return
      */
     boolean deleteTags(List<String> resourceIds, TaggedResourceType resourceType, Map<String, String> tags);
+    
+    List<? extends ResourceTag> listByResourceTypeAndId(TaggedResourceType type, long resourceId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/plugins/file-systems/netapp/src/com/cloud/netapp/dao/VolumeDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/file-systems/netapp/src/com/cloud/netapp/dao/VolumeDaoImpl.java b/plugins/file-systems/netapp/src/com/cloud/netapp/dao/VolumeDaoImpl.java
index 9c23410..4a83429 100644
--- a/plugins/file-systems/netapp/src/com/cloud/netapp/dao/VolumeDaoImpl.java
+++ b/plugins/file-systems/netapp/src/com/cloud/netapp/dao/VolumeDaoImpl.java
@@ -96,4 +96,5 @@ public class VolumeDaoImpl extends GenericDaoBase<NetappVolumeVO, Long> implemen
         
         return listBy(sc, searchFilter);
     }
+  
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index 3d5b14f..cfc71de 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -81,6 +81,7 @@ import com.cloud.projects.ProjectService;
 import com.cloud.resource.ResourceManager;
 import com.cloud.server.Criteria;
 import com.cloud.server.ManagementServer;
+import com.cloud.server.ResourceTag;
 import com.cloud.server.ResourceTag.TaggedResourceType;
 import com.cloud.server.StatsCollector;
 import com.cloud.server.TaggedResourceService;
@@ -301,7 +302,7 @@ public class ApiDBUtils {
     }
 
     public static List<UserVmVO> searchForUserVMs(Criteria c, List<Long> permittedAccounts) {
-        return _userVmMgr.searchForUserVMs(c, _accountDao.findById(Account.ACCOUNT_ID_SYSTEM), null, false, permittedAccounts, false, null);
+        return _userVmMgr.searchForUserVMs(c, _accountDao.findById(Account.ACCOUNT_ID_SYSTEM), null, false, permittedAccounts, false, null, null);
     }
 
     public static List<? extends StoragePoolVO> searchForStoragePools(Criteria c) {
@@ -766,4 +767,7 @@ public class ApiDBUtils {
         return _taggedResourceService.getUuid(resourceId, resourceType);
     }
 
+    public static List<? extends ResourceTag> listByResourceTypeAndId(TaggedResourceType type, long resourceId) {
+        return _taggedResourceService.listByResourceTypeAndId(type, resourceId);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 8c8d53b..305fdeb 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -157,6 +157,7 @@ import com.cloud.projects.ProjectAccount;
 import com.cloud.projects.ProjectInvitation;
 import com.cloud.server.Criteria;
 import com.cloud.server.ResourceTag;
+import com.cloud.server.ResourceTag.TaggedResourceType;
 import com.cloud.storage.DiskOfferingVO;
 import com.cloud.storage.GuestOS;
 import com.cloud.storage.GuestOSCategoryVO;
@@ -533,6 +534,16 @@ public class ApiResponseHelper implements ResponseGenerator {
         snapshotResponse.setName(snapshot.getName());
         snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId()));
         snapshotResponse.setState(snapshot.getStatus());
+        
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Snapshot, snapshot.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        snapshotResponse.setTags(tagResponses);
+        
         snapshotResponse.setObjectName("snapshot");
         return snapshotResponse;
     }
@@ -803,6 +814,15 @@ public class ApiResponseHelper implements ResponseGenerator {
             }
         }
         
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.PublicIpAddress, ipAddress.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        ipResponse.setTags(tagResponses);
+        
         ipResponse.setObjectName("ipaddress");
         return ipResponse;
     }
@@ -830,6 +850,15 @@ public class ApiResponseHelper implements ResponseGenerator {
         lbResponse.setState(stateToSet);
         populateOwner(lbResponse, loadBalancer);
         lbResponse.setZoneId(publicIp.getDataCenterId());
+        
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.UserVm, loadBalancer.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        lbResponse.setTags(tagResponses);
 
         lbResponse.setObjectName("loadbalancer");
         return lbResponse;
@@ -1118,6 +1147,15 @@ public class ApiResponseHelper implements ResponseGenerator {
             }
         }
         
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Volume, volume.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        volResponse.setTags(tagResponses);
+        
         volResponse.setExtractable(isExtractable);
         volResponse.setObjectName("volume");
         return volResponse;
@@ -1265,6 +1303,16 @@ public class ApiResponseHelper implements ResponseGenerator {
         if (state.equals(FirewallRule.State.Revoke)) {
             stateToSet = "Deleting";
         }
+        
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.PortForwardingRule, fwRule.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        response.setTags(tagResponses);
+        
         response.setState(stateToSet);
         response.setObjectName("portforwardingrule");
         return response;
@@ -1541,6 +1589,15 @@ public class ApiResponseHelper implements ResponseGenerator {
                 userVmResponse.setNics(nicResponses);
             }
             
+            //set tag information
+            List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.UserVm, userVm.getId());
+            List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+            for (ResourceTag tag : tags) {
+                ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+                tagResponses.add(tagResponse);
+            }
+            userVmResponse.setTags(tagResponses);
+            
             IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(userVm.getId());
             if (ip != null) {
                 userVmResponse.setPublicIpId(ip.getId());
@@ -1816,6 +1873,21 @@ public class ApiResponseHelper implements ResponseGenerator {
         Account owner = ApiDBUtils.findAccountById(result.getAccountId());
         populateAccount(response, owner.getId());
         populateDomain(response, owner.getDomainId());
+        
+        //set tag information
+        List<? extends ResourceTag> tags = null;
+        if (result.getFormat() == ImageFormat.ISO) {
+            tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.ISO, result.getId());
+        } else {
+            tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Template, result.getId());
+        }
+        
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        response.setTags(tagResponses);
 
         response.setObjectName("iso");
         return response;
@@ -2002,6 +2074,20 @@ public class ApiResponseHelper implements ResponseGenerator {
         templateResponse.setChecksum(template.getChecksum());
 
         templateResponse.setTemplateTag(template.getTemplateTag());
+        
+        //set tag information
+        List<? extends ResourceTag> tags = null;
+        if (template.getFormat() == ImageFormat.ISO) {
+            tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.ISO, template.getId());
+        } else {
+            tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Template, template.getId());
+        }
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        templateResponse.setTags(tagResponses);
 
         templateResponse.setObjectName("template");
         responses.add(templateResponse);
@@ -2240,6 +2326,15 @@ public class ApiResponseHelper implements ResponseGenerator {
                         egressRulesResponse.add(ruleData);
                     }
                 }
+                //set tag information
+                List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.UserVm, networkGroup.getId());
+                List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+                for (ResourceTag tag : tags) {
+                    ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+                    tagResponses.add(tagResponse);
+                }
+                netGrpResponse.setTags(tagResponses);
+                
                 netGrpResponse
                         .setSecurityGroupIngressRules(ingressRulesResponse);
                 netGrpResponse.setSecurityGroupEgressRules(egressRulesResponse);
@@ -2247,7 +2342,7 @@ public class ApiResponseHelper implements ResponseGenerator {
             netGrpResponse.setObjectName("securitygroup");
             netGrpResponses.add(netGrpResponse);
         }
-
+        
         response.setResponses(netGrpResponses);
         return response;
     }
@@ -2893,6 +2988,15 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setSpecifyIpRanges(network.getSpecifyIpRanges());
         response.setCanUseForDeploy(ApiDBUtils.canUseForDeploy(network));
 
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Network, network.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        response.setTags(tagResponses);
+
         response.setObjectName("network");
         return response;
     }
@@ -2954,6 +3058,15 @@ public class ApiResponseHelper implements ResponseGenerator {
 
         response.setIcmpCode(fwRule.getIcmpCode());
         response.setIcmpType(fwRule.getIcmpType());
+        
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.FirewallRule, fwRule.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        response.setTags(tagResponses);
 
         response.setState(stateToSet);
         response.setObjectName("firewallrule");
@@ -3076,6 +3189,15 @@ public class ApiResponseHelper implements ResponseGenerator {
         userVmResponse.setNics(new ArrayList<NicResponse>(nicResponses));
         userVmResponse.setPublicIpId(userVmData.getPublicIpId());
         userVmResponse.setPublicIp(userVmData.getPublicIp());
+        
+        //set tag information
+        List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.UserVm, userVmData.getId());
+        List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
+        for (ResourceTag tag : tags) {
+            ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
+            tagResponses.add(tagResponse);
+        }
+        userVmResponse.setTags(tagResponses);
 
         return userVmResponse;
     }
@@ -3408,34 +3530,37 @@ public class ApiResponseHelper implements ResponseGenerator {
     }
     
     @Override
-    public ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag) {
+    public ResourceTagResponse createResourceTagResponse(ResourceTag resourceTag, boolean keyValueOnly) {
         ResourceTagResponse response = new ResourceTagResponse();
         response.setKey(resourceTag.getKey());
         response.setValue(resourceTag.getValue());
-        response.setResourceType(resourceTag.getResourceType().toString());        
-        response.setId(ApiDBUtils.getUuid(String.valueOf(resourceTag.getResourceId()),resourceTag.getResourceType()));
-        Long accountId = resourceTag.getAccountId();
-        Long domainId = resourceTag.getDomainId();
-        if (accountId != null) {
-            Account account = ApiDBUtils.findAccountByIdIncludingRemoved(resourceTag.getAccountId());
-
-            if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
-                // find the project
-                Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
-                response.setProjectId(project.getId());
-                response.setProjectName(project.getName());
-            } else {
-                response.setAccountName(account.getAccountName());
-            }
-        }
         
-        if (domainId != null) {
-            response.setDomainId(domainId);
-            response.setDomainName(ApiDBUtils.findDomainById(domainId).getName());
+        if (!keyValueOnly) {
+            response.setResourceType(resourceTag.getResourceType().toString());        
+            response.setId(ApiDBUtils.getUuid(String.valueOf(resourceTag.getResourceId()),resourceTag.getResourceType()));
+            Long accountId = resourceTag.getAccountId();
+            Long domainId = resourceTag.getDomainId();
+            if (accountId != null) {
+                Account account = ApiDBUtils.findAccountByIdIncludingRemoved(resourceTag.getAccountId());
+
+                if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+                    // find the project
+                    Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
+                    response.setProjectId(project.getId());
+                    response.setProjectName(project.getName());
+                } else {
+                    response.setAccountName(account.getAccountName());
+                }
+            }
+            
+            if (domainId != null) {
+                response.setDomainId(domainId);
+                response.setDomainName(ApiDBUtils.findDomainById(domainId).getName());
+            }
+            
+            response.setCustomer(resourceTag.getCustomer());
         }
         
-        response.setCustomer(resourceTag.getCustomer());
-        
         response.setObjectName("tag");
   
         return response;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index de20374..f26d40d 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -163,6 +163,9 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.org.Grouping;
 import com.cloud.projects.Project;
 import com.cloud.projects.ProjectManager;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.ResourceTagVO;
+import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.AccountVO;
@@ -306,6 +309,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
     NetworkServiceMapDao _ntwkSrvcDao;
     @Inject
     StorageNetworkManager _stnwMgr;
+    @Inject
+    ResourceTagDao _resourceTagDao;
 
     private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5);
 
@@ -2700,6 +2705,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
         boolean isRecursive = cmd.isRecursive();
         Boolean specifyIpRanges = cmd.getSpecifyIpRanges();
         Boolean canUseForDeploy = cmd.canUseForDeploy();
+        Map<String, String> tags = cmd.getTags();
 
         // 1) default is system to false if not specified
         // 2) reset parameter to false if it's specified by the regular user
@@ -2783,6 +2789,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
         zoneSearch.and("networkType", zoneSearch.entity().getNetworkType(), SearchCriteria.Op.EQ);
         sb.join("zoneSearch", zoneSearch, sb.entity().getDataCenterId(), zoneSearch.entity().getId(), JoinBuilder.JoinType.INNER);
         sb.and("removed", sb.entity().getRemoved(), Op.NULL);
+        
+        if (tags != null && !tags.isEmpty()) {
+            SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+            for (int count=0; count < tags.size(); count++) {
+                tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
+                tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
+                tagSearch.cp();
+            }
+            tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+            sb.groupBy(sb.entity().getId());
+            sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
+        }
 
         if (permittedAccounts.isEmpty()) {
             SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
@@ -2802,22 +2820,25 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
             // Get domain level networks
             if (domainId != null) {
                 networksToReturn
-                        .addAll(listDomainLevelNetworks(
-                                buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter,
-                                domainId));
+                        .addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId,
+                                guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired,
+                                specifyIpRanges, tags), searchFilter,domainId));
             }
 
             if (!permittedAccounts.isEmpty()) {
                 networksToReturn.addAll(listAccountSpecificNetworks(
-                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter,
+                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, 
+                                physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, tags), searchFilter,
                         permittedAccounts));
             } else if (domainId == null || listAll) {
                 networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(
-                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges), searchFilter, path,
+                        buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, 
+                                physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, tags), searchFilter, path,
                         isRecursive));
             }
         } else {
-            networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges),
+            networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId,
+                    guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges, tags),
                     searchFilter);
         }
 
@@ -2873,8 +2894,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
         return hasFreeIps;
     }
 
-    private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId,
-            String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges) {
+
+    private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, 
+            Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId,
+            String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Map<String, String> tags) {
         SearchCriteria<NetworkVO> sc = sb.create();
 
         if (isSystem != null) {
@@ -2922,6 +2945,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
         if (specifyIpRanges != null) {
             sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges);
         }
+        
+        if (tags != null && !tags.isEmpty()) {
+            int count = 0;
+            sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Network.toString());
+            for (String key : tags.keySet()) {
+                sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
+                sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
+                count++;
+            }
+        }
 
         return sc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java b/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
index 5833bab..b9825b5 100644
--- a/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
+++ b/server/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
@@ -26,6 +26,8 @@ import com.cloud.network.rules.FirewallRule.FirewallRuleType;
 import com.cloud.network.rules.FirewallRule.Purpose;
 import com.cloud.network.rules.FirewallRule.State;
 import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
@@ -49,6 +51,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
     protected final GenericSearchBuilder<FirewallRuleVO, Long> RulesByIpCount;
 
     protected final FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao = ComponentLocator.inject(FirewallRulesCidrsDaoImpl.class);
+    ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
 
     protected FirewallRulesDaoImpl() {
         super();
@@ -268,5 +271,25 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
         sc.setParameters("ipAddressId", sourceIpId);
         return customSearch(sc, null).get(0);
     }
-
+    
+    @Override
+    @DB
+    public boolean remove(Long id) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        FirewallRuleVO entry = findById(id);
+        if (entry != null) {
+            if (entry.getPurpose() == Purpose.LoadBalancing) {
+                _tagsDao.removeBy(id, TaggedResourceType.LoadBalancer);
+            } else if (entry.getPurpose() == Purpose.PortForwarding) {
+                _tagsDao.removeBy(id, TaggedResourceType.PortForwardingRule);
+            } else if (entry.getPurpose() == Purpose.Firewall) {
+                _tagsDao.removeBy(id, TaggedResourceType.FirewallRule);
+            }
+        }
+        boolean result = super.remove(id);
+        txn.commit();
+        return result;
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/network/dao/IPAddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java
index 6e265df..bf6d152 100755
--- a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java
+++ b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java
@@ -30,6 +30,8 @@ import com.cloud.dc.VlanVO;
 import com.cloud.dc.dao.VlanDaoImpl;
 import com.cloud.network.IPAddressVO;
 import com.cloud.network.IpAddress.State;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
@@ -55,6 +57,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
     protected final GenericSearchBuilder<IPAddressVO, Long> AllocatedIpCountForAccount;    
     protected final VlanDaoImpl _vlanDao = ComponentLocator.inject(VlanDaoImpl.class);
     protected GenericSearchBuilder<IPAddressVO, Long> CountFreePublicIps;
+    ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
     
     
     // make it public for JUnit test
@@ -312,4 +315,18 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
         sc.setParameters("networkId", networkId);
         return customSearch(sc, null).get(0);       
     }
+    
+    @Override
+    @DB
+    public boolean remove(Long id) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        IPAddressVO entry = findById(id);
+        if (entry != null) {
+            _tagsDao.removeBy(id, TaggedResourceType.SecurityGroup);
+        }
+        boolean result = super.remove(id);
+        txn.commit();
+        return result;
+    }   
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/network/dao/LoadBalancerDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/LoadBalancerDaoImpl.java b/server/src/com/cloud/network/dao/LoadBalancerDaoImpl.java
index e08b786..f624bfa 100644
--- a/server/src/com/cloud/network/dao/LoadBalancerDaoImpl.java
+++ b/server/src/com/cloud/network/dao/LoadBalancerDaoImpl.java
@@ -132,5 +132,5 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
         sc.setParameters("state", State.Add.toString(), State.Revoke.toString());
         return listBy(sc);
     }
-
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/network/dao/NetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/NetworkDaoImpl.java b/server/src/com/cloud/network/dao/NetworkDaoImpl.java
index 1285487..a5b036b 100644
--- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java
+++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java
@@ -38,6 +38,8 @@ import com.cloud.network.Networks.Mode;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.offerings.NetworkOfferingVO;
 import com.cloud.offerings.dao.NetworkOfferingDaoImpl;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
 import com.cloud.utils.component.ComponentLocator;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
@@ -68,7 +70,7 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
     private final GenericSearchBuilder<NetworkVO, Integer> NetworksCount;
     final SearchBuilder<NetworkVO> SourceNATSearch;
     final GenericSearchBuilder<NetworkVO, Long>  CountByZoneAndURI;
-
+    ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
 
     NetworkAccountDaoImpl _accountsDao = ComponentLocator.inject(NetworkAccountDaoImpl.class);
     NetworkDomainDaoImpl _domainsDao = ComponentLocator.inject(NetworkDomainDaoImpl.class);
@@ -486,4 +488,17 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
         return listBy(sc);
     }
 
+    @Override
+    @DB
+    public boolean remove(Long id) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        NetworkVO entry = findById(id);
+        if (entry != null) {
+            _tagsDao.removeBy(id, TaggedResourceType.Network);
+        }
+        boolean result = super.remove(id);
+        txn.commit();
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
index ee0082e..c27df89 100644
--- a/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
+++ b/server/src/com/cloud/network/firewall/FirewallManagerImpl.java
@@ -58,6 +58,9 @@ import com.cloud.network.rules.FirewallRuleVO;
 import com.cloud.network.rules.PortForwardingRuleVO;
 import com.cloud.network.rules.dao.PortForwardingRulesDao;
 import com.cloud.projects.Project.ListProjectResourcesCriteria;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.ResourceTagVO;
+import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.DomainManager;
@@ -67,6 +70,7 @@ import com.cloud.utils.component.Inject;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
@@ -105,6 +109,8 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
     PortForwardingRulesDao _pfRulesDao;
     @Inject
     UserVmDao _vmDao;
+    @Inject
+    ResourceTagDao _resourceTagDao;
 
     private boolean _elbEnabled = false;
 
@@ -198,6 +204,7 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
     public List<? extends FirewallRule> listFirewallRules(ListFirewallRulesCmd cmd) {
         Long ipId = cmd.getIpAddressId();
         Long id = cmd.getId();
+        Map<String, String> tags = cmd.getTags();
 
         Account caller = UserContext.current().getCaller();
         List<Long> permittedAccounts = new ArrayList<Long>();
@@ -223,6 +230,19 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
         sb.and("id", sb.entity().getId(), Op.EQ);
         sb.and("ip", sb.entity().getSourceIpAddressId(), Op.EQ);
         sb.and("purpose", sb.entity().getPurpose(), Op.EQ);
+        
+
+        if (tags != null && !tags.isEmpty()) {
+        SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+        for (int count=0; count < tags.size(); count++) {
+            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
+            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
+            tagSearch.cp();
+        }
+        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+        sb.groupBy(sb.entity().getId());
+        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
+    }
 
         SearchCriteria<FirewallRuleVO> sc = sb.create();
         _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@@ -230,6 +250,16 @@ public class FirewallManagerImpl implements FirewallService, FirewallManager, Ma
         if (id != null) {
             sc.setParameters("id", id);
         }
+        
+        if (tags != null && !tags.isEmpty()) {
+            int count = 0;
+            sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.FirewallRule.toString());
+            for (String key : tags.keySet()) {
+                sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
+                sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
+                count++;
+            }
+        }
 
         if (ipId != null) {
             sc.setParameters("ip", ipId);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7acf8585/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index 29d6f39..cefde38 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -86,6 +86,9 @@ import com.cloud.network.rules.RulesManager;
 import com.cloud.network.rules.StickinessPolicy;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.projects.Project.ListProjectResourcesCriteria;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.ResourceTagVO;
+import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.DomainService;
@@ -162,6 +165,8 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
     ExternalLoadBalancerUsageManager _externalLBUsageMgr;
     @Inject 
     NetworkServiceMapDao _ntwkSrvcDao;
+    @Inject
+    ResourceTagDao _resourceTagDao;
 
     private String getLBStickinessCapability(long networkid) {
         Map<Service, Map<Capability, String>> serviceCapabilitiesMap = _networkMgr.getNetworkCapabilities(networkid);
@@ -1205,6 +1210,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
         String name = cmd.getLoadBalancerRuleName();
         String keyword = cmd.getKeyword();
         Long instanceId = cmd.getVirtualMachineId();
+        Map<String, String> tags = cmd.getTags();
 
         Account caller = UserContext.current().getCaller();
         List<Long> permittedAccounts = new ArrayList<Long>();
@@ -1234,6 +1240,18 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
             ipSearch.and("zoneId", ipSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
             sb.join("ipSearch", ipSearch, sb.entity().getSourceIpAddressId(), ipSearch.entity().getId(), JoinBuilder.JoinType.INNER);
         }
+        
+        if (tags != null && !tags.isEmpty()) {
+            SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+            for (int count=0; count < tags.size(); count++) {
+                tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
+                tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
+                tagSearch.cp();
+            }
+            tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+            sb.groupBy(sb.entity().getId());
+            sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
+        }
 
         SearchCriteria<LoadBalancerVO> sc = sb.create();
         _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@@ -1264,6 +1282,17 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
         if (zoneId != null) {
             sc.setJoinParameters("ipSearch", "zoneId", zoneId);
         }
+        
+
+        if (tags != null && !tags.isEmpty()) {
+            int count = 0;
+            sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.LoadBalancer.toString());
+            for (String key : tags.keySet()) {
+                sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
+                sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
+                count++;
+            }
+        }
 
         return _lbDao.search(sc, searchFilter);
     }