Esempio n. 1
0
def get_latency_metrics(request, group_name):
    envs = environs_helper.get_all_envs_by_group(request, group_name)
    launch_config = autoscaling_groups_helper.get_group_info(request, group_name)
    util_data = {}
    stage_names = []
    if len(envs) == 0:
        return HttpResponse(json.dumps(util_data), content_type="application/json")

    try:
        for env in envs:
            name = "{}.{}".format(env["envName"], env["stageName"])
            stage_names.append(name)
            metric_name1 = "launch_latency.{}".format(name)
            launch_data_points = autoscaling_metrics_helper.get_latency_data(request, env["id"],
                                                                             "LAUNCH", settings.DEFAULT_START_TIME)
            json_data = []
            for data_point in launch_data_points:
                timestamp, value = data_point["timestamp"], data_point["value"] / 1000
                json_data.append([timestamp, value])
            util_data[metric_name1] = json_data

            metric_name2 = "deploy_latency.{}".format(name)
            deploy_data_points = autoscaling_metrics_helper.get_latency_data(request, env["id"],
                                                                             "DEPLOY", settings.DEFAULT_START_TIME)
            json_data2 = []
            for data_point in deploy_data_points:
                timestamp, value = data_point["timestamp"], data_point["value"] / 1000
                json_data2.append([timestamp, value])
            util_data[metric_name2] = json_data2

        util_data["stage_names"] = stage_names
        util_data["launch_latency_th"] = launch_config.get("groupInfo")["launchLatencyTh"]
    except:
        log.error(traceback.format_exc())
    return HttpResponse(json.dumps(util_data), content_type="application/json")
Esempio n. 2
0
    def get(self, request, group_name):
        autoscaling_summary = autoscaling_groups_helper.get_autoscaling_summary(
            request, group_name)
        asg_status = autoscaling_summary.get("status", "UNKNOWN")
        enable_spot = autoscaling_summary.get("enableSpot", False)
        envs = environs_helper.get_all_envs_by_group(request, group_name)
        disabled_actions = autoscaling_groups_helper.get_disabled_asg_actions(
            request, group_name)
        pas_config = autoscaling_groups_helper.get_pas_config(
            request, group_name)

        if "Terminate" in disabled_actions:
            scaling_down_event_enabled = False
        else:
            scaling_down_event_enabled = True
        group_info = autoscaling_groups_helper.get_group_info(
            request, group_name)
        if group_info:
            launch_config = group_info.get('launchInfo')
        else:
            launch_config = None
        return render(
            request, 'groups/group_details.html', {
                "asg_status": asg_status,
                "enable_spot": enable_spot,
                "group_name": group_name,
                "scaling_down_event_enabled": scaling_down_event_enabled,
                "envs": envs,
                "group_info": group_info,
                "launch_config": launch_config,
                "pas_enabled":
                pas_config['pas_state'] if pas_config else False,
            })
Esempio n. 3
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. 4
0
    def get(self, request, group_name):
        asg_cluster = autoscaling_groups_helper.get_group_info(request, group_name)
        appNames = baseimages_helper.get_image_names(request, 'AWS')
        appNames = sorted(appNames)
        is_cmp = False
        if asg_cluster:
            asg_vm_info = asg_cluster.get("launchInfo")
            curr_image = None
            if asg_vm_info:
                curr_image = baseimages_helper.get_by_provider_name(request, asg_vm_info["imageId"])
                if asg_vm_info.get("subnets"):
                    asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',')
            group_info = asg_cluster.get("groupInfo")
            group_info = get_group_config_internal(group_info)
            #Directly search the cluster name. As long as there exists a cluster, treat this as cmp and hide
            #Launch Configuration
            basic_cluster_info = clusters_helper.get_cluster(request, group_name)
            if basic_cluster_info:
                is_cmp = True
        else:
            asg_vm_info = None
            group_info = None
            curr_image = None

        pas_config = autoscaling_groups_helper.get_pas_config(request, group_name)
        return render(request, 'groups/asg_config.html', {
            "asg_vm_config": asg_vm_info,
            "app_names": appNames,
            "curr_image": curr_image,
            "group_config": group_info,
            "group_name": group_name,
            "pas_config": pas_config,
            "is_cmp": is_cmp
        })
Esempio n. 5
0
    def get(self, request, group_name):
        asg_cluster = autoscaling_groups_helper.get_group_info(request, group_name)
        appNames = baseimages_helper.get_image_names(request, 'AWS')
        appNames = sorted(appNames)
        is_cmp = False
        if asg_cluster:
            asg_vm_info = asg_cluster.get("launchInfo")
            curr_image = None
            if asg_vm_info:
                curr_image = baseimages_helper.get_by_provider_name(request, asg_vm_info["imageId"])
                if asg_vm_info.get("subnets"):
                    asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',')
            group_info = asg_cluster.get("groupInfo")
            group_info = get_group_config_internal(group_info)
            envs = environs_helper.get_all_envs_by_group(request, group_name)
            for env in envs:
                basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
                if basic_cluster_info:
                    is_cmp = True
        else:
            asg_vm_info = None
            group_info = None
            curr_image = None

        pas_config = autoscaling_groups_helper.get_pas_config(request, group_name)
        return render(request, 'groups/asg_config.html', {
            "asg_vm_config": asg_vm_info,
            "app_names": appNames,
            "curr_image": curr_image,
            "group_config": group_info,
            "group_name": group_name,
            "pas_config": pas_config,
            "is_cmp": is_cmp
        })
Esempio n. 6
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. 7
0
def get_configs(request):
    params = request.GET
    groupName = params["group_name"]
    group_info = autoscaling_groups_helper.get_group_info(request, groupName)
    sorted_subnets = None
    sorted_sgs = None
    config = None
    if group_info:
        config = group_info.get("launchInfo")
        instance_types, sorted_subnets, sorted_sgs = get_system_specs(request)
        if config:
            if config.get("subnets", None):
                config["subnetArrays"] = config["subnets"].split(',')
            else:
                config["subnetArrays"] = []
            config["userData"] = config["userData"].replace("\n", "<br>")

    contents = render_to_string(
        'groups/get_config.tmpl', {
            "groupName": groupName,
            "subnets": sorted_subnets,
            "security_groups": sorted_sgs,
            "config": config,
        })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Esempio n. 8
0
    def get(self, request, group_name):
        autoscaling_summary = autoscaling_groups_helper.get_autoscaling_summary(request, group_name)
        asg_status = autoscaling_summary.get("status", "UNKNOWN")
        enable_spot = autoscaling_summary.get("enableSpot", False)
        envs = environs_helper.get_all_envs_by_group(request, group_name)
        disabled_actions = autoscaling_groups_helper.get_disabled_asg_actions(request, group_name)
        pas_config = autoscaling_groups_helper.get_pas_config(request, group_name)

        if "Terminate" in disabled_actions:
            scaling_down_event_enabled = False
        else:
            scaling_down_event_enabled = True
        group_info = autoscaling_groups_helper.get_group_info(request, group_name)
        if group_info:
            launch_config = group_info.get('launchInfo')
        else:
            launch_config = None
        return render(request, 'groups/group_details.html', {
            "asg_status": asg_status,
            "enable_spot": enable_spot,
            "group_name": group_name,
            "scaling_down_event_enabled": scaling_down_event_enabled,
            "envs": envs,
            "group_info": group_info,
            "launch_config": launch_config,
            "pas_enabled": pas_config['pas_state'] if pas_config else False,
        })
Esempio n. 9
0
    def get(self, request, group_name):
        asg_cluster = autoscaling_groups_helper.get_group_info(request, group_name)
        appNames = baseimages_helper.get_image_names(request, 'AWS')
        appNames = sorted(appNames)
        is_cmp = False
        if asg_cluster:
            asg_vm_info = asg_cluster.get("launchInfo")
            curr_image = None
            if asg_vm_info:
                curr_image = baseimages_helper.get_by_provider_name(request, asg_vm_info["imageId"])
                if asg_vm_info.get("subnets"):
                    asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',')
            group_info = asg_cluster.get("groupInfo")
            group_info = get_group_config_internal(group_info)
            #Directly search the cluster name. As long as there exists a cluster, treat this as cmp and hide
            #Launch Configuration
            basic_cluster_info = clusters_helper.get_cluster(request, group_name)
            if basic_cluster_info:
                is_cmp = True
        else:
            asg_vm_info = None
            group_info = None
            curr_image = None

        pas_config = autoscaling_groups_helper.get_pas_config(request, group_name)
        return render(request, 'groups/asg_config.html', {
            "asg_vm_config": asg_vm_info,
            "app_names": appNames,
            "curr_image": curr_image,
            "group_config": group_info,
            "group_name": group_name,
            "pas_config": pas_config,
            "is_cmp": is_cmp
        })
Esempio n. 10
0
def get_asg_name(request, hosts):
    if IS_PINTEREST:
        for host in hosts:
            if host and host.get('groupName'):
                group_info = autoscaling_groups_helper.get_group_info(request, host.get('groupName'))
                if group_info and group_info.get("launchInfo") and group_info.get("launchInfo")["asgStatus"] == "ENABLED":
                    return host.get('groupName')
    return None
Esempio n. 11
0
def get_asg_name(request, hosts):
    if IS_PINTEREST:
        for host in hosts:
            if host and host.get('groupName'):
                group_info = autoscaling_groups_helper.get_group_info(request, host.get('groupName'))
                if group_info and group_info.get("launchInfo") and group_info.get("launchInfo")["asgStatus"] == "ENABLED":
                    return host.get('groupName')
    return None
Esempio n. 12
0
 def get(self, request, group_name):
     autoscaling_summary = autoscaling_groups_helper.get_autoscaling_summary(request, group_name)
     asg_status = autoscaling_summary.get("status", "UNKNOWN")
     enable_spot = autoscaling_summary.get("enableSpot", False)
     envs = environs_helper.get_all_envs_by_group(request, group_name)
     disabled_actions = autoscaling_groups_helper.get_disabled_asg_actions(request, group_name)
     if "Terminate" in disabled_actions:
         scaling_down_event_enabled = False
     else:
         scaling_down_event_enabled = True
     group_info = autoscaling_groups_helper.get_group_info(request, group_name)
     return render(request, 'groups/group_details.html', {
         "asg_status": asg_status,
         "enable_spot": enable_spot,
         "group_name": group_name,
         "scaling_down_event_enabled": scaling_down_event_enabled,
         "envs": envs,
         "group_info": group_info,
     })
Esempio n. 13
0
def get_launch_config(request, group_name):
    try:
        group_info = autoscaling_groups_helper.get_group_info(request, group_name)
        launch_config = group_info.get("launchInfo")

        if launch_config and launch_config.get("subnets"):
            launch_config["subnetArrays"] = launch_config["subnets"].split(',')
        appNames = baseimages_helper.get_image_names(request, 'AWS')
        appNames = sorted(appNames)
        curr_image = baseimages_helper.get_by_provider_name(request, launch_config["imageId"])
        html = render_to_string('groups/launch_config.tmpl', {
            "group_name": group_name,
            "app_names": appNames,
            "config": launch_config,
            "curr_image": curr_image,
            "csrf_token": get_token(request),
        })
    except:
        log.error(traceback.format_exc())
        raise
    return HttpResponse(json.dumps(html), content_type="application/json")
Esempio n. 14
0
def get_group_config(request, group_name):
    try:
        group_info = autoscaling_groups_helper.get_group_info(request, group_name)
        group_config = group_info.get("groupInfo")
        group_config = get_group_config_internal(group_config)
        is_cmp = False
        envs = environs_helper.get_all_envs_by_group(request, group_name)
        for env in envs:
            basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
            if basic_cluster_info:
                is_cmp = True
        html = render_to_string('groups/group_config.tmpl', {
            "group_name": group_name,
            "config": group_config,
            "is_cmp": is_cmp,
            "csrf_token": get_token(request),
        })
    except:
        log.error(traceback.format_exc())
        raise
    return HttpResponse(json.dumps(html), content_type="application/json")
Esempio n. 15
0
def get_launch_config(request, group_name):
    try:
        group_info = autoscaling_groups_helper.get_group_info(request, group_name)
        launch_config = group_info.get("launchInfo")

        if launch_config and launch_config.get("subnets"):
            launch_config["subnetArrays"] = launch_config["subnets"].split(',')
        appNames = baseimages_helper.get_image_names(request, 'AWS')
        appNames = sorted(appNames)
        curr_image = baseimages_helper.get_by_provider_name(request, launch_config["imageId"])
        html = render_to_string('groups/launch_config.tmpl', {
            "group_name": group_name,
            "app_names": appNames,
            "config": launch_config,
            "curr_image": curr_image,
            "csrf_token": get_token(request),
        })
    except:
        log.error(traceback.format_exc())
        raise
    return HttpResponse(json.dumps(html), content_type="application/json")
Esempio n. 16
0
def get_group_config(request, group_name):
    try:
        group_info = autoscaling_groups_helper.get_group_info(request, group_name)
        group_config = group_info.get("groupInfo")
        group_config = get_group_config_internal(group_config)
        is_cmp = False
        envs = environs_helper.get_all_envs_by_group(request, group_name)
        for env in envs:
            basic_cluster_info = clusters_helper.get_cluster(request, env.get('clusterName'))
            if basic_cluster_info:
                is_cmp = True
        html = render_to_string('groups/group_config.tmpl', {
            "group_name": group_name,
            "config": group_config,
            "is_cmp": is_cmp,
            "csrf_token": get_token(request),
        })
    except:
        log.error(traceback.format_exc())
        raise
    return HttpResponse(json.dumps(html), content_type="application/json")
Esempio n. 17
0
    def get(self, request, group_name):
        asg_cluster = autoscaling_groups_helper.get_group_info(
            request, group_name)
        appNames = baseimages_helper.get_image_names(request, 'AWS')
        appNames = sorted(appNames)
        is_cmp = False
        if asg_cluster:
            asg_vm_info = asg_cluster.get("launchInfo")
            curr_image = None
            if asg_vm_info:
                curr_image = baseimages_helper.get_by_provider_name(
                    request, asg_vm_info["imageId"])
                if asg_vm_info.get("subnets"):
                    asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(
                        ',')
            group_info = asg_cluster.get("groupInfo")
            group_info = get_group_config_internal(group_info)
            envs = environs_helper.get_all_envs_by_group(request, group_name)
            for env in envs:
                basic_cluster_info = clusters_helper.get_cluster(
                    request, env.get('clusterName'))
                if basic_cluster_info:
                    is_cmp = True
        else:
            asg_vm_info = None
            group_info = None
            curr_image = None

        pas_config = autoscaling_groups_helper.get_pas_config(
            request, group_name)
        return render(
            request, 'groups/asg_config.html', {
                "asg_vm_config": asg_vm_info,
                "app_names": appNames,
                "curr_image": curr_image,
                "group_config": group_info,
                "group_name": group_name,
                "pas_config": pas_config,
                "is_cmp": is_cmp
            })
Esempio n. 18
0
 def get(self, request, group_name):
     autoscaling_summary = autoscaling_groups_helper.get_autoscaling_summary(
         request, group_name)
     asg_status = autoscaling_summary.get("status", "UNKNOWN")
     enable_spot = autoscaling_summary.get("enableSpot", False)
     envs = environs_helper.get_all_envs_by_group(request, group_name)
     disabled_actions = autoscaling_groups_helper.get_disabled_asg_actions(
         request, group_name)
     if "Terminate" in disabled_actions:
         scaling_down_event_enabled = False
     else:
         scaling_down_event_enabled = True
     group_info = autoscaling_groups_helper.get_group_info(
         request, group_name)
     return render(
         request, 'groups/group_details.html', {
             "asg_status": asg_status,
             "enable_spot": enable_spot,
             "group_name": group_name,
             "scaling_down_event_enabled": scaling_down_event_enabled,
             "envs": envs,
             "group_info": group_info,
         })
Esempio n. 19
0
def get_configs(request):
    params = request.GET
    groupName = params["group_name"]
    group_info = autoscaling_groups_helper.get_group_info(request, groupName)
    sorted_subnets = None
    sorted_sgs = None
    config = None
    if group_info:
        config = group_info.get("launchInfo")
        instance_types, sorted_subnets, sorted_sgs = get_system_specs(request)
        if config:
            if config.get("subnets", None):
                config["subnetArrays"] = config["subnets"].split(',')
            else:
                config["subnetArrays"] = []
            config["userData"] = config["userData"].replace("\n", "<br>")

    contents = render_to_string('groups/get_config.tmpl', {
        "groupName": groupName,
        "subnets": sorted_subnets,
        "security_groups": sorted_sgs,
        "config": config,
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Esempio n. 20
0
    def get(self, request, name, stage):
        # cluster manager
        provider_list = None
        basic_cluster_info = None
        create_new = False
        adv = False
        env = environs_helper.get_env_by_stage(request, name, stage)
        cluster_name = env.get('clusterName')
        if IS_PINTEREST:
            provider_list = baseimages_helper.get_all_providers(request)
            basic_cluster_info = clusters_helper.get_cluster(request, cluster_name)
            if basic_cluster_info:
                base_image_id = basic_cluster_info.get('baseImageId')
                base_image = baseimages_helper.get_by_id(request, base_image_id)
                asg_cluster = autoscaling_groups_helper.get_group_info(request, cluster_name)
                basic_cluster_info['asg_info'] = asg_cluster

            params = request.GET
            if params.get('adv'):
                adv = params.get('adv')
            if params.get('create_new'):
                create_new = params.get('create_new')

        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
            groups = common.get_env_groups(request, name, stage)
            if cluster_name in groups:
                groups.remove(cluster_name)
            info = {
                "env": env,
                "hosts": hosts,
                "groups": groups,
                "csrf_token": get_token(request),
                'is_pinterest': IS_PINTEREST,
                'provider_list': provider_list,
                'basic_cluster_info': basic_cluster_info,
                'adv': adv,
                'create_new': create_new,
            }
            return HttpResponse(json.dumps(info), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        groups = common.get_env_groups(request, name, stage)
        if cluster_name in groups:
            groups.remove(cluster_name)
        data = {
            "envs": envs,
            "env": env,
            "stages": stages,
            "hosts": hosts,
            "groups": groups,
            'is_pinterest': IS_PINTEREST,
            'provider_list': provider_list,
            'basic_cluster_info': basic_cluster_info,
            'adv': adv,
            'create_new': create_new
        }
        data['info'] = json.dumps(data)
        return render(request, 'configs/capacity.html', data)
Esempio n. 21
0
    def get(self, request, name, stage):
        # cluster manager
        provider_list = None
        basic_cluster_info = None
        create_new = False
        adv = False
        env = environs_helper.get_env_by_stage(request, name, stage)
        cluster_name = env.get('clusterName')
        if IS_PINTEREST:
            provider_list = baseimages_helper.get_all_providers(request)
            basic_cluster_info = clusters_helper.get_cluster(request, cluster_name)
            if basic_cluster_info:
                base_image_id = basic_cluster_info.get('baseImageId')
                base_image = baseimages_helper.get_by_id(request, base_image_id)
                asg_cluster = autoscaling_groups_helper.get_group_info(request, cluster_name)
                basic_cluster_info['asg_info'] = asg_cluster
                basic_cluster_info['base_image_info'] = base_image

            params = request.GET
            if params.get('adv'):
                adv = params.get('adv')
            if params.get('create_new'):
                create_new = params.get('create_new')

        if request.is_ajax():
            # return data for ajax calls
            hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
            groups = common.get_env_groups(request, name, stage)
            if cluster_name in groups:
                groups.remove(cluster_name)
            info = {
                "env": env,
                "hosts": hosts,
                "groups": groups,
                "csrf_token": get_token(request),
                'is_pinterest': IS_PINTEREST,
                'provider_list': provider_list,
                'basic_cluster_info': basic_cluster_info,
                'adv': adv,
                'create_new': create_new,
            }
            return HttpResponse(json.dumps(info), content_type="application/json")

        # otherwise, return a page
        envs = environs_helper.get_all_env_stages(request, name)
        stages, env = common.get_all_stages(envs, stage)
        hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
        groups = common.get_env_groups(request, name, stage)
        if cluster_name in groups:
            groups.remove(cluster_name)
        data = {
            "envs": envs,
            "env": env,
            "stages": stages,
            "hosts": hosts,
            "groups": groups,
            'is_pinterest': IS_PINTEREST,
            'provider_list': provider_list,
            'basic_cluster_info': basic_cluster_info,
            'adv': adv,
            'create_new': create_new
        }
        data['info'] = json.dumps(data)
        return render(request, 'configs/capacity.html', data)
Esempio n. 22
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())
Esempio n. 23
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())