Revision 73415719 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
4141 | 4141 |
return self.target.GetTags() |
4142 | 4142 |
|
4143 | 4143 |
|
4144 |
class LUSearchTags(NoHooksLU): |
|
4145 |
"""Searches the tags for a given pattern. |
|
4146 |
|
|
4147 |
""" |
|
4148 |
_OP_REQP = ["pattern"] |
|
4149 |
|
|
4150 |
def CheckPrereq(self): |
|
4151 |
"""Check prerequisites. |
|
4152 |
|
|
4153 |
This checks the pattern passed for validity by compiling it. |
|
4154 |
|
|
4155 |
""" |
|
4156 |
try: |
|
4157 |
self.re = re.compile(self.op.pattern) |
|
4158 |
except re.error, err: |
|
4159 |
raise errors.OpPrereqError("Invalid search pattern '%s': %s" % |
|
4160 |
(self.op.pattern, err)) |
|
4161 |
|
|
4162 |
def Exec(self, feedback_fn): |
|
4163 |
"""Returns the tag list. |
|
4164 |
|
|
4165 |
""" |
|
4166 |
cfg = self.cfg |
|
4167 |
tgts = [("/cluster", cfg.GetClusterInfo())] |
|
4168 |
ilist = [cfg.GetInstanceInfo(name) for name in cfg.GetInstanceList()] |
|
4169 |
tgts.extend([("/instances/%s" % i.name, i) for i in ilist]) |
|
4170 |
nlist = [cfg.GetNodeInfo(name) for name in cfg.GetNodeList()] |
|
4171 |
tgts.extend([("/nodes/%s" % n.name, n) for n in nlist]) |
|
4172 |
results = [] |
|
4173 |
for path, target in tgts: |
|
4174 |
for tag in target.GetTags(): |
|
4175 |
if self.re.search(tag): |
|
4176 |
results.append((path, tag)) |
|
4177 |
return results |
|
4178 |
|
|
4179 |
|
|
4144 | 4180 |
class LUAddTags(TagsLU): |
4145 | 4181 |
"""Sets a tag on a given object. |
4146 | 4182 |
|
Also available in: Unified diff