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

Added dropdown with accounts for advanced cluster settings #1495

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ Vue.component('cloudprovider-select', {
}
});

Vue.component('accounts-select', {
template: '<div v-if="accounts">\
<label-select label="Account" title="Account" \
v-bind:value="value" \
v-bind:selectoptions="accounts" \
v-on:input="updateAccountValue"></label-select></div>',
props: ['accounts', 'value'],
methods: {
updateAccountValue: function (value) {
this.$emit('accountchange', value);
}
}
});

Vue.component('cell-select', {
template: '<div>\
<label-select label="Cell" title="Cell" \
Expand Down Expand Up @@ -545,4 +559,4 @@ Vue.component('stateful-help', {
<br />
</div>
</div>`
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
<form id="clusterConfigFormId" class="form-horizontal" role="form">
<fieldset id="clusterConfigFieldSetId">
<cloudprovider-select v-bind:cloudproviders="providers" v-bind:value="currentProvider"></cloudprovider-select>
<accounts-select v-bind:accounts="accounts" v-on:accountchange="accountChange" v-bind:value="currentAccountId"></accounts-select>
<cell-select v-bind:cells="cells" v-on:cellchange="cellChange" v-bind:value="currentCell"></cell-select>
<label-input label="Capacity" placeholder="# of instances" v-model="instanceCount"></label-input>
<arch-select v-bind:arches="arches" v-on:archchange="archChange" v-bind:value="archValue"></arch-select>
Expand Down Expand Up @@ -141,6 +142,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
confirmDialogTitle: "Confirm New Capacity Creation",
confirmDialogId: "createHostGroup",
currentProvider: info.defaultProvider,
currentAccountId: info.defaultAccountId,
currentCell: info.defaultCell,
currentArch: info.defaultArch,
hostTypeHelpData:[],
Expand All @@ -160,6 +162,14 @@ <h4 class="panel-title pull-left">Capacity</h4>
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 {
Expand Down Expand Up @@ -285,6 +295,9 @@ <h4 class="panel-title pull-left">Capacity</h4>
}, {cell: capacitySetting.currentCell})
}
},
accountChange: function (value) {
capacitySetting.currentAccountId = value;
},
cellChange: function(value) {
capacitySetting.currentCell = value;
capacitySetting.cellValue = value;
Expand Down Expand Up @@ -575,6 +588,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
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(',');
}
Expand Down
32 changes: 28 additions & 4 deletions deploy-board/deploy_board/webapp/cluster_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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', {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"]

Expand Down
15 changes: 15 additions & 0 deletions deploy-board/deploy_board/webapp/helpers/accounts_helper.py
Original file line number Diff line number Diff line change
@@ -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
Loading