Esempio n. 1
0
   def GET(self):
 
       user_data = web.input()
       env_id = user_data.env_id
       config = Config.Config (str(env_id))
                
       #get stopped instances
       stopped_instances = list()
       stopped_instances=config.get_list('stopped_instances')
          
           
       #get running instances
       instance_list = aws_ec2.get_running_instances(config)
       instance_id_list = list()
       for instance in instance_list:
               instance_id_list.append(instance.id)
       
      
       return render.instances(instance_id_list,str(env_id),stopped_instances)
Esempio n. 2
0
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
Esempio n. 3
0
def get_avg_cpu_utilization_percentage_for_environment(config):
    """Return average CPU utilization for the given environment within number of minutes specified in config"""
    logger = logging.getLogger(__name__)
    instances = aws_ec2.get_running_instances(config)
    cw = boto.ec2.cloudwatch.connect_to_region(config.get('region'))
    env_metric = EnvMetric()
    for instance in instances:
        list_metrics = cw.list_metrics(dimensions={'InstanceId': instance.id}, metric_name='CPUUtilization')
        #Newly added instances do not have recorded data, thus the query returns an empty list
        if len(list_metrics) > 0:
            inst_metric = InstanceMetric(instance,list_metrics[0])
            start,end = get_start_end_statistics_time(config)
            inst_metric.query = list_metrics[0].query(start, end, ['Average'])
            percent, num = inst_metric.average_percentage()
            rec = str(inst_metric.metric_records())
            logger.info('%s: CPU %.0f%% for %d min. %s' %(inst_metric.instance.id, percent, num,rec))
            env_metric.instance_metrics.append(inst_metric)
    now = str(time.time()).split('.')[0]
    now_human = str(datetime.datetime.now())
    percent, num = env_metric.get_average_percentage()
    data = '%s, %s, %.2f, %d, %d' %(now_human, now, percent, len(config.get_list('instances')), len(config.get_list('stopped_instances')))
    logger.info(data)
    print(data)
    return env_metric