Using Botto To Run and Manage Amazon AMI Instances
From Resin 3.0
(Difference between revisions)
(New page: Using boto to fire up three Resin AMI instances. ami-bb16ddd2 is an AMI which has Resin 4.24 on it. <code> <pre> from boto.ec2.connection import EC2Connection import time conn = EC2Conn...) |
|||
Line 26: | Line 26: | ||
print "Checking servers..." | print "Checking servers..." | ||
for instance in instances: | for instance in instances: | ||
+ | done=0 | ||
instance.update() | instance.update() | ||
print "Server status %s " % instance.state | print "Server status %s " % instance.state | ||
Line 38: | Line 39: | ||
</code> | </code> | ||
− | TODO read ~/.eucarc file for variables for AWS_ACCESS_KEY, AWS_SECRET_KEY | + | # TODO read ~/.eucarc file for variables for AWS_ACCESS_KEY, AWS_SECRET_KEY |
− | TODO Allow passing of ami-bb16ddd2 as command line. | + | # TODO Allow passing of ami-bb16ddd2 as command line. |
− | TODO read USER_DATA from file passed as command line arg | + | # TODO read USER_DATA from file passed as command line arg |
− | TODO pass number of servers as command line arg | + | # TODO pass number of servers as command line arg |
Latest revision as of 09:40, 3 December 2011
Using boto to fire up three Resin AMI instances.
ami-bb16ddd2 is an AMI which has Resin 4.24 on it.
from boto.ec2.connection import EC2Connection import time conn = EC2Connection('AWS_ACCESS_KEY', 'AWS_SECRET_KEY') resin_image = conn.get_all_images(image_ids=["ami-bb16ddd2"])[0] reservation = resin_image.run( min_count=3, max_count=3, user_data="blah blah blah", instance_type='t1.micro', key_name="resin2") instances = reservation.instances time.sleep(20) count = 0 done = 0 while True: count += 1 if count > 10: break print "Checking servers..." for instance in instances: done=0 instance.update() print "Server status %s " % instance.state if instance.state==u'running': done+=1 if done >= 3: break time.sleep(20) print ("All instances are running")
# TODO read ~/.eucarc file for variables for AWS_ACCESS_KEY, AWS_SECRET_KEY # TODO Allow passing of ami-bb16ddd2 as command line. # TODO read USER_DATA from file passed as command line arg # TODO pass number of servers as command line arg