Skip to content

Commit

Permalink
Merge branch 'master' into max
Browse files Browse the repository at this point in the history
  • Loading branch information
knguyen100000010 committed Mar 26, 2024
2 parents eafad54 + 37a187d commit 74b9ba7
Show file tree
Hide file tree
Showing 49 changed files with 1,064 additions and 819 deletions.
14 changes: 7 additions & 7 deletions deploy-board/deploy_board/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@
TELETRAAN_TRANSFER_OWNERSHIP_URL = os.getenv("TELETRAAN_TRANSFER_OWNERSHIP_URL", None)
TELETRAAN_RESOURCE_OWNERSHIP_WIKI_URL = os.getenv("TELETRAAN_RESOURCE_OWNERSHIP_WIKI_URL", None)
TELETRAAN_PROJECT_URL_FORMAT = os.getenv("TELETRAAN_PROJECT_URL_FORMAT", None)
RODIMUS_CLUSTER_REPLACEMENT_WIKI_URL = os.getenv("RODIMUS_CLUSTER_REPLACEMENT_WIKI_URL", None)
RODIMUS_AUTO_CLUSTER_REFRESH_WIKI_URL = os.getenv("RODIMUS_AUTO_CLUSTER_REFRESH_WIKI_URL", None)

# use Rodimus if present
RODIMUS_SERVICE_URL = os.getenv("RODIMUS_SERVICE_URL", None)
RODIMUS_SERVICE_VERSION = os.getenv("RODIMUS_SERVICE_VERSION", None)
RODIMUS_SERVICE_PROXY_HTTP = os.getenv("RODIMUS_SERVICE_PROXY_HTTP", None)
RODIMUS_SERVICE_PROXY_HTTPS = os.getenv("RODIMUS_SERVICE_PROXY_HTTPS", None)
RODIMUS_SERVICE_USE_BEARER = os.getenv("RODIMUS_SERVICE_USE_BEARER", "true").lower() != "false" # default is True
RODIMUS_SERVICE_URL = os.getenv("TELETRAAN_RODIMUS_SERVICE_URL", None)
RODIMUS_SERVICE_VERSION = os.getenv("TELETRAAN_RODIMUS_SERVICE_VERSION", None)
RODIMUS_SERVICE_PROXY_HTTP = os.getenv("TELETRAAN_RODIMUS_SERVICE_PROXY_HTTP", None)
RODIMUS_SERVICE_PROXY_HTTPS = os.getenv("TELETRAAN_RODIMUS_SERVICE_PROXY_HTTPS", None)
RODIMUS_SERVICE_USE_BEARER = os.getenv("TELETRAAN_RODIMUS_SERVICE_USE_BEARER", "true").lower() != "false" # default is True
RODIMUS_CLUSTER_REPLACEMENT_WIKI_URL = os.getenv("TELETRAAN_RODIMUS_CLUSTER_REPLACEMENT_WIKI_URL", None)
RODIMUS_AUTO_CLUSTER_REFRESH_WIKI_URL = os.getenv("TELETRAAN_RODIMUS_AUTO_CLUSTER_REFRESH_WIKI_URL", None)

if IS_PINTEREST:
# use knox if present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,21 @@ Vue.component('baseimage-select', {
warningText: '',
}
},
props: ['imageNames', 'baseImages', 'selectedImageName', 'selectedBaseImage', 'pinImage', 'pinImageEnabled'],
props: ['imageNames', 'baseImages', 'selectedImageName', 'selectedBaseImage', 'pinImage', 'pinImageEnabled', 'accountOwnerId'],
methods: {
helpClick: function () {
this.$emit('help-clicked')
},
tryShowWarning: function (baseImageId, pinImage) {
tryShowWarning: function (baseImageId, pinImage, accountOwnerId) {
if (!pinImage) {
this.showWarning = false;
} else {
const ONE_DAY = 1000 * 60 * 60 * 24;
let baseImage = this.baseImages.find(i => i.value == baseImageId);
let age = Math.round((Date.now() - new Date(baseImage.publishDate)) / ONE_DAY);
if (age > 180) {
this.warningText = `The base image configured is over 180 days old (${age} days). Please consider update or opt-in Auto Update (Unpin image).`;
this.showWarning = true;
} else {
this.showWarning = false;
}
const baseImage = this.baseImages.find(i => i.value === baseImageId);
const warnings = this.createWarningMessages(baseImage, accountOwnerId);
this.showWarning = warnings.length > 0;
this.warningText = '\n' + warnings.map(
(item, index) => `${index + 1}. ${item}`
).join('\n');
}
},
pinImageClick: function (pin) {
Expand All @@ -110,12 +107,44 @@ Vue.component('baseimage-select', {
} else {
this.showWarning = false;
}
},

createWarningMessages: function(baseImage, accountOwnerId) {
const messages = [];
const oneDay = 1000 * 60 * 60 * 24;
const imageCreationDate = new Date(baseImage.publishDate);
let age = Math.round((Date.now() - imageCreationDate) / oneDay);
if (age > 180) {
messages.push(
`The base image configured is over 180 days old (${age} days). ` +
"Please consider update or opt-in Auto Update (Unpin image)."
);
}

const sharedImagesCreationDate = new Date("2024-03-15");
const primaryAccount = '998131032990';
if (accountOwnerId && accountOwnerId !== primaryAccount
&& imageCreationDate < sharedImagesCreationDate) {
const options = { day: 'numeric', month: 'long', year: 'numeric' };
const formattedDate = sharedImagesCreationDate.toLocaleDateString('en-GB', options);
messages.push(
"The base image has configured in primary account and may not works in " +
`the sub account, please use base images after ${formattedDate} ` +
"for sub accounts.");
}
return messages;
}
},
watch: {
selectedBaseImage: function (baseImageId) {
this.tryShowWarning(baseImageId, this.pinImage);
this.tryShowWarning(baseImageId, this.pinImage, this.accountOwnerId);
},
accountOwnerId: function (newAccountOwnerId) {
this.tryShowWarning(this.selectedBaseImage, this.pinImage, newAccountOwnerId);
}
},
mounted() {
this.tryShowWarning(this.selectedBaseImage, this.pinImage, this.accountOwnerId);
}
});

Expand Down Expand Up @@ -189,14 +218,19 @@ Vue.component('aws-user-data', {
acc[entry.name] = entry.value;
return acc;
}, {});

// hide link for cmp_base profiles
if (userDataObj['pinfo_role'] === 'cmp_base') {
return ' ';
}
const hieraPaths = this.hierapaths.trim().split("\n").reduce(
(acc, line) => acc.set(line, [
...new Set(line.matchAll(/(?<=%{::)[a-z0-9_]+(?=})/gi).map(val => val[0]))
]),
new Map()
);

const matchingPuppetPath = hieraPaths.keys().find(line =>
const matchingPuppetPath = hieraPaths.keys().find(line =>
hieraPaths.get(line).every(variable => !!userDataObj[variable])
);
const variables = hieraPaths.get(matchingPuppetPath);
Expand Down
46 changes: 46 additions & 0 deletions deploy-board/deploy_board/templates/accounts/account_details.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends 'accounts/accounts_base.html' %}

{% block breadcrumb-items %}
<ul class="breadcrumb">
<li><a href="/">Home</a></li>
<li><a href="/clouds/accounts">Accounts</a></li>
<li class="active">{{ account.id }}</li>
</ul>
{% endblock %}

{% block main %}
<div class="panel panel-default">
<div class="panel-heading clearfix">
<h4 class="panel-title pull-left">Account Details</h4>
</div>
<div class="panel-body table-responsive">
<table class="table table-striped table-bordered table-condensed table-hover">
<tr>
<td>ID</td>
<td>{{ account.id }}</td>
</tr>
<tr>
<td>Owner ID <span class="deployToolTip glyphicon glyphicon-question-sign" data-toggle="tooltip" title="External ID used by cloud provider. For example, AWS account ID"></span></td>
<td>{{ account.data.ownerId }}</td>
</tr>
<tr>
<td>Name</td>
<td>{{ account.name }}</td>
</tr>
<tr>
<td>Cloud Provider</td>
<td>{{ account.cloudProvider }}</td>
</tr>
<tr>
<td>Cell</td>
<td>{{ account.cell }}</td>
</tr>
<tr>
<td>Description</td>
<td>{{ account.description }}</td>
</tr>
</table>
</div>
</div>

{% endblock %}
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/templates/accounts/accounts.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h4 class="panel-title pull-left">Account Details</h4>
<th class="col-lg-2">Name</th>
<th class="col-lg-2">Cell</th>
<th class="col-lg-2">Provider</th>
<th></th>
</tr>
</thead>
<tbody>
Expand All @@ -31,6 +32,7 @@ <h4 class="panel-title pull-left">Account Details</h4>
<td>{{ account.name }}</td>
<td>{{ account.cell }}</td>
<td>{{ account.cloudProvider }}</td>
<td><a href="/clouds/accounts/{{account.cloudProvider}}/{{account.cell}}/{{account.id}}">Details</a></td>
</tr>
{% endfor %}
</tbody>
Expand Down
99 changes: 74 additions & 25 deletions deploy-board/deploy_board/templates/configs/new_capacity_adv.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
<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>
<baseimage-select v-model="pinImage" :image-names="imageNames" :base-images="baseImages"
<baseimage-select v-model="pinImage" :image-names="imageNames" :base-images="baseImages" v-bind:account-owner-id="currentAccountOwnerId"
:selected-image-name="imageNameValue" :selected-base-image="baseImageValue" :pin-image-enabled="pinImageEnabled"
@base-image-change="baseImageChange" @image-name-change="imageNameChange" @help-clicked="baseImageHelpClick" >
</baseimage-select>
Expand Down Expand Up @@ -153,7 +153,8 @@ <h4 class="panel-title pull-left">Capacity</h4>
confirmDialogId: "createHostGroup",
currentProvider: info.defaultProvider,
currentAccountId: info.defaultAccountId,
currentCell: info.defaultCell,
currentAccountOwnerId: getAccountOwnerId(info.defaultAccountId),
currentCell: getDefaultCell(info.defaultAccountId),
currentArch: info.defaultArch,
hostTypeHelpData:[],
hostTypeOptions: info.hostTypes.map(
Expand All @@ -165,7 +166,6 @@ <h4 class="panel-title pull-left">Capacity</h4>
isDisabled: item.retired || item.blessed_status === "DECOMMISSIONING"
}
}),
cellValue: info.defaultCell,
archValue: info.defaultArch,
imageNameValue: info.defaultBaseImage,
imageNames: mapImageNameToOptions(info.baseImageNames),
Expand All @@ -186,14 +186,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
value: o, text: o
}
}),
cells: info.cells.map(
function (item) {
return {
value: item.name,
text: item.name,
isSelected: item.name == info.defaultCell
}
}),
cells: getUiCells(info.defaultAccountId),
arches: info.arches.map(
function (item) {
return {
Expand Down Expand Up @@ -308,11 +301,12 @@ <h4 class="panel-title pull-left">Capacity</h4>
}
},
accountChange: function (value) {
capacitySetting.currentAccountId = value;
this.currentAccountId = value;
this.currentAccountOwnerId = getAccountOwnerId(value);
this.cells = getUiCells(value);
this.cellChange(getDefaultCell(value));
},
cellChange: function(value) {
capacitySetting.currentCell = value;
capacitySetting.cellValue = value;
capacitySetting.currentCell = value;
// grab all the image names for this cell
var scope = this;
Expand All @@ -328,51 +322,59 @@ <h4 class="panel-title pull-left">Capacity</h4>
xhr.setRequestHeader("X-CSRFToken", csrftoken);
},
success: function (data) {
capacitySetting.imageNames = mapImageNameToOptions(data);
scope.imageNameChange(data[0]);
capacitySetting.imageNames = data ? mapImageNameToOptions(data) : [];
scope.imageNameChange(data && data.length > 0 ? data[0] : null);
},
error: function (data) {
globalNotificationBanner.error = data
}
});


const securityZonesUrl =
`${location.protocol}//${location.host}/clouds/securityzones/${provider}/${cell}` +
`?accountId=${this.currentAccountId}`
// grab all security zone for this cell
$.ajax({
type: 'GET',
url: location.protocol + '//' + location.host + '/clouds/securityzones/' + provider + '/' + cell,
url: securityZonesUrl,
dataType: "json",
beforeSend: function (xhr) {
var csrftoken = getCookie('csrftoken');
xhr.setRequestHeader("X-CSRFToken", csrftoken);
},
success: function (data) {
capacitySetting.securityZones = data.map(
capacitySetting.securityZones = data ? data.map(
function (item) {
return {
value: item.abstract_name,
text: item.abstract_name,
isSelected: item.id === data[0].id
}
});
capacitySetting.selectedSecurityZoneValue = data[0].abstract_name;
}) : [];
capacitySetting.selectedSecurityZoneValue = data && data.length > 0 ? data[0].abstract_name : null;
},
error: function (data) {
globalNotificationBanner.error = data
}
});

const placementsUrl =
`${location.protocol}//${location.host}/clouds/placements/${provider}/${cell}` +
`?accountId=${this.currentAccountId}`
// grab all placement for this cell
$.ajax({
type: 'GET',
url: location.protocol + '//' + location.host + '/clouds/placements/' + provider + '/' + cell,
url: placementsUrl,
dataType: "json",
beforeSend: function (xhr) {
var csrftoken = getCookie('csrftoken');
xhr.setRequestHeader("X-CSRFToken", csrftoken);
},
success: function (data) {
var placements = getDefaultPlacement({'placements': data});
var placements = data ? getDefaultPlacement({'placements': data}) : null;

capacitySetting.placements = placements.getFullList(false, null);
capacitySetting.placements = placements ? placements.getFullList(false, null) : null;
},
error: function (data) {
globalNotificationBanner.error = data
Expand Down Expand Up @@ -439,6 +441,13 @@ <h4 class="panel-title pull-left">Capacity</h4>
imageNameChange: function (value) {
var cell = capacitySetting.currentCell;
capacitySetting.imageNameValue = value;
if (!value) {
capacitySetting.baseImages = [];
capacitySetting.baseImageValue = null;
capacitySetting.pinImage = null;
capacitySetting.pinImageEnabled = false;
return;
}
//Grab all images for this image name
$.ajax({
type: 'GET',
Expand Down Expand Up @@ -648,7 +657,7 @@ <h4 class="panel-title pull-left">Capacity</h4>
},
updateStatefulStatus: function(value) {
this.selectedStatefulStatus = value
}
},
},
watch: {
placements: function(){
Expand All @@ -663,8 +672,48 @@ <h4 class="panel-title pull-left">Capacity</h4>
localStorage.setItem("accessRole", accessRoleObj.value);
}
}
})
});


function getUiCells(accountId) {
const account = getAccount(accountId);
if (account && account.cells) {
return account.cells
.map(uiCell);
}
return info.cells
.map(uiCell);
}

function getDefaultCell(accountId) {
const account = getAccount(accountId);

if (account && account.cells) {
if (!account.cells.some(cell => cell.name === info.defaultCell)) {
return account.cells[0].name;
}
}
return info.defaultCell;
}

function uiCell(item) {
return {
value: item.name,
text: item.name,
isSelected: item.name === info.defaultCell
};
}

function getAccount(accountId) {
return info.accounts != null ?
info.accounts.find(function (o) { return o.id === accountId })
: null;
}

function getAccountOwnerId(accountId) {
const account = getAccount(accountId);
return account ? account.ownerId : null;
}

$(document).ready(function () {
$('.single-select-search').chosen({
Expand Down
Loading

0 comments on commit 74b9ba7

Please sign in to comment.