From 74b37400324ad31039f38618d05b9fdaf05815d4 Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sat, 13 Sep 2014 12:23:08 -0700 Subject: Removed duplicate code in add_tag and remove_tag Since add_tags is a more general version of add_tag that uses the same API call, add_tag can simply call add_tags with the correct parameters. Likewise for remove_tag and remove_tags. For remove_tag in particular, these lines were redundant: if value is not None: tags = {key : value} else: tags = [key] Since EC2Connection.delete_tags just converts the list back to a dict of {key: None} anyway, these extra checks serve no purpose. --- boto/ec2/ec2object.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/boto/ec2/ec2object.py b/boto/ec2/ec2object.py index 7cc7e424..8bc428db 100644 --- a/boto/ec2/ec2object.py +++ b/boto/ec2/ec2object.py @@ -77,14 +77,7 @@ class TaggedEC2Object(EC2Object): If you want only the tag name and no value, the value should be the empty string. """ - status = self.connection.create_tags( - [self.id], - {key: value}, - dry_run=dry_run - ) - if self.tags is None: - self.tags = TagSet() - self.tags[key] = value + self.add_tags({key: value}, dry_run) def add_tags(self, tags, dry_run=False): """ @@ -124,17 +117,7 @@ class TaggedEC2Object(EC2Object): NOTE: There is an important distinction between a value of '' and a value of None. """ - if value is not None: - tags = {key: value} - else: - tags = [key] - status = self.connection.delete_tags( - [self.id], - tags, - dry_run=dry_run - ) - if key in self.tags: - del self.tags[key] + self.remove_tags({key: value}, dry_run) def remove_tags(self, tags, dry_run=False): """ -- cgit v1.2.1