diff --git a/amicleaner/cli.py b/amicleaner/cli.py index fa6c6bd..1d163ed 100755 --- a/amicleaner/cli.py +++ b/amicleaner/cli.py @@ -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 @@ -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( @@ -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): @@ -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: diff --git a/amicleaner/core.py b/amicleaner/core.py index ccc1604..d8aa3e1 100644 --- a/amicleaner/core.py +++ b/amicleaner/core.py @@ -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 diff --git a/amicleaner/utils.py b/amicleaner/utils.py index 978dfb9..28d6fd7 100644 --- a/amicleaner/utils.py +++ b/amicleaner/utils.py @@ -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: