Skip to content

Commit

Permalink
added support for EBS snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbcullen committed Jun 6, 2017
1 parent 72a063d commit e267c5a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='aws-tagger',
version='0.4.0',
version='0.5.0',
packages=find_packages(),
include_package_data=True,
install_requires=[
Expand All @@ -28,7 +28,7 @@
author="Patrick Cullen and the WaPo platform tools team",
author_email="[email protected]",
url="https://github.com/washingtonpost/aws-tagger",
download_url = "https://github.com/washingtonpost/aws-tagger/tarball/v0.4.0",
download_url = "https://github.com/washingtonpost/aws-tagger/tarball/v0.5.0",
keywords = ['tag', 'tagger', 'tagging', 'aws'],
classifiers = []
)
32 changes: 24 additions & 8 deletions tagger/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,39 @@ def tag(self, resource_id, tags):
return

tagger = None
if resource_id.startswith('arn:'):
product, resource_id = self._parse_arn(resource_id)
if product:
tagger = self.taggers.get(product)
else:
tagger = self.taggers['s3']


if resource_id.startswith('i-'):
tagger = self.taggers['ec2']
elif resource_id.startswith('vol-'):
tagger = self.taggers['ec2']
elif resource_id.startswith('arn:'):
parts = resource_id.split(':')
if len(parts) > 4:
product = parts[2]
tagger = self.taggers.get(product)
else:
tagger = self.taggers['s3']
elif resource_id.startswith('snap-'):
tagger = self.taggers['ec2']

if tagger:
tagger.tag(resource_id, tags)
else:
print "Tagging is not support for this resource %s" % resource_id

def _parse_arn(self, resource_arn):
product = None
resource_id = None
parts = resource_arn.split(':')
if len(parts) > 5:
product = parts[2]
resource_id = parts[5]
resource_parts = resource_id.split('/')
if len(resource_parts) > 1:
resource_id = resource_parts[-1]

return product, resource_id

class MultipleResourceTagger(object):
def __init__(self, dryrun, verbose, role=None, region=None):
self.tagger = SingleResourceTagger(dryrun, verbose, role=role, region=region)
Expand Down Expand Up @@ -192,7 +208,7 @@ def tag(self, instance_id, tags):
try:
self._ec2_create_tags(Resources=resource_ids, Tags=aws_tags)
except botocore.exceptions.ClientError as exception:
if exception.response["Error"]["Code"] in ['InvalidVolume.NotFound', 'InvalidInstanceID.NotFound']:
if exception.response["Error"]["Code"] in ['InvalidSnapshot.NotFound', 'InvalidVolume.NotFound', 'InvalidInstanceID.NotFound']:
print "Resource not found: %s" % instance_id
else:
raise exception
Expand Down

0 comments on commit e267c5a

Please sign in to comment.