forked from discobean/ebs-pin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathebs-pin
More file actions
executable file
·46 lines (35 loc) · 1.77 KB
/
ebs-pin
File metadata and controls
executable file
·46 lines (35 loc) · 1.77 KB
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
#!/usr/bin/env python2.7
from ebspin import base, configuration
import argparse, logging, sys
logging.basicConfig(level=logging.INFO)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
attach = argparse.ArgumentParser(add_help=False)
attach.add_argument('-u', '--uuid', required=True, help='The UUID tag')
attach.add_argument('-d', '--device', default='/dev/xvdf', help='The device to use, default=/dev/xvdf')
attach.add_argument('-s', '--size', default=10, type=int, help='The volume size in GB, default=10')
attach.add_argument('-t', '--type', default='gp2', help='The volume type, standard, gp2 etc, default=gp2')
attach.add_argument('-a', '--tags', nargs='+', default=None, help='List of AWS tags to add, e.g. Key1=Value1 Key2=Value2')
snapshot = argparse.ArgumentParser(add_help=False)
snapshot.add_argument('-u', '--uuid', required=True, help='The UUID tag')
snapshot.add_argument('-a', '--tags', nargs='+', default=None, help='List of additional AWS tags to add, e.g. Key1=Value1 Key2=Value2')
sp = parser.add_subparsers()
sp_attach = sp.add_parser('attach', help='Attach or create new volume', parents=[attach])
sp_attach.set_defaults(which='attach')
sp_snapshot = sp.add_parser('snapshot', help='Snapshot existing volume', parents=[snapshot])
sp_snapshot.set_defaults(which='snapshot')
args = parser.parse_args()
# convert tags Key=Value to dictionary
tags = {}
if args.tags:
for tag in args.tags:
key, value = tag.split('=')
tags[key] = value
args.tags = tags
c = configuration.Configuration()
metadata = c.metadata()
b = base.Base(args, metadata)
if args.which == 'attach':
b.attach()
if args.which == 'snapshot':
b.snapshot()