diff options
-rw-r--r-- | boto/ec2/ec2object.py | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/boto/ec2/ec2object.py b/boto/ec2/ec2object.py index 9edf12ee..7cc7e424 100644 --- a/boto/ec2/ec2object.py +++ b/boto/ec2/ec2object.py @@ -65,7 +65,7 @@ class TaggedEC2Object(EC2Object): def add_tag(self, key, value='', dry_run=False): """ - Add a tag to this object. Tag's are stored by AWS and can be used + Add a tag to this object. Tags are stored by AWS and can be used to organize and filter resources. Adding a tag involves a round-trip to the EC2 service. @@ -117,12 +117,12 @@ class TaggedEC2Object(EC2Object): :type value: str :param value: An optional value that can be stored with the tag. - If a value is provided, it must match the value - currently stored in EC2. If not, the tag will not - be removed. If a value of None is provided, all - tags with the specified name will be deleted. - NOTE: There is an important distinction between - a value of '' and a value of None. + If a value is provided, it must match the value currently + stored in EC2. If not, the tag will not be removed. If + a value of None is provided, the tag will be + unconditionally deleted. + NOTE: There is an important distinction between a value + of '' and a value of None. """ if value is not None: tags = {key: value} @@ -135,3 +135,26 @@ class TaggedEC2Object(EC2Object): ) if key in self.tags: del self.tags[key] + + def remove_tags(self, tags, dry_run=False): + """ + Removes tags from this object. Removing tags involves a round-trip + to the EC2 service. + + :type tags: dict + :param tags: A dictionary of key-value pairs for the tags being removed. + For each key, the provided value must match the value + currently stored in EC2. If not, that particular tag will + not be removed. However, if a value of None is provided, + the tag will be unconditionally deleted. + NOTE: There is an important distinction between a value of + '' and a value of None. + """ + status = self.connection.delete_tags( + [self.id], + tags, + dry_run=dry_run + ) + for key, value in tags.iteritems(): + if key in self.tags: + del self.tags[key] |