-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomanager.py
51 lines (36 loc) · 1.29 KB
/
domanager.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
50
51
#!/usr/bin/env python
import argparse
import sys
from configuration import Configuration
from create import create
from destroy import destroy
def do_create(args):
"""Create a droplet based on configuration"""
config = Configuration()
if not config.read_config(args.config_file):
return False
create(config)
return True
def do_destroy(args):
"""Destroy a droplet based on configuration"""
config = Configuration()
if not config.read_config(args.config_file):
return False
destroy(config)
return True
def main(args):
"""Parse arguments and call create/destroy function"""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(title='subcommands')
parser_create = subparsers.add_parser('create', help='Create a droplet')
parser_create.set_defaults(func=do_create)
parser_create.add_argument('config_file',
help='Configuration file to use')
parser_destroy = subparsers.add_parser('destroy', help='Destroy a droplet')
parser_destroy.set_defaults(func=do_destroy)
parser_destroy.add_argument('config_file',
help='Configuration file to use')
args = parser.parse_args()
args.func(args)
if __name__ == '__main__':
main(sys.argv)