-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaws.py
More file actions
46 lines (42 loc) · 1.37 KB
/
Copy pathaws.py
File metadata and controls
46 lines (42 loc) · 1.37 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
"""Usage: aws [options]
aws [options] list
aws [options] start <instance-id>
aws [options] stop <instance-id>
aws [options] stop
aws [options] instanceid
aws (-h | --help)
aws --version
Options:
-d Enable debug
-h --help Show this help
--version Show version
"""
import logging
from lib.conf import Configuration
from docopt import docopt
from lib.cloud import AWS
if __name__ == '__main__':
arguments = docopt(__doc__, version='AWS Manager 1.0')
config = Configuration(__file__, 'config.yaml')
if arguments['-d']:
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.ERROR)
logging.info(arguments)
aws = AWS(config.aws_apikey, config.aws_apisecret)
if arguments['list'] == True:
aws.listInstances()
elif arguments['instanceid'] == True:
instanceId = aws.getSelfInstanceId()
if instanceId == None:
print('This is not an AWS instance')
else:
print(instanceId)
elif arguments['start'] == True:
aws.startInstance(arguments['<instance-id>'])
elif arguments['stop'] == True:
status = aws.stopInstance(arguments['<instance-id>'])
if status == False:
print('Instance could not be stopped')
else:
print('Instance successfully stopped')