From 9f248770ae11dfb153f204266c3a84fa72cf16c0 Mon Sep 17 00:00:00 2001 From: Vitalii Date: Tue, 19 Mar 2024 18:00:59 -0400 Subject: [PATCH 1/3] Fixed render pages for non-default placement id --- .../deploy_board/webapp/capacity_views.py | 4 +++- .../deploy_board/webapp/cluster_view.py | 14 ++++++----- deploy-board/deploy_board/webapp/env_views.py | 4 +++- .../deploy_board/webapp/group_view.py | 24 ++++++++++--------- .../webapp/helpers/placements_helper.py | 7 +++--- .../webapp/helpers/securityzones_helper.py | 3 +-- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/deploy-board/deploy_board/webapp/capacity_views.py b/deploy-board/deploy_board/webapp/capacity_views.py index 98e9688ded..d0e168627d 100644 --- a/deploy-board/deploy_board/webapp/capacity_views.py +++ b/deploy-board/deploy_board/webapp/capacity_views.py @@ -52,8 +52,10 @@ def get(self, request, name, stage): basic_cluster_info['asg_info'] = asg_cluster basic_cluster_info['base_image_info'] = base_image try: + account_id = basic_cluster_info.get('accountId') placements = placements_helper.get_simplified_by_ids( - request, basic_cluster_info['placement'], basic_cluster_info['provider'], basic_cluster_info['cellName']) + request, account_id, basic_cluster_info['placement'], + basic_cluster_info['provider'], basic_cluster_info['cellName']) except Exception as e: logger.warning('Failed to get placements: {}'.format(e)) diff --git a/deploy-board/deploy_board/webapp/cluster_view.py b/deploy-board/deploy_board/webapp/cluster_view.py index 4600b81af6..6430c5ea5c 100644 --- a/deploy-board/deploy_board/webapp/cluster_view.py +++ b/deploy-board/deploy_board/webapp/cluster_view.py @@ -52,7 +52,7 @@ def get(self, request, name, stage): security_zones = securityzones_helper.get_by_provider_and_cell_name( request, DEFAULT_PROVIDER, DEFAULT_CELL) placements = placements_helper.get_by_provider_and_cell_name( - request, DEFAULT_PROVIDER, DEFAULT_CELL) + request, None, DEFAULT_PROVIDER, DEFAULT_CELL) default_base_image = get_base_image_info_by_name(request, DEFAULT_CMP_IMAGE, DEFAULT_CELL) env = environs_helper.get_env_by_stage(request, name, stage) @@ -140,7 +140,7 @@ def get(self, request, name, stage): security_zones = securityzones_helper.get_by_provider_and_cell_name( request, DEFAULT_PROVIDER, DEFAULT_CELL) placements = placements_helper.get_by_provider_and_cell_name( - request, DEFAULT_PROVIDER, DEFAULT_CELL) + request, None, DEFAULT_PROVIDER, DEFAULT_CELL) cells = cells_helper.get_by_provider(request, DEFAULT_PROVIDER) arches = arches_helper.get_all(request) base_images = get_base_image_info_by_name(request, DEFAULT_CMP_IMAGE, DEFAULT_CELL) @@ -247,9 +247,9 @@ def get(self, request, name, stage): cells = cells_helper.get_by_provider(request, current_cluster['provider']) arches = arches_helper.get_all(request) security_zones = securityzones_helper.get_by_provider_and_cell_name( - request, current_cluster['provider'], current_cluster['cellName']) + request, current_cluster.get("accountId"), current_cluster['provider'], current_cluster['cellName']) placements = placements_helper.get_by_provider_and_cell_name( - request, current_cluster['provider'], current_cluster['cellName']) + request, current_cluster.get("accountId"), current_cluster['provider'], current_cluster['cellName']) base_images = get_base_image_info_by_name( request, current_image['abstract_name'], current_cluster['cellName']) base_images_names = baseimages_helper.get_image_names_by_arch( @@ -504,7 +504,8 @@ def get_images_by_provider_and_cell(request, provider, cell): def get_placements_by_provider_and_cell(request, provider, cell): - data = placements_helper.get_by_provider_and_cell_name(request, provider, cell) + account_id = request.GET.get("accountId", None) + data = placements_helper.get_by_provider_and_cell_name(request, account_id, provider, cell) return HttpResponse(json.dumps(data), content_type="application/json") @@ -824,7 +825,8 @@ def get_placements_by_provider(request): curr_placement = params['curr_placement'] curr_placement_arrays = curr_placement.split(',') - placements = placements_helper.get_by_provider_and_cell_name(request, provider, cell) + account_id = params.get("accountId", None) + placements = placements_helper.get_by_provider_and_cell_name(request, account_id, provider, cell) contents = render_to_string("clusters/get_placement.tmpl", { 'placements': placements, 'curr_placement_arrays': curr_placement_arrays, diff --git a/deploy-board/deploy_board/webapp/env_views.py b/deploy-board/deploy_board/webapp/env_views.py index affdc6cbef..0cad48d411 100644 --- a/deploy-board/deploy_board/webapp/env_views.py +++ b/deploy-board/deploy_board/webapp/env_views.py @@ -469,8 +469,10 @@ def get(self, request, name, stage=None): remaining_capacity = None if capacity_info['cluster']: add_account_from_cluster(request, basic_cluster_info, accounts) + account_id = basic_cluster_info.get("accountId") placements = placements_helper.get_simplified_by_ids( - request, basic_cluster_info['placement'], basic_cluster_info['provider'], basic_cluster_info['cellName']) + request, account_id, basic_cluster_info['placement'], + basic_cluster_info['provider'], basic_cluster_info['cellName']) remaining_capacity = functools.reduce(lambda s, e: s + e['capacity'], placements, 0) host_type = hosttypes_helper.get_by_id(request, basic_cluster_info['hostType']) host_type_blessed_status = host_type['blessed_status'] diff --git a/deploy-board/deploy_board/webapp/group_view.py b/deploy-board/deploy_board/webapp/group_view.py index b1f7b3e7c4..5bbf72de7e 100644 --- a/deploy-board/deploy_board/webapp/group_view.py +++ b/deploy-board/deploy_board/webapp/group_view.py @@ -341,8 +341,10 @@ def get_asg_config(request, group_name): try: basic_cluster_info = clusters_helper.get_cluster(request, group_name) if basic_cluster_info: + account_id = basic_cluster_info.get("accountId") placements = placements_helper.get_simplified_by_ids( - request, basic_cluster_info['placement'], basic_cluster_info['provider'], basic_cluster_info['cellName']) + request, account_id, basic_cluster_info['placement'], + basic_cluster_info['provider'], basic_cluster_info['cellName']) except Exception as e: log.warning('Failed to get placements: {}'.format(e)) content = render_to_string("groups/asg_config.tmpl", { @@ -459,7 +461,7 @@ def get_policy(request, group_name): policy["instanceWarmup"] = policy["instanceWarmup"] // 60 else: policy["instanceWarmup"] = 0 - + scale_up_steps = [] scale_down_steps = [] @@ -470,15 +472,15 @@ def get_policy(request, group_name): if step["metricIntervalLowerBound"] != None and float(step["metricIntervalLowerBound"]) >= 0: scale_up_steps.append({"lower_bound": float(step["metricIntervalLowerBound"]), "adjustment": step["scalingAdjustment"]}) - scale_down_steps = sorted(scale_down_steps, key=lambda d: d['upper_bound']) + scale_down_steps = sorted(scale_down_steps, key=lambda d: d['upper_bound']) scale_up_steps = sorted(scale_up_steps, key=lambda d: d['lower_bound']) - + scale_down_steps_string = ", ".join([str(step['upper_bound']) for step in scale_down_steps]) scale_up_steps_string = ", ".join([str(step['lower_bound']) for step in scale_up_steps]) scale_down_adjustments_string = ", ".join([str(step['adjustment']) for step in scale_down_steps]) scale_up_adjustments_string = ", ".join([str(step['adjustment']) for step in scale_up_steps]) - + step_scaling_policy["scale_down_steps_string"] = scale_down_steps_string step_scaling_policy["scale_up_steps_string"] = scale_up_steps_string step_scaling_policy["scale_down_adjustments_string"] = scale_down_adjustments_string @@ -541,7 +543,7 @@ def update_policy(request, group_name): for name in policy_names.values(): disable_scale_in = False if name + "_disableScaleIn" in input: - disable_scale_in = True + disable_scale_in = True policy = build_target_scaling_policy(name, input[name+"_awsMetrics"], input[name+"_target"], input[name+"_instanceWarmup"], disable_scale_in) scaling_policies["scalingPolicies"].append(policy) else: @@ -579,7 +581,7 @@ def update_policy(request, group_name): if params["scalingType"] == "PercentChangeInCapacity": step_scaling_policy["minAdjustmentMagnitude"] = params["minAdjustmentMagnitude"] - + step_scaling_policy["stepAdjustments"] = [] if (params['scaleUpSteps']): @@ -629,7 +631,7 @@ def _parse_metrics_configs(request, group_name): if key.startswith('TELETRAAN_'): alarm_info = {} alarm_info["scalingPolicies"] = [] - + alarm_id = key[len('TELETRAAN_'):] action_type = params["actionType_{}".format(alarm_id)] @@ -720,7 +722,7 @@ def get_alarms(request, group_name): "StatusCheckFailed_Instance", "StatusCheckFailed_System", "StatusCheckFailed_AttachedEBS" - ] + ] content = render_to_string("groups/asg_metrics.tmpl", { "group_name": group_name, "alarms": alarms, @@ -759,7 +761,7 @@ def add_alarms(request, group_name): policies = autoscaling_groups_helper.get_policies(request, group_name) - # Use simple scaling for custom metric + # Use simple scaling for custom metric if "customUrlCheckbox" in params: policy_type = "simple-scaling" @@ -1506,7 +1508,7 @@ def get_host_ami_dist(request, group_name): label_data_percentage = list(zip(labels, data, percentages)) any_host_with_outdated_ami = False - + if len(label_data_percentage) > 1 or (len(label_data_percentage) == 1 and label_data_percentage[0][0] != current_AMI): any_host_with_outdated_ami = True diff --git a/deploy-board/deploy_board/webapp/helpers/placements_helper.py b/deploy-board/deploy_board/webapp/helpers/placements_helper.py index 4fff764544..3a9e218ec9 100644 --- a/deploy-board/deploy_board/webapp/helpers/placements_helper.py +++ b/deploy-board/deploy_board/webapp/helpers/placements_helper.py @@ -28,8 +28,7 @@ def get_all(request, index, size): return rodimus_client.get("/placements", request.teletraan_user_id.token, params=params) -def get_by_provider_and_cell_name(request, provider, cell_name): - account_id = request.GET.get("accountId", None) +def get_by_provider_and_cell_name(request, account_id, provider, cell_name): query = f"?accountId={account_id}" if account_id is not None else "" if cell_name: return rodimus_client.get( @@ -44,8 +43,8 @@ def get_by_id(request, placement_id): return rodimus_client.get("/placements/%s" % placement_id, request.teletraan_user_id.token) -def get_simplified_by_ids(request, placement_str, provider, cell): +def get_simplified_by_ids(request, account_id, placement_str, provider, cell): current_placement_ids = set(placement_str.split(',')) - all_placements = get_by_provider_and_cell_name(request, provider, cell) + all_placements = get_by_provider_and_cell_name(request, account_id, provider, cell) return [{k: placement[k] for k in placement if k in ['id', 'capacity', 'abstract_name', 'provider_name']} for placement in all_placements if placement['id'] in current_placement_ids] diff --git a/deploy-board/deploy_board/webapp/helpers/securityzones_helper.py b/deploy-board/deploy_board/webapp/helpers/securityzones_helper.py index 1971ba1478..e4a6416a92 100644 --- a/deploy-board/deploy_board/webapp/helpers/securityzones_helper.py +++ b/deploy-board/deploy_board/webapp/helpers/securityzones_helper.py @@ -28,8 +28,7 @@ def get_all(request, index, size): return rodimus_client.get("/security_zones", request.teletraan_user_id.token, params=params) -def get_by_provider_and_cell_name(request, provider, cell_name): - account_id = request.GET.get("accountId", None) +def get_by_provider_and_cell_name(request, account_id, provider, cell_name): query = f"?accountId={account_id}" if account_id is not None else "" if cell_name: return rodimus_client.get( From 56b6af08043687cd7ec0f0dab2cf8408d94bd0ed Mon Sep 17 00:00:00 2001 From: Vitalii Date: Wed, 20 Mar 2024 12:24:20 -0400 Subject: [PATCH 2/3] Added passing accountId to get security zones --- deploy-board/deploy_board/webapp/cluster_view.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/deploy-board/deploy_board/webapp/cluster_view.py b/deploy-board/deploy_board/webapp/cluster_view.py index 6430c5ea5c..8e104a624b 100644 --- a/deploy-board/deploy_board/webapp/cluster_view.py +++ b/deploy-board/deploy_board/webapp/cluster_view.py @@ -50,7 +50,7 @@ def get(self, request, name, stage): host_type['mem'] = float(host_type['mem']) / 1024 security_zones = securityzones_helper.get_by_provider_and_cell_name( - request, DEFAULT_PROVIDER, DEFAULT_CELL) + request, None, DEFAULT_PROVIDER, DEFAULT_CELL) placements = placements_helper.get_by_provider_and_cell_name( request, None, DEFAULT_PROVIDER, DEFAULT_CELL) default_base_image = get_base_image_info_by_name(request, DEFAULT_CMP_IMAGE, DEFAULT_CELL) @@ -138,7 +138,7 @@ def get(self, request, name, stage): host_type['mem'] = float(host_type['mem']) / 1024 security_zones = securityzones_helper.get_by_provider_and_cell_name( - request, DEFAULT_PROVIDER, DEFAULT_CELL) + request, None, DEFAULT_PROVIDER, DEFAULT_CELL) placements = placements_helper.get_by_provider_and_cell_name( request, None, DEFAULT_PROVIDER, DEFAULT_CELL) cells = cells_helper.get_by_provider(request, DEFAULT_PROVIDER) @@ -510,7 +510,8 @@ def get_placements_by_provider_and_cell(request, provider, cell): def get_security_zones_by_provider_and_cell(request, provider, cell): - data = securityzones_helper.get_by_provider_and_cell_name(request, provider, cell) + data = securityzones_helper.get_by_provider_and_cell_name( + request, request.get("accountId", None), provider, cell) return HttpResponse(json.dumps(data), content_type="application/json") @@ -771,7 +772,8 @@ def get_security_zones_by_provider(request): curr_security_zone = params['curr_security_zone'] cell = params.get('cell', DEFAULT_CELL) - security_zones = securityzones_helper.get_by_provider_and_cell_name(request, provider, cell) + security_zones = securityzones_helper.get_by_provider_and_cell_name( + request, request.get("accountId", None), provider, cell) contents = render_to_string("clusters/get_security_zone.tmpl", { 'security_zones': security_zones, 'curr_security_zone': curr_security_zone, From 6c7a1488ae3802be09b9baf3f6ed451c0fda159e Mon Sep 17 00:00:00 2001 From: Vitalii Date: Wed, 20 Mar 2024 12:46:11 -0400 Subject: [PATCH 3/3] Fixed getting account from account id --- deploy-board/deploy_board/webapp/cluster_view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy-board/deploy_board/webapp/cluster_view.py b/deploy-board/deploy_board/webapp/cluster_view.py index 8e104a624b..695e2a5bca 100644 --- a/deploy-board/deploy_board/webapp/cluster_view.py +++ b/deploy-board/deploy_board/webapp/cluster_view.py @@ -511,7 +511,7 @@ def get_placements_by_provider_and_cell(request, provider, cell): def get_security_zones_by_provider_and_cell(request, provider, cell): data = securityzones_helper.get_by_provider_and_cell_name( - request, request.get("accountId", None), provider, cell) + request, request.GET.get("accountId", None), provider, cell) return HttpResponse(json.dumps(data), content_type="application/json") @@ -773,7 +773,7 @@ def get_security_zones_by_provider(request): cell = params.get('cell', DEFAULT_CELL) security_zones = securityzones_helper.get_by_provider_and_cell_name( - request, request.get("accountId", None), provider, cell) + request, request.GET.get("accountId", None), provider, cell) contents = render_to_string("clusters/get_security_zone.tmpl", { 'security_zones': security_zones, 'curr_security_zone': curr_security_zone,