Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Dahlgren committed May 19, 2014
2 parents 1076056 + 9b3b89f commit 2c04563
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 26 deletions.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ You can also restart it using

automated-ebs-snapshots --config ~/automated-ebs-snapshots.conf --deamon restart

Release notes
-------------

0.3.0
^^^^^

- Print volume Name tag in --list (`#3 <https://github.com/skymill/automated-ebs-snapshots/issues/3>`__)
- Support authentication using instance profiles (`#5 <https://github.com/skymill/automated-ebs-snapshots/issues/5>`__)
- Only write logs to file if --log-file is specified (`#2 <https://github.com/skymill/automated-ebs-snapshots/issues/2>`__)

Author
------

Expand Down
37 changes: 22 additions & 15 deletions automated_ebs_snapshots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from automated_ebs_snapshots import volume_manager
from automated_ebs_snapshots.daemon import Daemon

logging.config.dictConfig({
LOG_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
Expand All @@ -25,44 +25,51 @@
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'standard'
},
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.TimedRotatingFileHandler',
'formatter': 'standard',
'filename': args.log_file,
'when': 'midnight',
'backupCount': 5
}
},
'loggers': {
'': {
'handlers': ['default', 'file'],
'handlers': ['default'],
'level': 'INFO',
'propagate': True
},
'lib.bundle_manager': {
'handlers': ['default', 'file'],
'handlers': ['default'],
'level': 'DEBUG',
'propagate': False
},
'lib.config_handler': {
'handlers': ['default', 'file'],
'handlers': ['default'],
'level': 'DEBUG',
'propagate': False
},
'lib.connection_handler': {
'handlers': ['default', 'file'],
'handlers': ['default'],
'level': 'DEBUG',
'propagate': False
},
'lib.deployment_manager': {
'handlers': ['default', 'file'],
'handlers': ['default'],
'level': 'DEBUG',
'propagate': False
}
}
})
}

if args.log_file:
LOG_CONFIG['handlers']['file'] = {
'level': 'DEBUG',
'class': 'logging.handlers.TimedRotatingFileHandler',
'formatter': 'standard',
'filename': args.log_file,
'when': 'midnight',
'backupCount': 5
}

for logger in LOG_CONFIG['loggers'].keys():
LOG_CONFIG['loggers'][logger]['handlers'].append('file')

logging.config.dictConfig(LOG_CONFIG)
logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions automated_ebs_snapshots/command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
help='Print the Automated EBS Snapshots version and exit')
general_ag.add_argument(
'--log-file',
default='/var/log/automated-ebs-snapshots.log',
help='Path to the log file. Default: /var/log/automated-ebs-snapshots.log')
help='Path to file to send logs to')
general_ag.add_argument(
'--daemon',
help=(
Expand Down
16 changes: 16 additions & 0 deletions automated_ebs_snapshots/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys

from boto import ec2
from boto.utils import get_instance_metadata

logger = logging.getLogger(__name__)

Expand All @@ -19,12 +20,27 @@ def connect_to_ec2(region='us-east-1', access_key=None, secret_key=None):
:returns: boto.ec2.connection.EC2Connection -- EC2 connection
"""
logger.info('Connecting to AWS EC2 in {}'.format(region))

# Fetch instance metadata
metadata = get_instance_metadata(timeout=1, num_retries=1)
if metadata:
try:
profile_name = metadata['iam']['info'][u'InstanceProfileArn']
region = metadata['placement']['availability-zone'][:-1]
except KeyError:
profile_name = None

if access_key:
# Connect using supplied credentials
connection = ec2.connect_to_region(
region,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key)
elif metadata:
# Connect using instance profile
connection = ec2.connect_to_region(region, profile_name=profile_name)
else:
# Connect using env vars or boto credentials
connection = ec2.connect_to_region(region)

if not connection:
Expand Down
2 changes: 1 addition & 1 deletion automated_ebs_snapshots/settings.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[general]
version: 0.2.1
version: 0.3.0
44 changes: 36 additions & 8 deletions automated_ebs_snapshots/volume_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
""" Handle EBS volumes """
import logging

Expand Down Expand Up @@ -30,12 +31,25 @@ def list(connection):
logger.info('No watched volumes found')
return

logger.info('---------------+--------------+-------------')
logger.info('{volume:<14} | {interval:<12} | {retention:<10}'.format(
volume='Volume ID',
interval='Interval',
retention='Retention'))
logger.info('---------------+--------------+-------------')
logger.info(
'+----------------'
'+----------------------'
'+--------------'
'+------------+')
logger.info(
'| {volume:<14} '
'| {volume_name:<20.20} '
'| {interval:<12} '
'| {retention:<10} |'.format(
volume='Volume ID',
volume_name='Volume name',
interval='Interval',
retention='Retention'))
logger.info(
'+----------------'
'+----------------------'
'+--------------'
'+------------+')

for volume in volumes:
if 'AutomatedEBSSnapshots' not in volume.tags:
Expand All @@ -50,13 +64,27 @@ def list(connection):
else:
retention = volume.tags['AutomatedEBSSnapshotsRetention']

# Get the volume name
try:
volume_name = volume.tags['Name']
except KeyError:
volume_name = ''

logger.info(
'{volume_id:<14} | {interval:<12} | {retention:<10}'.format(
'| {volume_id:<14} '
'| {volume_name:<20.20} '
'| {interval:<12} '
'| {retention:<10} |'.format(
volume_id=volume.id,
volume_name=volume_name,
interval=interval,
retention=retention))

logger.info('---------------+--------------+-------------')
logger.info(
'+----------------'
'+----------------------'
'+--------------'
'+------------+')


def unwatch(connection, volume_id):
Expand Down

0 comments on commit 2c04563

Please sign in to comment.