Esempio n. 1
0
def get_asg_config(request, group_name):
    asg_summary = autoscaling_groups_helper.get_autoscaling_summary(
        request, group_name)
    pas_config = autoscaling_groups_helper.get_pas_config(request, group_name)
    instances = groups_helper.get_group_hosts(request, group_name)
    group_info = autoscaling_groups_helper.get_group_info(request, group_name)
    launch_config = group_info.get("launchInfo")
    group_size = len(instances)
    policies = autoscaling_groups_helper.TerminationPolicy
    if asg_summary.get("spotRatio", None):
        asg_summary["spotRatio"] *= 100
    if asg_summary.get("sensitivityRatio", None):
        asg_summary["sensitivityRatio"] *= 100
    scheduled_actions = autoscaling_groups_helper.get_scheduled_actions(
        request, group_name)
    time_based_asg = False
    if len(scheduled_actions) > 0:
        time_based_asg = True
    content = render_to_string(
        "groups/asg_config.tmpl", {
            "group_name": group_name,
            "asg": asg_summary,
            "group_size": group_size,
            "terminationPolicies": policies,
            "instanceType": launch_config.get("instanceType"),
            "time_based_asg": time_based_asg,
            "csrf_token": get_token(request),
            "pas_config": pas_config,
        })
    return HttpResponse(json.dumps(content), content_type="application/json")
Esempio n. 2
0
def get_asg_config(request, group_name):
    asg_summary = autoscaling_groups_helper.get_autoscaling_summary(request, group_name)
    pas_config = autoscaling_groups_helper.get_pas_config(request, group_name)
    instances = groups_helper.get_group_hosts(request, group_name)
    group_info = autoscaling_groups_helper.get_group_info(request, group_name)
    launch_config = group_info.get("launchInfo")
    group_size = len(instances)
    policies = autoscaling_groups_helper.TerminationPolicy
    if asg_summary.get("spotRatio", None):
        asg_summary["spotRatio"] *= 100
    if asg_summary.get("sensitivityRatio", None):
        asg_summary["sensitivityRatio"] *= 100
    scheduled_actions = autoscaling_groups_helper.get_scheduled_actions(request, group_name)
    time_based_asg = False
    if len(scheduled_actions) > 0:
        time_based_asg = True
    content = render_to_string("groups/asg_config.tmpl", {
        "group_name": group_name,
        "asg": asg_summary,
        "group_size": group_size,
        "terminationPolicies": policies,
        "instanceType": launch_config.get("instanceType"),
        "time_based_asg": time_based_asg,
        "csrf_token": get_token(request),
        "pas_config": pas_config,
    })
    return HttpResponse(json.dumps(content), content_type="application/json")
Esempio n. 3
0
def gen_report(request, env, progress, sortByStatus="false"):
    agentStats = []
    firstTimeAgentStats = []
    deployStats = {}
    deprecatedDeployStats = []

    # always set the current
    deploy = deploys_helper.get(request, env['deployId'])
    build_info = builds_helper.get_build_and_tag(request, deploy["buildId"])
    stageDistMap = genStageDistMap()
    stateDistMap = genStateDistMap()
    currentDeployStat = DeployStatistics(deploy=deploy,
                                         build=build_info['build'],
                                         stageDistMap=stageDistMap,
                                         stateDistMap=stateDistMap,
                                         buildTag=build_info.get('tag'))
    deployStats[env['deployId']] = currentDeployStat

    for agent in progress["agents"]:
        if agent["firstDeploy"]:
            firstTimeAgentStats.append(
                addToEnvReport(request, deployStats, agent, env))
        else:
            agentStats.append(addToEnvReport(request, deployStats, agent, env))

    if sortByStatus == "true":
        agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y))

    for key, value in deployStats.iteritems():
        if key != env['deployId']:
            deprecatedDeployStats.append(value)

    provisioning_hosts = progress["provisioningHosts"]
    if IS_PINTEREST:
        basic_cluster_info = clusters_helper.get_cluster(
            request, env.get('clusterName'))
        if basic_cluster_info and basic_cluster_info.get('capacity'):
            hosts_in_cluster = groups_helper.get_group_hosts(
                request, env.get('clusterName'))
            num_to_fake = basic_cluster_info.get('capacity') - len(
                hosts_in_cluster)
            for i in range(num_to_fake):
                faked_host = {}
                faked_host['hostName'] = 'UNKNOWN'
                faked_host['hostId'] = 'UNKNOWN'
                faked_host['state'] = 'PROVISIONED'
                provisioning_hosts.append(faked_host)

    return AgentReport(firstTimeAgentStats=firstTimeAgentStats,
                       agentStats=agentStats,
                       currentDeployStat=currentDeployStat,
                       deprecatedDeployStats=deprecatedDeployStats,
                       missingHosts=progress["missingHosts"],
                       provisioningHosts=provisioning_hosts,
                       envName=env['envName'],
                       stageName=env['stageName'])
Esempio n. 4
0
def gen_report(request, env, progress, sortByStatus="false"):
    agentStats = []
    firstTimeAgentStats = []
    deployStats = {}
    deprecatedDeployStats = []

    # always set the current
    deploy = deploys_helper.get(request, env['deployId'])
    build_info = builds_helper.get_build_and_tag(request, deploy["buildId"])
    stageDistMap = genStageDistMap()
    stateDistMap = genStateDistMap()
    currentDeployStat = DeployStatistics(deploy=deploy, build=build_info['build'], stageDistMap=stageDistMap,
                                         stateDistMap=stateDistMap, buildTag=build_info.get('tag'))
    deployStats[env['deployId']] = currentDeployStat

    for agent in progress["agents"]:
        if agent["firstDeploy"]:
            firstTimeAgentStats.append(addToEnvReport(request, deployStats, agent, env))
        else:
            agentStats.append(addToEnvReport(request, deployStats, agent, env))

    if sortByStatus == "true":
        agentStats.sort(cmp=lambda x, y: _compare_agent_status(x, y))

    for key, value in deployStats.iteritems():
        if key != env['deployId']:
            deprecatedDeployStats.append(value)

    provisioning_hosts = progress["provisioningHosts"]
    if IS_PINTEREST:
        basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
        if basic_cluster_info and basic_cluster_info.get('capacity'):
            hosts_in_cluster = groups_helper.get_group_hosts(request, env.get('clusterName'))
            num_to_fake = basic_cluster_info.get('capacity') - len(hosts_in_cluster)
            for i in range(num_to_fake):
                faked_host = {}
                faked_host['hostName'] = 'UNKNOWN'
                faked_host['hostId'] = 'UNKNOWN'
                faked_host['state'] = 'PROVISIONED'
                provisioning_hosts.append(faked_host)

    return AgentReport(firstTimeAgentStats=firstTimeAgentStats,
                       agentStats=agentStats,
                       currentDeployStat=currentDeployStat,
                       deprecatedDeployStats=deprecatedDeployStats,
                       missingHosts=progress["missingHosts"],
                       provisioningHosts=provisioning_hosts,
                       envName=env['envName'], stageName=env['stageName'])
Esempio n. 5
0
def get_group_info(request, group_name):
    try:
        group_info = autoscaling_groups_helper.get_group_info(
            request, group_name)
        launch_config = group_info.get("launchInfo")
        asgs = autoscaling_groups_helper.get_autoscaling(request, group_name)
        spot_asg = None
        nonspot_asg = None
        spot_asg_instances = []
        nonspot_asg_instances = []
        if asgs:
            for asg in asgs:
                if asg.get("enableSpot", None):
                    spot_asg = asg
                    spot_asg_instances = asg.get("instances")
                else:
                    nonspot_asg = asg
                    nonspot_asg_instances = asg.get("instances")

        all_hosts_in_group = groups_helper.get_group_hosts(request, group_name)
        non_asg_host_names = []
        non_asg_host_ids = []
        asg_host_names = []
        spot_asg_host_names = []
        if spot_asg:
            has_spot_group = True
        else:
            has_spot_group = False

        for host in all_hosts_in_group:
            host_name = host.get("hostName", "")
            host_id = host.get("hostId", "")
            if nonspot_asg_instances and host_id in nonspot_asg_instances:
                asg_host_names.append(host_name)
                nonspot_asg_instances.remove(host_id)
            elif spot_asg_instances and host_id in spot_asg_instances:
                spot_asg_host_names.append(host_name)
                spot_asg_instances.remove(host_id)
            else:
                non_asg_host_names.append(host_name)
                non_asg_host_ids.append(host_id)

        non_asg_host_ids_str = ",".join(non_asg_host_ids)
        asg_host_names.extend(nonspot_asg_instances)
        spot_asg_host_names.extend(spot_asg_instances)

        if launch_config["asgStatus"] == "DISABLED":
            asg_status_str = "Disabled"
        elif launch_config["asgStatus"] == "ENABLED":
            asg_status_str = "Enabled"
        else:
            asg_status_str = "Not Enabled"
        asg_state = autoscaling_groups_helper.get_alarm_state(
            request, group_name)
        if asg_state == "UNKNOWN":
            asg_state_str = ""
        elif asg_state == "SCALE_UP_ALARM":
            asg_state_str = "Scaling up"
        elif asg_state == "SCALE_DOWN_ALARM":
            asg_state_str = "Scaling down"
        else:
            asg_state_str = "OK"

        group_size = len(asg_host_names) + len(non_asg_host_names) + len(
            spot_asg_host_names)
        spot_size = len(spot_asg_host_names)
        content = render_to_string(
            "groups/group_info.tmpl", {
                "instance_type": launch_config["instanceType"],
                "security_group": launch_config["securityGroup"],
                "group_name": group_name,
                "fleet_size": group_size,
                "spot_size": spot_size,
                "asg": nonspot_asg,
                "spot_asg": spot_asg,
                "asg_status": asg_status_str,
                "asg_hosts": asg_host_names,
                "spot_asg_hosts": spot_asg_host_names,
                "other_hosts": non_asg_host_names,
                "other_host_ids": non_asg_host_ids_str,
                "has_spot_group": has_spot_group,
                "asg_state": asg_state_str,
                "csrf_token": get_token(request),
            })
        return HttpResponse(json.dumps({"html": content}),
                            content_type="application/json")
    except:
        log.error(traceback.format_exc())
Esempio n. 6
0
def get_group_info(request, group_name):
    try:
        group_info = autoscaling_groups_helper.get_group_info(request, group_name)
        launch_config = group_info.get("launchInfo")
        asgs = autoscaling_groups_helper.get_autoscaling(request, group_name)
        spot_asg = None
        nonspot_asg = None
        spot_asg_instances = []
        nonspot_asg_instances = []
        if asgs:
            for asg in asgs:
                if asg.get("enableSpot", None):
                    spot_asg = asg
                    spot_asg_instances = asg.get("instances")
                else:
                    nonspot_asg = asg
                    nonspot_asg_instances = asg.get("instances")

        all_hosts_in_group = groups_helper.get_group_hosts(request, group_name)
        non_asg_host_names = []
        non_asg_host_ids = []
        asg_host_names = []
        spot_asg_host_names = []
        if spot_asg:
            has_spot_group = True
        else:
            has_spot_group = False

        for host in all_hosts_in_group:
            host_name = host.get("hostName", "")
            host_id = host.get("hostId", "")
            if nonspot_asg_instances and host_id in nonspot_asg_instances:
                asg_host_names.append(host_name)
                nonspot_asg_instances.remove(host_id)
            elif spot_asg_instances and host_id in spot_asg_instances:
                spot_asg_host_names.append(host_name)
                spot_asg_instances.remove(host_id)
            else:
                non_asg_host_names.append(host_name)
                non_asg_host_ids.append(host_id)

        non_asg_host_ids_str = ",".join(non_asg_host_ids)
        asg_host_names.extend(nonspot_asg_instances)
        spot_asg_host_names.extend(spot_asg_instances)

        if launch_config["asgStatus"] == "DISABLED":
            asg_status_str = "Disabled"
        elif launch_config["asgStatus"] == "ENABLED":
            asg_status_str = "Enabled"
        else:
            asg_status_str = "Not Enabled"
        group_size = len(asg_host_names) + len(non_asg_host_names) + len(spot_asg_host_names)
        spot_size = len(spot_asg_host_names)
        content = render_to_string("groups/group_info.tmpl", {
            "instance_type": launch_config["instanceType"],
            "security_group": launch_config["securityGroup"],
            "group_name": group_name,
            "fleet_size": group_size,
            "spot_size": spot_size,
            "asg": nonspot_asg,
            "spot_asg": spot_asg,
            "asg_status": asg_status_str,
            "asg_hosts": asg_host_names,
            "spot_asg_hosts": spot_asg_host_names,
            "other_hosts": non_asg_host_names,
            "other_host_ids": non_asg_host_ids_str,
            "has_spot_group": has_spot_group,
            "csrf_token": get_token(request),
        })
        return HttpResponse(json.dumps({"html": content}), content_type="application/json")
    except:
        log.error(traceback.format_exc())