Skip to content

Commit

Permalink
snapshots can now be created with a list of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
janschumann committed Dec 13, 2018
1 parent 2b3d64d commit 84c9ffa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
20 changes: 15 additions & 5 deletions AutoscalingLifecycle/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import botocore.waiter as waiter
from boltons.tbutils import ExceptionInfo
from boto3 import Session
import boto3
from botocore.client import BaseClient as BotoClient
from botocore.exceptions import WaiterError, ClientError

Expand All @@ -17,11 +17,11 @@ class ClientFactory(object):
"""


def __init__(self, session: Session, logger: Logger):
def __init__(self, session: boto3.Session, logger: Logger):
"""
:param session: A boto3 Session instamce
:type session: Session
:param session: A boto3 boto3.Session instamce
:type session: boto3.Session
:param logger: A LifecycleLogger instance
:type logger: LifecycleLogger
"""
Expand Down Expand Up @@ -340,6 +340,12 @@ def __init__(self, client: BotoClient, waiters: CustomWaiters, logging: Logging,


class Ec2Client(BaseClient):

def __init__(self, client: BotoClient, waiters: CustomWaiters, logging: Logging, *args):
super().__init__(client, waiters, logging)
self.resource = boto3.resource('ec2')


def find_instances_by_name(self, name) -> list:
response = self.client.describe_instances(
Filters=[
Expand Down Expand Up @@ -386,7 +392,7 @@ def get_instance(self, instance_id) -> dict:
return dict()


def create_snapshot(self, description, volume_id):
def create_snapshot(self, description, volume_id, tags: list):
response = self.client.create_snapshot(
Description=description,
VolumeId=volume_id,
Expand All @@ -396,6 +402,10 @@ def create_snapshot(self, description, volume_id):
SnapshotIds=[response.get('SnapshotId')],
)

if len(tags) > 0:
snapshot = self.resource.Snapshot(response.get('SnapshotId'))
snapshot.create_tags(Tags=tags)


class AutoscalingClient(BaseClient):

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.0

NEW FEATURES:

* Snapshots can now be created with a list of tags

## 0.61.0

IMPROVEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name = "AutoscalingLifecycle",
version = "0.61.0",
version = "1.0.0",
author = "Jan Schumann",
author_email = "[email protected]",
description = "A library to handle aws autoscaling lifecycle events",
Expand Down

0 comments on commit 84c9ffa

Please sign in to comment.