Skip to content

Commit

Permalink
Merge pull request #24 from bonclay7/snapshots_message
Browse files Browse the repository at this point in the history
orphan ebs snapshots recap message
  • Loading branch information
bonclay7 authored Aug 19, 2016
2 parents b8e013b + 8bb7fc5 commit 4dbe22f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions amicleaner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, args):
self.mapping_key = args.mapping_key or MAPPING_KEY
self.mapping_values = args.mapping_values or MAPPING_VALUES
self.keep_previous = args.keep_previous
self.skip_orphans = args.skip_orphans
self.check_orphans = args.check_orphans
self.from_ids = args.from_ids
self.full_report = args.full_report
self.force_delete = args.force_delete
Expand Down Expand Up @@ -81,6 +81,9 @@ def clean_orphans(self):
cleaner = OrphanSnapshotCleaner()
snaps = cleaner.fetch()

if not snaps:
return

Printer.print_orphan_snapshots(snaps)

answer = raw_input(
Expand All @@ -90,8 +93,8 @@ def clean_orphans(self):

if confirm:
print "Removing orphan snapshots... "
cleaner.clean(snaps[])
print "snapshots removed !"
count = cleaner.clean(snaps)
print "\n{0} orphan snapshots successfully removed !".format(count)

def print_defaults(self):

Expand All @@ -102,7 +105,7 @@ def print_defaults(self):

def run_cli(self):

if not self.skip_orphans:
if self.check_orphans:
self.clean_orphans()

if self.from_ids:
Expand Down
6 changes: 5 additions & 1 deletion amicleaner/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ def clean(self, snapshots):
actually deletes the snapshots with an array
of snapshots ids
"""
count = len(snapshots)

snapshots = snapshots or []

for snap in snapshots[0:2]:
for snap in snapshots:
try:
self.ec2.delete_snapshot(SnapshotId=snap)
except ClientError as e:
self.log("{0} deletion failed : {1}".format(snap, e))
count -= 1

return count

def log(self, msg):
print msg
Expand Down
6 changes: 3 additions & 3 deletions amicleaner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def parse_args(args):
action="store_true",
help="Skip confirmation")

parser.add_argument("--skip-orphans",
dest='skip_orphans',
parser.add_argument("--check-orphans",
dest='check_orphans',
action="store_true",
help="Skip orphaned snapshots cleaning")
help="Check and clean orphaned snapshots")

parsed_args = parser.parse_args(args)
if parsed_args.mapping_key and not parsed_args.mapping_values:
Expand Down

0 comments on commit 4dbe22f

Please sign in to comment.