From f27302fafc3e4d65f7dd44f551ded242629d9ade Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 8 Oct 2007 15:10:52 +0000 Subject: [PATCH] Change tags add/remove to process multiple tags This patch changes the tags opcodes to work with multiple tags at once instead of only one. As such, the opcodes and some parameters are renamed. Reviewed-by: imsnah --- lib/cmdlib.py | 32 +++++++++++++++++++++----------- lib/mcpu.py | 4 ++-- lib/opcodes.py | 12 ++++++------ 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index d692a3d..cf84943 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -3730,11 +3730,11 @@ class LUGetTags(TagsLU): return self.target.GetTags() -class LUAddTag(TagsLU): +class LUAddTags(TagsLU): """Sets a tag on a given object. """ - _OP_REQP = ["kind", "name", "tag"] + _OP_REQP = ["kind", "name", "tags"] def CheckPrereq(self): """Check prerequisites. @@ -3743,14 +3743,16 @@ class LUAddTag(TagsLU): """ TagsLU.CheckPrereq(self) - objects.TaggableObject.ValidateTag(self.op.tag) + for tag in self.op.tags: + objects.TaggableObject.ValidateTag(tag) def Exec(self, feedback_fn): """Sets the tag. """ try: - self.target.AddTag(self.op.tag) + for tag in self.op.tags: + self.target.AddTag(tag) except errors.TagError, err: raise errors.OpExecError("Error while setting tag: %s" % str(err)) try: @@ -3761,11 +3763,11 @@ class LUAddTag(TagsLU): " aborted. Please retry.") -class LUDelTag(TagsLU): - """Delete a tag from a given object. +class LUDelTags(TagsLU): + """Delete a list of tags from a given object. """ - _OP_REQP = ["kind", "name", "tag"] + _OP_REQP = ["kind", "name", "tags"] def CheckPrereq(self): """Check prerequisites. @@ -3774,15 +3776,23 @@ class LUDelTag(TagsLU): """ TagsLU.CheckPrereq(self) - objects.TaggableObject.ValidateTag(self.op.tag) - if self.op.tag not in self.target.GetTags(): - raise errors.OpPrereqError("Tag not found") + for tag in self.op.tags: + objects.TaggableObject.ValidateTag(tag) + del_tags = frozenset(self.op.tags) + cur_tags = self.target.GetTags() + if not del_tags <= cur_tags: + diff_tags = del_tags - cur_tags + diff_names = ["'%s'" % tag for tag in diff_tags] + diff_names.sort() + raise errors.OpPrereqError("Tag(s) %s not found" % + (",".join(diff_names))) def Exec(self, feedback_fn): """Remove the tag from the object. """ - self.target.RemoveTag(self.op.tag) + for tag in self.op.tags: + self.target.RemoveTag(tag) try: self.cfg.Update(self.target) except errors.ConfigurationError: diff --git a/lib/mcpu.py b/lib/mcpu.py index 2714588..1f46dbb 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -79,8 +79,8 @@ class Processor(object): opcodes.OpExportInstance: cmdlib.LUExportInstance, # tags lu opcodes.OpGetTags: cmdlib.LUGetTags, - opcodes.OpSetTag: cmdlib.LUAddTag, - opcodes.OpDelTag: cmdlib.LUDelTag, + opcodes.OpAddTags: cmdlib.LUAddTags, + opcodes.OpDelTags: cmdlib.LUDelTags, } diff --git a/lib/opcodes.py b/lib/opcodes.py index 94a68fa..3544ed6 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -256,13 +256,13 @@ class OpGetTags(OpCode): __slots__ = ["kind", "name"] -class OpSetTag(OpCode): - """Sets the value of a tag on a given object.""" +class OpAddTags(OpCode): + """Add a list of tags on a given object.""" OP_ID = "OP_TAGS_SET" - __slots__ = ["kind", "name", "tag"] + __slots__ = ["kind", "name", "tags"] -class OpDelTag(OpCode): - """Remove a tag from a given object.""" +class OpDelTags(OpCode): + """Remove a list of tags from a given object.""" OP_ID = "OP_TAGS_DEL" - __slots__ = ["kind", "name", "tag"] + __slots__ = ["kind", "name", "tags"] -- 1.7.10.4