Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed get placements and security zones by account id #1535

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion deploy-board/deploy_board/webapp/capacity_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
24 changes: 14 additions & 10 deletions deploy-board/deploy_board/webapp/cluster_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ 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, 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)

Expand Down Expand Up @@ -138,9 +138,9 @@ 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, 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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -504,12 +504,14 @@ 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")


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.get("accountId", None), provider, cell)
return HttpResponse(json.dumps(data), content_type="application/json")


Expand Down Expand Up @@ -770,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.get("accountId", None), provider, cell)
contents = render_to_string("clusters/get_security_zone.tmpl", {
'security_zones': security_zones,
'curr_security_zone': curr_security_zone,
Expand Down Expand Up @@ -824,7 +827,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,
Expand Down
4 changes: 3 additions & 1 deletion deploy-board/deploy_board/webapp/env_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
24 changes: 13 additions & 11 deletions deploy-board/deploy_board/webapp/group_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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 = []

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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']):
Expand Down Expand Up @@ -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)]

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading