Ejemplo n.º 1
0
	def wait_for_instance(self, instance_id, state):
		"""
		wait for EC2 instance to reach a state
		"""
		msg( "... waiting EC2 instance " + instance_id + " to be in " + state + " state ..." )
		reached = False
		instance = None
		while not reached:
			insts = self.connection.get_all_instances([instance_id])
			for res in insts :
				instance = res.instances[0]
				debug_msg( "... current state: " + instance.state )
				if instance.state == state :
					reached = True
					break
			if not reached:
				BaseDatetime.sleep(10)
		return instance
Ejemplo n.º 2
0
				key = self.connection.create_key_pair(ec2_key_pair)
				key.save(key_dir)
			else:
				raise
	
		reservation = self.connection.run_instances(ec2_ami,
							key_name=ec2_key_pair,
							instance_type=ec2_instancetype, 
							security_groups=[group])
			
		instance = reservation.instances[0]
		conn.create_tags([instance.id], {"Name":ec2_tag})

		while instance.state  == u'pending':
			msg( "Instance state: %s" % instance.state )
			BaseDatetime.sleep(10)
			instance.update()

		msg( "Instance.ID: %s: " % instance.id )
		msg( "Instance state: %s " % instance.state )
		msg( "Public DNS: %s" % instance.public_dns_name )

		return instance

	def start_instance(self, instance_id):
		"""
		start EC2 instance with given ID 
		"""
		msg( "... starting EC2 instance " + instance_id + " ..." )
		self.connection.start_instances(instance_ids=[instance_id])
		return self.wait_for_instance(instance_id, "running")
Ejemplo n.º 3
0
import os

import BaseDatetime
from BaseDatetime import sleep
from optparse import OptionParser
#
# The list of modules that are included by Python 2.7 library:
# http://docs.python.org/2/library/index.html
#
# e.g.
# re, os, datetime, urllib, socket

debug = False
dryrun = False
LOGGER_NAME = "~~((~~ bluestorm ~~))~~"
basedatetime = BaseDatetime.BaseDatetime()

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
    datefmt='%Y-%m-%dT%H:%M:%S')


#
# Basic System Releated Utilities
#
def parse_cmd_opts(usage, cmd_opts_map, args_min=0):
    parser = OptionParser(usage)
    for option in cmd_opts_map:
        parser.add_option(option[0],
                          option[1],