-
Notifications
You must be signed in to change notification settings - Fork 0
/
new 2.py
49 lines (38 loc) · 1.65 KB
/
new 2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#snapshot.py
! /usr/bin/python
from boto import ec2;
import boto.utils
import argparse
def parsed_args():
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--instance_id",
help="the instance id you want to snapshot. default: current instance id",
default=boto.utils.get_instance_metadata()['instance-id'])
parser.add_argument('-m', "--mount_point",
help="the mount moint you're searching for. default: /dev/sdf",
default='/dev/sdf')
parser.add_argument('-r', "--region",
help="the region you're in. default: us-west-2",
default='us-west-2')
parser.add_argument('-t', "--tag",
help="the tag you'd like to apply to the snapshot. default: codepen-app",
default='codepen-app')
return parser.parse_args()
def main():
args = parsed_args()
conn = ec2.connect_to_region(args.region)
vols = conn.get_all_volumes(filters={'attachment.instance-id': args.instance_id})
matches = [x for x in vols if x.attach_data.device == args.mount_point]
if (len(matches) == 1):
code_volume = matches[0]
else:
raise Exception('No attached volume could be found for %s' % mount_point)
print "found. the plan is to snapshot %s with tag %s" % (args.mount_point, args.tag)
snap = code_volume.create_snapshot(snapshot_description(code_volume, args.instance_id))
snap.add_tag('Name', args.tag)
print "done."
def snapshot_description(volume, instance_id):
return "deployment snapshot of volume %s on instance %s" % (volume.id, instance_id)
if __name__ == '__main__':
main()
Sign up for free