Use labels to identify the cloud-shell container

Change-Id: Ic3dd0f949c3937f0e5b5d4f81aed7ca30ab271ff
Closes-Bug: #1847227
This commit is contained in:
Hongbin Lu 2019-10-13 18:49:10 +00:00
parent 899a0d78a2
commit 2583d574d2
1 changed files with 15 additions and 4 deletions

View File

@ -60,13 +60,25 @@
ctrl.region = cloudsYaml.match(/region_name: "(.+)"/)[1];
// container name
ctrl.container.name = "cloud-shell-" + ctrl.user + "-" + ctrl.project +
ctrl.containerLabel = "cloud-shell-" + ctrl.user + "-" + ctrl.project +
"-" + ctrl.domain + "-" + ctrl.region;
// get container
zun.getContainer(ctrl.container.name, true).then(onGetContainer, onFailGetContainer);
zun.getContainers().then(findContainer);
});
function findContainer(response) {
var container = response.data.items.find(function(item) {
return item.labels['cloud-shell'] === ctrl.containerLabel;
});
if (typeof (container) === 'undefined') {
onFailGetContainer();
} else {
onGetContainer({data: container});
}
}
function onGetContainer(response) {
ctrl.container = response.data;
@ -119,13 +131,12 @@
// create new container and attach console to it.
var image = angular.element("#cloud-shell-menu").attr("cloud-shell-image");
var model = {
name: ctrl.container.name,
image: image,
command: "/bin/bash",
interactive: true,
run: true,
environment: "OS_CLOUD=openstack",
labels: "cloud-shell=" + ctrl.container.name
labels: "cloud-shell=" + ctrl.containerLabel
};
zun.createContainer(model).then(function (response) {
// attach