Make network tags searchable
authorHrvoje Ribicic <riba@google.com>
Fri, 13 Dec 2013 12:47:27 +0000 (12:47 +0000)
committerHrvoje Ribicic <riba@google.com>
Mon, 16 Dec 2013 15:31:37 +0000 (16:31 +0100)
This patch adds the network tags to the tags searched by gnt-cluster
search-tags, and in the process cleans up the code slightly.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>

lib/cmdlib/tags.py

index 726e3a1..9f85f40 100644 (file)
@@ -127,18 +127,24 @@ class LUTagsSearch(NoHooksLU):
       raise errors.OpPrereqError("Invalid search pattern '%s': %s" %
                                  (self.op.pattern, err), errors.ECODE_INVAL)
 
+  @staticmethod
+  def _ExtendTagTargets(targets, object_type_name, object_info_dict):
+    return targets.extend(("/%s/%s" % (object_type_name, o.name), o)
+                          for o in object_info_dict.values())
+
   def Exec(self, feedback_fn):
     """Returns the tag list.
 
     """
     cfg = self.cfg
     tgts = [("/cluster", cfg.GetClusterInfo())]
-    ilist = cfg.GetAllInstancesInfo().values()
-    tgts.extend([("/instances/%s" % i.name, i) for i in ilist])
-    nlist = cfg.GetAllNodesInfo().values()
-    tgts.extend([("/nodes/%s" % n.name, n) for n in nlist])
-    tgts.extend(("/nodegroup/%s" % n.name, n)
-                for n in cfg.GetAllNodeGroupsInfo().values())
+
+    LUTagsSearch._ExtendTagTargets(tgts, "instances", cfg.GetAllInstancesInfo())
+    LUTagsSearch._ExtendTagTargets(tgts, "nodes", cfg.GetAllNodesInfo())
+    LUTagsSearch._ExtendTagTargets(tgts, "nodegroup",
+                                   cfg.GetAllNodeGroupsInfo())
+    LUTagsSearch._ExtendTagTargets(tgts, "network", cfg.GetAllNetworksInfo())
+
     results = []
     for path, target in tgts:
       for tag in target.GetTags():