Created
June 30, 2016 13:59
-
-
Save gin1314/1913565d9ba18dc26ae2003b8385632c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# @author: [email protected] | |
# this will generate json structure for .shuttle.json | |
import json | |
import sys, getopt | |
def parse_opt(argv): | |
cert_path = '' | |
environment = '' | |
name = '' | |
username = '' | |
try: | |
opts, args = getopt.getopt(argv,"e:c:n:u:",["env=","cert=","name=","username="]) | |
except getopt.GetoptError: | |
print "%s --env production --cert ~/cert.pem --name \"accessname\" --username ec2-user" % sys.argv[0] | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print "%s --env production --cert ~/cert.pem --name \"accessname\" --username ec2-user" % sys.argv[0] | |
sys.exit() | |
elif opt in ("-e", "--env"): | |
environment = arg | |
elif opt in ("-c", "--cert"): | |
cert_path = arg | |
elif opt in ("-n", "--name"): | |
name = arg | |
elif opt in ("-u", "--username"): | |
username = arg | |
return { "cert_path": cert_path, "environment" : environment, "name": name, "username": username } | |
opts = {} | |
if __name__ == '__main__': | |
opts = parse_opt(sys.argv[1:]) | |
fo = open("file.txt", "r+") | |
serv = [] | |
for i, ip in enumerate(fo.readlines()): | |
ip = ip.rstrip('\n') | |
serv.append( | |
{ | |
"%s %s" % (opts["name"], ip): [ | |
{ | |
"cmd": "ssh %s@%s -i %s" % (opts["username"], ip, opts['cert_path']), | |
"name": "%s %s" % (opts["name"], i) | |
} | |
] | |
}) | |
print json.dumps(serv,indent=2, separators=(',', ': ')) | |
fo.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment