Esempio n. 1
0
def gen_asg_setting(request, group_name):
     asg = autoscaling_groups_helper.get_autoscaling(request, group_name)
     policies = autoscaling_groups_helper.TerminationPolicy
     content = render_to_string("groups/create_asg_modal.tmpl", {
         "asg": asg,
         "group_name": group_name,
         "policies": policies,
         "csrf_token": get_token(request)})
     return HttpResponse(content)
Esempio n. 2
0
def gen_asg_setting(request, group_name):
     asg = autoscaling_groups_helper.get_autoscaling(request, group_name)
     policies = autoscaling_groups_helper.TerminationPolicy
     content = render_to_string("groups/create_asg_modal.tmpl", {
         "asg": asg,
         "group_name": group_name,
         "policies": policies,
         "csrf_token": get_token(request)})
     return HttpResponse(content)
Esempio n. 3
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. 4
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())