This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
executable file
·60 lines (43 loc) · 1.56 KB
/
cli.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
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
from controllers import *
from config import CALL_MAP
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
def get_parser():
parse = ArgumentParser(description=__doc__, formatter_class=ArgumentDefaultsHelpFormatter)
parse.add_argument("-t", "--tag",
dest="tag",
required=True,
help="Tag/name used for infrastructure orchestration.")
parse.add_argument("-a", "--action",
dest="action",
required=True,
help="Action to execute on the infrastructure.")
return parse
def main(tag, action):
start_time = time.time()
cloud = Cloud(tag)
if cloud:
print('Cloud control class instantiated.')
else:
print('Critical error, try again.')
instance = 'cloud'
if action in CALL_MAP:
expression = '{0}.{1}()'.format(instance, action)
result = eval(expression)
print(result)
end_time = time.time()
print('Time elapsed: {0}s'.format(end_time - start_time))
if __name__ == '__main__':
parser = get_parser()
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
if args.action not in CALL_MAP:
print('"{0}" either does not exist or you do not have the permission to execute it.'.format(args.action))
print('You can execute the following methods: {0}'.format(CALL_MAP))
sys.exit(1)
main(args.tag, args.action)