diff --git a/deploy-board/deploy_board/static/js/components/clusterconfigcomponents.js b/deploy-board/deploy_board/static/js/components/clusterconfigcomponents.js index 7ec34b76ba..0c2a4687fa 100644 --- a/deploy-board/deploy_board/static/js/components/clusterconfigcomponents.js +++ b/deploy-board/deploy_board/static/js/components/clusterconfigcomponents.js @@ -10,6 +10,20 @@ Vue.component('cloudprovider-select', { } }); +Vue.component('accounts-select', { + template: '
\ +
', + props: ['accounts', 'value'], + methods: { + updateAccountValue: function (value) { + this.$emit('accountchange', value); + } + } +}); + Vue.component('cell-select', { template: '
\
` -}); \ No newline at end of file +}); diff --git a/deploy-board/deploy_board/templates/configs/new_capacity_adv.html b/deploy-board/deploy_board/templates/configs/new_capacity_adv.html index e3d720a646..617940ac14 100644 --- a/deploy-board/deploy_board/templates/configs/new_capacity_adv.html +++ b/deploy-board/deploy_board/templates/configs/new_capacity_adv.html @@ -46,6 +46,7 @@

Capacity

+ @@ -141,6 +142,7 @@

Capacity

confirmDialogTitle: "Confirm New Capacity Creation", confirmDialogId: "createHostGroup", currentProvider: info.defaultProvider, + currentAccountId: info.defaultAccountId, currentCell: info.defaultCell, currentArch: info.defaultArch, hostTypeHelpData:[], @@ -160,6 +162,14 @@

Capacity

instanceCount: "", placements: placements.getFullList(false, null), placementsHelpData: [], + accounts: info.accounts != null ? info.accounts.map( + function (o) { + return { + value: o.id, + text: o.ownerId + " / " + o.name + " / " + o.description, + isSelected: o.id === info.defaultAccountId, + } + }) : null, providers: info.providerList.map( function (o) { return { @@ -285,6 +295,9 @@

Capacity

}, {cell: capacitySetting.currentCell}) } }, + accountChange: function (value) { + capacitySetting.currentAccountId = value; + }, cellChange: function(value) { capacitySetting.currentCell = value; capacitySetting.cellValue = value; @@ -575,6 +588,7 @@

Capacity

clusterInfo['securityZone'] = this.selectedSecurityZoneValue; clusterInfo['replacementTimeout'] = this.replacementTimeout; clusterInfo['statefulStatus'] = this.selectedStatefulStatus; + clusterInfo['accountId'] = this.currentAccountId; if (this.selectedPlacements != null && this.selectedPlacements.length>0){ clusterInfo['placement'] = this.selectedPlacements.join(','); } diff --git a/deploy-board/deploy_board/webapp/cluster_view.py b/deploy-board/deploy_board/webapp/cluster_view.py index e8416f25d6..e4b5b65c6c 100644 --- a/deploy-board/deploy_board/webapp/cluster_view.py +++ b/deploy-board/deploy_board/webapp/cluster_view.py @@ -31,7 +31,7 @@ import logging from .helpers import baseimages_helper, hosttypes_helper, securityzones_helper, placements_helper, \ - autoscaling_groups_helper, groups_helper, cells_helper, arches_helper + autoscaling_groups_helper, groups_helper, cells_helper, arches_helper, accounts_helper from .helpers import clusters_helper, environs_helper, environ_hosts_helper, baseimages_helper from .helpers.exceptions import NotAuthorizedException, TeletraanException, IllegalArgumentException from . import common @@ -147,6 +147,9 @@ def get(self, request, name, stage): base_images_names = baseimages_helper.get_image_names_by_arch( request, DEFAULT_PROVIDER, DEFAULT_CELL, DEFAULT_ARCH) + accounts = accounts_helper.get_all_accounts(request) + default_account = get_default_account(accounts) + env = environs_helper.get_env_by_stage(request, name, stage) provider_list = baseimages_helper.get_all_providers(request) @@ -173,7 +176,9 @@ def get(self, request, name, stage): 'configList': get_aws_config_name_list_by_image(DEFAULT_CMP_IMAGE), 'enable_ami_auto_update': ENABLE_AMI_AUTO_UPDATE, 'stateful_status': clusters_helper.StatefulStatuses.get_status(None), - 'stateful_options': clusters_helper.StatefulStatuses.get_all_statuses() + 'stateful_options': clusters_helper.StatefulStatuses.get_all_statuses(), + 'accounts': list(map(create_ui_account, accounts)) if accounts is not None else None, + 'defaultAccountId': default_account['id'] if default_account is not None else None, } # cluster manager return render(request, 'configs/new_capacity_adv.html', { @@ -567,6 +572,25 @@ def get_base_image_info_by_name(request, name, cell): return baseimages_helper.get_by_name(request, name, cell) +def create_ui_account(account): + if account is None: + return None + return { + 'id': account['id'], + 'name': account['name'], + 'description': account['description'], + 'ownerId': account['data']['ownerId'], + } + + +def get_default_account(accounts): + if accounts is None: + return None + for account in accounts: + if account['name'] == 'default': + return account + return None + def get_base_images_by_name_json(request, name): cell = DEFAULT_CELL params = request.GET @@ -1107,7 +1131,7 @@ def sanitize_slack_email_input(input): res = '' if input == None or len(input) == 0: return res - + tokens = input.strip().split(',') for e in tokens: e = e.strip() @@ -1176,7 +1200,7 @@ def submit_auto_refresh_config(request, name, stage): auto_refresh_config["bakeTime"] = params["bakeTime"] auto_refresh_config["config"] = rollingUpdateConfig auto_refresh_config["type"] = "LATEST" - + emails = params["emails"] slack_channels = params["slack_channels"] diff --git a/deploy-board/deploy_board/webapp/helpers/accounts_helper.py b/deploy-board/deploy_board/webapp/helpers/accounts_helper.py new file mode 100644 index 0000000000..16f55b3a4c --- /dev/null +++ b/deploy-board/deploy_board/webapp/helpers/accounts_helper.py @@ -0,0 +1,15 @@ +from deploy_board.webapp.helpers.rodimus_client import RodimusClient +import logging + +log = logging.getLogger(__name__) + +rodimus_client = RodimusClient() + + +def get_all_accounts(request): + try: + return rodimus_client.get("/accounts", request.teletraan_user_id.token, {"provider": "AWS"}) + except Exception as e: + log.error(f"Can't get all accounts: error = {e}") + # return None for backward-compatibility + return None