This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added delete-snapshots/deregister-images scripts.
[Issue(s) #7]
- Loading branch information
Showing
3 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) 2012 Steffen Opel http://opelbrothers.net/ | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the | ||
# "Software"), to deal in the Software without restriction, including | ||
# without limitation the rights to use, copy, modify, merge, publish, dis- | ||
# tribute, sublicense, and/or sell copies of the Software, and to permit | ||
# persons to whom the Software is furnished to do so, subject to the fol- | ||
# lowing conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | ||
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
|
||
from pprint import pprint | ||
import argparse | ||
import boto | ||
import boto.ec2 | ||
import botocross as bc | ||
import logging | ||
|
||
# configure command line argument parsing | ||
parser = argparse.ArgumentParser(description='Delete EBS snapshots in all/some available EC2 regions', | ||
parents=[bc.build_region_parser(), bc.build_common_parser()]) | ||
parser.add_argument("-f", "--filter", action="append", help="An EBS snapshot filter. [can be used multiple times]") | ||
parser.add_argument("-i", "--id", dest="resource_ids", action="append", help="An EBS snapshot id. [can be used multiple times]") | ||
args = parser.parse_args() | ||
|
||
# process common command line arguments | ||
log = logging.getLogger('botocross') | ||
bc.configure_logging(log, args.log_level) | ||
credentials = bc.parse_credentials(args) | ||
regions = bc.filter_regions(boto.ec2.regions(), args.region) | ||
filters = bc.build_filter_params(args.filter) | ||
log.info(args.resource_ids) | ||
|
||
# execute business logic | ||
log.info("Deleting EBS snapshots:") | ||
|
||
for region in regions: | ||
try: | ||
ec2 = boto.connect_ec2(region=region, **credentials) | ||
resources = ec2.get_all_snapshots(snapshot_ids=args.resource_ids, owner='self', filters=filters) | ||
print region.name + ": " + str(len(resources)) + " EBS snapshots" | ||
for resource in resources: | ||
if args.verbose: | ||
print resource.id | ||
else: | ||
ec2.delete_snapshot(resource.id) | ||
except boto.exception.BotoServerError, e: | ||
log.error(e.error_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) 2012 Steffen Opel http://opelbrothers.net/ | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the | ||
# "Software"), to deal in the Software without restriction, including | ||
# without limitation the rights to use, copy, modify, merge, publish, dis- | ||
# tribute, sublicense, and/or sell copies of the Software, and to permit | ||
# persons to whom the Software is furnished to do so, subject to the fol- | ||
# lowing conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | ||
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
|
||
from pprint import pprint | ||
import argparse | ||
import boto | ||
import boto.ec2 | ||
import botocross as bc | ||
import logging | ||
|
||
# configure command line argument parsing | ||
parser = argparse.ArgumentParser(description='Deregister EC2 images in all/some available EC2 regions', | ||
parents=[bc.build_region_parser(), bc.build_common_parser()]) | ||
parser.add_argument("-f", "--filter", action="append", help="An EC2 image filter. [can be used multiple times]") | ||
parser.add_argument("-i", "--id", dest="resource_ids", action="append", help="An EC2 image id. [can be used multiple times]") | ||
args = parser.parse_args() | ||
|
||
# process common command line arguments | ||
log = logging.getLogger('botocross') | ||
bc.configure_logging(log, args.log_level) | ||
credentials = bc.parse_credentials(args) | ||
regions = bc.filter_regions(boto.ec2.regions(), args.region) | ||
filters = bc.build_filter_params(args.filter) | ||
log.info(args.resource_ids) | ||
|
||
# execute business logic | ||
log.info("Deregistering EC2 images") | ||
|
||
for region in regions: | ||
try: | ||
ec2 = boto.connect_ec2(region=region, **credentials) | ||
resources = ec2.get_all_images(image_ids=args.resource_ids, owners=['self'], filters=filters) | ||
print region.name + ": " + str(len(resources)) + " EC2 images" | ||
for resource in resources: | ||
if args.verbose: | ||
print resource.id | ||
else: | ||
ec2.deregister_image(resource.id, delete_snapshot=True) | ||
except boto.exception.BotoServerError, e: | ||
log.error(e.error_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters