Last active
December 31, 2015 14:39
-
-
Save shantanuo/8001509 to your computer and use it in GitHub Desktop.
1 for ubuntu with freeswitch & interspire or 2 for tokudb on redhat # python instance.py 1 # python instance.py --help
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/python | |
| access_key='ABC' | |
| secret_key='PQR+XYZ' | |
| my_instance_type='t1.micro' | |
| # following instance types are available | |
| # t1.micro m1.small m1.medium m1.large m1.xlarge m3.xlarge m3.2xlarge m2.xlarge m2.2xlarge m2.4xlarge c1.medium c1.xlarge hi1.4xlarge hs1.8xlarge | |
| my_security_groups='N-1-0-1-AutogenByAWSMP-' | |
| import boto.ec2 | |
| conn = boto.ec2.connect_to_region('us-east-1', aws_access_key_id=access_key, aws_secret_access_key=secret_key) | |
| def start_instance(): | |
| myreservation = conn.run_instances(amiid, placement='us-east-1a', key_name='nov15a',instance_type=my_instance_type,security_groups=[my_security_groups]) | |
| myinstanceid = conn.get_all_instances(filters={'reservation-id':myreservation.id})[0].instances[0] | |
| print "import boto.ec2" | |
| print ("conn = boto.ec2.connect_to_region('us-east-1', aws_access_key_id='%s', aws_secret_access_key='%s')" % (access_key, secret_key)) | |
| print ("conn.terminate_instances(['%s'])" % (myinstanceid.id)) | |
| print myreservation | |
| import time | |
| time.sleep(150) | |
| mydns = conn.get_all_instances(filters={'reservation-id':myreservation.id})[0].instances[0].public_dns_name | |
| myip = mydns.split('.', 1)[0] | |
| print ("ssh -i nov15a.pem %s@%s" % (user, mydns)) | |
| print ("sed -i 's/ec2-54-211-117-11/%s/' /var/www/interspire/email/admin/includes/config.php" % (myip)) | |
| print ("/usr/local/freeswitch/bin/freeswitch") | |
| print ("/usr/local/kannel/sbin/smsbox /usr/local/kannel/smskannel.conf") | |
| mykey="""-----BEGIN RSA PRIVATE KEY----- | |
| 0TbMa9ukv5LXDHS9ZcyNyYpmVFa7HFYVh4CxSTK+e00SKaGBMle1VlkxW3jJBNEob0Mq7H4PWxOS | |
| qJENdo5NUayOcKxSfzhxR5CCdkzspPT7j3LFvFj4u8pFPrwiVwDVxdKx18FSsrCqNspovLg= | |
| -----END RSA PRIVATE KEY----- | |
| """ | |
| with open("nov15a.pem", "w") as w: | |
| w.write(mykey) | |
| import argparse | |
| parser = argparse.ArgumentParser(description="Select the image. Change the source code to change instance type from t1.micro") | |
| parser.add_argument("action", choices=["1", "2"], help='1 for ubuntu with freeswitch & interspire or 2 for tokudb on redhat') | |
| args = parser.parse_args() | |
| print args | |
| if args.action == "1": | |
| amiid='ami-ad96b2c4' | |
| user='ubuntu' | |
| start_instance() | |
| if args.action == "2": | |
| amiid='ami-c5471fac' | |
| user='ec2-user' | |
| start_instance() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment