Пример #1
0
def get_asg_name(request, host):
    asg = ''
    if host and host.get('groupName'):
        group_info = groups_helper.get_group_info(request, host.get('groupName'))
        if group_info and group_info["asgStatus"] == "ENABLED":
            asg = host.get('groupName')
    return asg
Пример #2
0
def get_asg_config(request, group_name):
    asg_summary = groups_helper.get_autoscaling_summary(request, group_name)
    instances = groups_helper.get_group_instances(request, group_name)
    group_info = groups_helper.get_group_info(request, group_name)
    launch_config = group_info.get("launchInfo")
    group_size = len(instances)
    policies = 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 = 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),
    })
    return HttpResponse(json.dumps(content), content_type="application/json")
Пример #3
0
def get_launch_config(request, group_name):
    try:
        group_info = groups_helper.get_group_info(request, group_name)
        if group_info and group_info.get("subnets"):
            group_info["subnetArrays"] = group_info["subnets"].split(',')
        if group_info and not group_info.get("asgStatus"):
            group_info["asgStatus"] = "UNKNOWN"
        if group_info and group_info.get("launchLatencyTh"):
            group_info["launchLatencyTh"] = group_info.get(
                "launchLatencyTh") / 60
        if group_info and group_info.get("healthcheckPeriod"):
            group_info["healthcheckPeriod"] = group_info.get(
                "healthcheckPeriod") / 60
        if group_info and group_info.get("lifecycleTimeout"):
            group_info["lifecycleTimeout"] = group_info.get(
                "lifecycleTimeout") / 60

        appNames = images_helper.get_all_app_names(request)
        appNames = sorted(appNames)
        curr_image = images_helper.get_image_by_id(request,
                                                   group_info["imageId"])
        html = render_to_string(
            'groups/group_config.tmpl', {
                "group_name": group_name,
                "app_names": appNames,
                "config": group_info,
                "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")
Пример #4
0
def get_latency_metrics(request, group_name):
    envs = environs_helper.get_all_envs_by_group(request, group_name)
    launch_config = 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["launchLatencyTh"]
    except:
        log.error(traceback.format_exc())
    return HttpResponse(json.dumps(util_data), content_type="application/json")
Пример #5
0
def get_asg_config(request, group_name):
    asgs = groups_helper.get_autoscaling(request, group_name)
    instances = groups_helper.get_group_instances(request, group_name)
    group_info = groups_helper.get_group_info(request, group_name)
    result_asg = {}
    if len(asgs) > 1:
        result_asg["enableSpot"] = True
        for asg in asgs:
            if asg.get("spotGroup"):
                result_asg["ratio"] = asg["spotRatio"] * 100
                result_asg["bidPrice"] = asg["bidPrice"]
            else:
                result_asg["minSize"] = asg["minSize"]
                result_asg["maxSize"] = asg["maxSize"]
                result_asg["terminationPolicy"] = asg["terminationPolicy"]
    else:
        result_asg = asgs[0]
        result_asg["enableSpot"] = False

    group_size = len(instances)
    policies = groups_helper.TerminationPolicy
    content = render_to_string("groups/asg_config.tmpl", {
        "group_name": group_name,
        "asg": result_asg,
        "group_size": group_size,
        "terminationPolicies": policies,
        "instanceType": group_info.get("instanceType"),
        "csrf_token": get_token(request),
    })
    return HttpResponse(json.dumps(content), content_type="application/json")
Пример #6
0
 def get(self, request, group_name):
     asg_cluster = groups_helper.get_group_info(request, group_name)
     appNames = images_helper.get_all_app_names(request)
     appNames = sorted(appNames)
     is_cmp = False
     if asg_cluster:
         asg_vm_info = asg_cluster.get("launchInfo")
         if asg_vm_info and asg_vm_info.get("subnets"):
             asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',')
         group_info = asg_cluster.get("groupInfo")
         curr_image = images_helper.get_image_by_id(request,
                                                    asg_vm_info["imageId"])
         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('envName'), env.get('stageName'))
             if basic_cluster_info:
                 is_cmp = True
     else:
         asg_vm_info = None
         group_info = None
         curr_image = None
     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,
             "is_cmp": is_cmp
         })
Пример #7
0
def get_launch_config(request, group_name):
    try:
        group_info = groups_helper.get_group_info(request, group_name)
        if group_info and group_info.get("subnets"):
            group_info["subnetArrays"] = group_info["subnets"].split(',')
        if group_info and not group_info.get("asgStatus"):
            group_info["asgStatus"] = "UNKNOWN"
        if group_info and group_info.get("launchLatencyTh"):
            group_info["launchLatencyTh"] = group_info.get("launchLatencyTh") / 60
        if group_info and group_info.get("healthcheckPeriod"):
            group_info["healthcheckPeriod"] = group_info.get("healthcheckPeriod") / 60
        if group_info and group_info.get("lifecycleTimeout"):
            group_info["lifecycleTimeout"] = group_info.get("lifecycleTimeout") / 60

        appNames = images_helper.get_all_app_names(request)
        appNames = sorted(appNames)
        curr_image = images_helper.get_image_by_id(request, group_info["imageId"])
        html = render_to_string('groups/group_config.tmpl', {
            "group_name": group_name,
            "app_names": appNames,
            "config": group_info,
            "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")
Пример #8
0
def get_configs(request):
    params = request.GET
    groupName = params["group_name"]
    config = groups_helper.get_group_info(request, groupName)
    empty_config = False
    if not config.get("instanceType") or not config.get("securityGroup") \
            or not config.get("imageId") or not config.get("userData") or not config.get("subnets"):
        empty_config = True

    instance_types, sorted_subnets, sorted_sgs = get_system_specs(request)
    if config and config.get("subnets"):
        config["subnetArrays"] = config["subnets"].split(',')

    if config and config.get("userData"):
        config["userData"] = config["userData"].replace("\n", "<br>")

    contents = render_to_string('groups/get_config.tmpl', {
        "groupName": groupName,
        "empty_config": empty_config,
        "subnets": sorted_subnets,
        "security_groups": sorted_sgs,
        "config": config,
        "asgStatus": config["asgStatus"],
    })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Пример #9
0
def get_asg_name(request, host):
    asg = ''
    if host and host.get('groupName'):
        group_info = groups_helper.get_group_info(request, host.get('groupName'))
        if group_info and group_info["asgStatus"] == "ENABLED":
            asg = host.get('groupName')
    return asg
Пример #10
0
 def get(self, request, group_name):
     asg_cluster = groups_helper.get_group_info(request, group_name)
     appNames = images_helper.get_all_app_names(request)
     appNames = sorted(appNames)
     is_cmp = False
     if asg_cluster:
         asg_vm_info = asg_cluster.get("launchInfo")
         if asg_vm_info and asg_vm_info.get("subnets"):
              asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',')
         group_info = asg_cluster.get("groupInfo")
         curr_image = images_helper.get_image_by_id(request, asg_vm_info["imageId"])
         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('envName'), env.get('stageName'))
             if basic_cluster_info:
                 is_cmp = True
     else:
         asg_vm_info = None
         group_info = None
         curr_image = None
     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,
         "is_cmp": is_cmp
     })
Пример #11
0
def get_configs(request):
    params = request.GET
    groupName = params["group_name"]
    config = groups_helper.get_group_info(request, groupName)
    empty_config = False
    if not config.get("instanceType") or not config.get("securityGroup") \
            or not config.get("imageId") or not config.get("userData") or not config.get("subnets"):
        empty_config = True

    instance_types, sorted_subnets, sorted_sgs = get_system_specs(request)
    if config and config.get("subnets"):
        config["subnetArrays"] = config["subnets"].split(',')

    if config and config.get("userData"):
        config["userData"] = config["userData"].replace("\n", "<br>")

    contents = render_to_string(
        'groups/get_config.tmpl', {
            "groupName": groupName,
            "empty_config": empty_config,
            "subnets": sorted_subnets,
            "security_groups": sorted_sgs,
            "config": config,
            "asgStatus": config["asgStatus"],
        })
    return HttpResponse(json.dumps(contents), content_type="application/json")
Пример #12
0
def get_asg_name(request, hosts):
    for host in hosts:
        if host and host.get('groupName'):
            group_info = groups_helper.get_group_info(request, host.get('groupName'))
            if group_info and group_info["asgStatus"] == "ENABLED":
                return host.get('groupName')
    return None
Пример #13
0
def get_group_info(request, group_name):
    try:
        group_info = groups_helper.get_group_info(request, group_name)
        asgs = 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("spotGroup", 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_instances(request, group_name)
        non_asg_host_names = []
        asg_host_names = []
        spot_asg_host_names = []

        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)

        asg_host_names.extend(nonspot_asg_instances)
        spot_asg_host_names.extend(spot_asg_instances)

        if group_info["asgStatus"] == "DISABLED":
            asg_status_str = "Disabled"
        elif group_info["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": group_info["instanceType"],
            "security_group": group_info["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,
            "other_hosts": non_asg_host_names,
        })
        return HttpResponse(json.dumps({"html": content}), content_type="application/json")
    except:
        log.error(traceback.format_exc())
Пример #14
0
def get_asg_name(request, hosts):
    if IS_PINTEREST:
        for host in hosts:
            if host and host.get('groupName'):
                group_info = 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
Пример #15
0
def get_asg_name(request, hosts):
    if IS_PINTEREST:
        for host in hosts:
            if host and host.get('groupName'):
                group_info = 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
Пример #16
0
    def get(self, request, name, stage, hostname):
        agents = agents_helper.get_agents_by_host(request, hostname)
        env = environs_helper.get_env_by_stage(request, name, stage)
        host = environ_hosts_helper.get_host_by_env_and_hostname(
            request, name, stage, hostname)
        show_terminate = False
        asg = ''
        if host and host.get('hostId'):
            if host.get('state') != 'PENDING_TERMINATE' and host.get(
                    'state') != 'TERMINATING' and host.get(
                        'state') != 'TERMINATED':
                show_terminate = True

        cluster_provider = clusters_helper.get_cluster_provider(
            request, name, stage)
        if cluster_provider == 'null':
            cluster_provider = None

        # TODO deprecated it
        if host and host.get('groupName'):
            group_info = groups_helper.get_group_info(request,
                                                      host.get('groupName'))
            if group_info and group_info["asgStatus"] == "ENABLED":
                asg = host.get('groupName')

        # gather the env name and stage info
        agent_wrappers = []
        for agent in agents:
            agent_wrapper = {}
            agent_wrapper["agent"] = agent
            envId = agent['envId']
            agent_env = environs_helper.get(request, envId)
            agent_wrapper["env"] = env
            agent_wrapper["error"] = ""
            if agent.get('lastErrno', 0) != 0:
                agent_wrapper["error"] = agents_helper.get_agent_error(
                    request, agent_env['envName'], agent_env['stageName'],
                    hostname)
            agent_wrappers.append(agent_wrapper)

        return render(
            request, 'hosts/host_details.html', {
                'env_name': name,
                'stage_name': stage,
                'hostname': hostname,
                'host': host,
                'agent_wrappers': agent_wrappers,
                'show_terminate': show_terminate,
                'cluster_provider': cluster_provider,
                'asg_group': asg,
                'pinterest': IS_PINTEREST,
            })
Пример #17
0
def get_group_config(request, group_name):
    try:
        group_info = groups_helper.get_group_info(request, group_name)
        group_config = group_info.get("groupInfo")
        group_config = get_group_config_internal(group_config)
        html = render_to_string('groups/group_config.tmpl', {
            "group_name": group_name,
            "config": group_config,
            "csrf_token": get_token(request),
        })
    except:
        log.error(traceback.format_exc())
        raise
    return HttpResponse(json.dumps(html), content_type="application/json")
Пример #18
0
 def get(self, request, group_name):
     autoscaling_summary = 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)
     scaling_down_event_enabled = groups_helper.get_scaling_down_event_status(request, group_name)
     group_info = 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,
     })
Пример #19
0
    def get(self, request, name, stage, hostname):
        agents = agents_helper.get_agents_by_host(request, hostname)
        env = environs_helper.get_env_by_stage(request, name, stage)
        host = environ_hosts_helper.get_host_by_env_and_hostname(request, name, stage, hostname)
        show_terminate = False
        asg = ''
        if host and host.get('hostId'):
            if host.get('state') != 'PENDING_TERMINATE' and host.get('state') != 'TERMINATING' and host.get('state') != 'TERMINATED':
                show_terminate = True

        cluster_provider = clusters_helper.get_cluster_provider(request, name, stage)
        if cluster_provider == 'null':
            cluster_provider = None

        # TODO deprecated it
        if host and host.get('groupName'):
            group_info = groups_helper.get_group_info(request, host.get('groupName'))
            if group_info and group_info["asgStatus"] == "ENABLED":
                asg = host.get('groupName')

        # gather the env name and stage info
        agent_wrappers = []
        for agent in agents:
            agent_wrapper = {}
            agent_wrapper["agent"] = agent
            envId = agent['envId']
            agent_env = environs_helper.get(request, envId)
            agent_wrapper["env"] = env
            agent_wrapper["error"] = ""
            if agent.get('lastErrno', 0) != 0:
                agent_wrapper["error"] = agents_helper.get_agent_error(request, agent_env['envName'],
                                                                       agent_env['stageName'], hostname)
            agent_wrappers.append(agent_wrapper)

        return render(request, 'hosts/host_details.html', {
            'env_name': name,
            'stage_name': stage,
            'hostname': hostname,
            'host': host,
            'agent_wrappers': agent_wrappers,
            'show_terminate': show_terminate,
            'cluster_provider': cluster_provider,
            'asg_group': asg,
            'pinterest': IS_PINTEREST,
        })
Пример #20
0
def get_asg_config(request, group_name):
    asg_summary = groups_helper.get_autoscaling_summary(request, group_name)
    instances = groups_helper.get_group_instances(request, group_name)
    group_info = groups_helper.get_group_info(request, group_name)
    group_size = len(instances)
    policies = groups_helper.TerminationPolicy
    if asg_summary.get("spotRatio", None):
        asg_summary["spotRatio"] *= 100
    if asg_summary.get("sensitivityRatio", None):
        asg_summary["sensitivityRatio"] *= 100
    content = render_to_string("groups/asg_config.tmpl", {
        "group_name": group_name,
        "asg": asg_summary,
        "group_size": group_size,
        "terminationPolicies": policies,
        "instanceType": group_info.get("instanceType"),
        "csrf_token": get_token(request),
    })
    return HttpResponse(json.dumps(content), content_type="application/json")
Пример #21
0
    def get(self, request, name, stage, hostname):
        host = environ_hosts_helper.get_host_by_env_and_hostname(request, name, stage, hostname)
        show_terminate = False
        if host and host.get('state') and host.get('state') != 'PENDING_TERMINATE' and host.get('state') != 'TERMINATING' and host.get('state') != 'TERMINATED':
            show_terminate = True

        # TODO deprecated it
        asg = ''
        if host and host.get('groupName'):
            group_info = groups_helper.get_group_info(request, host.get('groupName'))
            if group_info and group_info["asgStatus"] == "ENABLED":
                asg = host.get('groupName')

        # gather the env name and stage info
        agents = agents_helper.get_agents_by_host(request, hostname)
        agent_wrappers = []
        show_force_terminate = False
        for agent in agents:
            if agent.get('deployStage') == 'STOPPING' or agent.get('deployStage') == 'STOPPED':
                if is_agent_failed(agent):
                    show_force_terminate = True
            agent_wrapper = {}
            agent_wrapper["agent"] = agent
            envId = agent['envId']
            agent_env = environs_helper.get(request, envId)
            agent_wrapper["env"] = agent_env
            agent_wrapper["error"] = ""
            if agent.get('lastErrno', 0) != 0:
                agent_wrapper["error"] = agents_helper.get_agent_error(request, agent_env['envName'],
                                                                       agent_env['stageName'], hostname)
            agent_wrappers.append(agent_wrapper)

        return render(request, 'hosts/host_details.html', {
            'env_name': name,
            'stage_name': stage,
            'hostname': hostname,
            'host': host,
            'agent_wrappers': agent_wrappers,
            'show_terminate': show_terminate,
            'show_force_terminate': show_force_terminate,
            'asg_group': asg,
            'pinterest': IS_PINTEREST,
        })
Пример #22
0
def get_configs(request):
    params = request.GET
    groupName = params["group_name"]
    group_info = 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:
            config["subnetArrays"] = config["subnets"].split(',')
            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")
Пример #23
0
def get_launch_config(request, group_name):
    try:
        group_info = 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 = images_helper.get_all_app_names(request)
        appNames = sorted(appNames)
        curr_image = images_helper.get_image_by_id(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")
Пример #24
0
def get_group_config(request, group_name):
    try:
        group_info = 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('envName'), env.get('stageName'))
            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")
Пример #25
0
def get_launch_config(request, group_name):
    try:
        group_info = 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 = images_helper.get_all_app_names(request)
        appNames = sorted(appNames)
        curr_image = images_helper.get_image_by_id(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")
Пример #26
0
def get_host_details(request, name):
    agents = agents_helper.get_agents_by_host(request, name)
    hosts = hosts_helper.get_hosts_by_name(request, name)
    # gather the env name and stage info
    agent_wrappers = []
    for agent in agents:
        agent_wrapper = {}
        agent_wrapper["agent"] = agent
        envId = agent['envId']
        env = environs_helper.get(request, envId)
        agent_wrapper["env"] = env
        agent_wrapper["error"] = ""
        if agent.get('lastErrno', 0) != 0:
            agent_wrapper["error"] = agents_helper.get_agent_error(
                request, env['envName'], env['stageName'], name)
        agent_wrappers.append(agent_wrapper)

    host_id = ""
    asgGroup = ""
    for host in hosts:
        host_id = host['hostId']
        group_name = host["groupName"]
        # TODO Remove this hack
        if not group_name or group_name == 'NULL':
            continue
        group_info = groups_helper.get_group_info(request, group_name)
        if group_info and group_info["asgStatus"] == "ENABLED":
            asgGroup = group_name
            break

    return render(
        request, 'hosts/host_details.html', {
            'agent_wrappers': agent_wrappers,
            'hosts': hosts,
            'name': name,
            'hostId': host_id,
            'show_terminate': True,
            "asg_group": asgGroup,
            "pinterest": IS_PINTEREST,
        })
Пример #27
0
def get_group_info(request, group_name):
    try:
        group_info = groups_helper.get_group_info(request, group_name)
        hosts_in_asg = set(
            groups_helper.get_autoscaling_group_instances(request, group_name))
        all_hosts_in_group = groups_helper.get_group_instances(
            request, group_name)
        non_asg_host_names = []
        asg_host_names = []
        for host in all_hosts_in_group:
            host_name = host.get("hostName", "")
            host_id = host.get("hostId", "")
            if host_id in hosts_in_asg:
                asg_host_names.append(host_name)
                hosts_in_asg.remove(host_id)
            else:
                non_asg_host_names.append(host_name)
        asg_host_names.extend(hosts_in_asg)

        if group_info["asgStatus"] == "DISABLED":
            asg_status_str = "Disabled"
        elif group_info["asgStatus"] == "ENABLED":
            asg_status_str = "Enabled"
        else:
            asg_status_str = "Not Enabled"
        group_size = len(hosts_in_asg) + len(all_hosts_in_group)
        content = render_to_string(
            "groups/group_info.tmpl", {
                "group_name": group_name,
                "instance_type": group_info["instanceType"],
                "security_group": group_info["securityGroup"],
                "fleet_size": group_size,
                "asg_status": asg_status_str,
                "asg_hosts": asg_host_names,
                "other_hosts": non_asg_host_names
            })
        return HttpResponse(json.dumps({"html": content}),
                            content_type="application/json")
    except:
        log.error(traceback.format_exc())
Пример #28
0
def get_configs(request):
    params = request.GET
    groupName = params["group_name"]
    group_info = 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:
            config["subnetArrays"] = config["subnets"].split(',')
            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")
Пример #29
0
def get_group_info(request, group_name):
    try:
        group_info = groups_helper.get_group_info(request, group_name)
        hosts_in_asg = set(groups_helper.get_autoscaling_group_instances(request, group_name))
        all_hosts_in_group = groups_helper.get_group_instances(request, group_name)
        non_asg_host_names = []
        asg_host_names = []
        for host in all_hosts_in_group:
            host_name = host.get("hostName", "")
            host_id = host.get("hostId", "")
            if host_id in hosts_in_asg:
                asg_host_names.append(host_name)
                hosts_in_asg.remove(host_id)
            else:
                non_asg_host_names.append(host_name)
        asg_host_names.extend(hosts_in_asg)

        if group_info["asgStatus"] == "DISABLED":
            asg_status_str = "Disabled"
        elif group_info["asgStatus"] == "ENABLED":
            asg_status_str = "Enabled"
        else:
            asg_status_str = "Not Enabled"
        group_size = len(hosts_in_asg) + len(all_hosts_in_group)
        content = render_to_string(
            "groups/group_info.tmpl",
            {
                "group_name": group_name,
                "instance_type": group_info["instanceType"],
                "security_group": group_info["securityGroup"],
                "fleet_size": group_size,
                "asg_status": asg_status_str,
                "asg_hosts": asg_host_names,
                "other_hosts": non_asg_host_names,
            },
        )
        return HttpResponse(json.dumps({"html": content}), content_type="application/json")
    except:
        log.error(traceback.format_exc())
Пример #30
0
def get_host_details(request, name):
    agents = agents_helper.get_agents_by_host(request, name)
    hosts = hosts_helper.get_hosts_by_name(request, name)
    # gather the env name and stage info
    agent_wrappers = []
    for agent in agents:
        agent_wrapper = {}
        agent_wrapper["agent"] = agent
        envId = agent['envId']
        env = environs_helper.get(request, envId)
        agent_wrapper["env"] = env
        agent_wrapper["error"] = ""
        if agent.get('lastErrno', 0) != 0:
            agent_wrapper["error"] = agents_helper.get_agent_error(request, env['envName'],
                                                                   env['stageName'], name)
        agent_wrappers.append(agent_wrapper)

    host_id = ""
    asgGroup = ""
    for host in hosts:
        host_id = host['hostId']
        group_name = host["groupName"]
        # TODO Remove this hack
        if not group_name or group_name == 'NULL':
            continue
        group_info = groups_helper.get_group_info(request, group_name)
        if group_info and group_info["asgStatus"] == "ENABLED":
            asgGroup = group_name
            break

    return render(request, 'hosts/host_details.html', {
        'agent_wrappers': agent_wrappers,
        'hosts': hosts,
        'name': name,
        'hostId': host_id,
        'show_terminate': True,
        "asg_group": asgGroup,
        "pinterest": IS_PINTEREST,
    })
Пример #31
0
 def get(self, request, group_name):
     asg_cluster = groups_helper.get_group_info(request, group_name)
     appNames = images_helper.get_all_app_names(request)
     appNames = sorted(appNames)
     if asg_cluster:
         asg_vm_info = asg_cluster.get("launchInfo")
         if asg_vm_info and asg_vm_info.get("subnets"):
              asg_vm_info["subnetArrays"] = asg_vm_info["subnets"].split(',')
         group_info = asg_cluster.get("groupInfo")
         curr_image = images_helper.get_image_by_id(request, asg_vm_info["imageId"])
         group_info = get_group_config_internal(group_info)
     else:
         asg_vm_info = None
         group_info = None
         curr_image = None
     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,
     })
Пример #32
0
def get_group_config(request, group_name):
    try:
        group_info = 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('envName'), env.get('stageName'))
            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")
Пример #33
0
def get_group_info(request, group_name):
    try:
        group_info = groups_helper.get_group_info(request, group_name)
        asgs = 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("spotGroup", 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_instances(
            request, group_name)
        non_asg_host_names = []
        asg_host_names = []
        spot_asg_host_names = []

        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)

        asg_host_names.extend(nonspot_asg_instances)
        spot_asg_host_names.extend(spot_asg_instances)

        if group_info["asgStatus"] == "DISABLED":
            asg_status_str = "Disabled"
        elif group_info["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": group_info["instanceType"],
                "security_group": group_info["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,
                "other_hosts": non_asg_host_names,
            })
        return HttpResponse(json.dumps({"html": content}),
                            content_type="application/json")
    except:
        log.error(traceback.format_exc())