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")
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")
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())
def get_asg_config(request, group_name): asg = groups_helper.get_autoscaling(request, group_name) instances = groups_helper.get_group_instances(request, group_name) group_size = len(instances) policies = groups_helper.TerminationPolicy content = render_to_string("groups/asg_config.tmpl", { "group_name": group_name, "asg": asg, "group_size": group_size, "terminationPolicies": policies, "csrf_token": get_token(request), }) return HttpResponse(json.dumps(content), content_type="application/json")
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")
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())
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())
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())