def scale_up_with_new_instance(config): """Scale up with a new instance that first gets configured""" logger = logging.getLogger(__name__) logger.info("Upscaling with the new instance started.") # Launch instance logger.info("Launching an instance.") instance, _ = aws_ec2.launch_instance() # Start app logger.info("Performing deployment operations.") aws_ec2.app_predeployment(config) aws_ec2.deploy_app_at_instance(config, instance) aws_ec2.app_postdeployment(config) # Register instance at load balancer logger.info("Registering an instance at the load balancer") elb = aws_ec2_elb.get_load_balancer(config.get("region"), config.get("elb_name")) elb.register_instances([instance.id]) # Update config instances = config.get_list("instances") instances.append(instance.id) config.set_list("instances", instances)
def deploy_app_at_environment(config): """Deploy an app to the environment""" logger = logging.getLogger(__name__) aws_ec2.app_predeployment(config) #Transfer the archives to the instances instances = aws_ec2.get_running_instances(config) threads = list() for instance in instances: threads.append(threading.Thread(target=aws_ec2.deploy_app_at_instance, args=(config,instance))) [t.start() for t in threads] [t.join() for t in threads] aws_ec2.app_postdeployment(config) output = 'Deployment completed for %d instance(s). App may still be inaccessible for a couple of minutes' % len(instances) logger.info(output) print output