From 2583d574d278b6bb32f7a3de1c6c1e3bdd0e8869 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 13 Oct 2019 18:49:10 +0000 Subject: [PATCH] Use labels to identify the cloud-shell container Change-Id: Ic3dd0f949c3937f0e5b5d4f81aed7ca30ab271ff Closes-Bug: #1847227 --- .../cloud-shell/cloud-shell.controller.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/zun_ui/static/cloud-shell/cloud-shell.controller.js b/zun_ui/static/cloud-shell/cloud-shell.controller.js index 99bd2d7..5db74d0 100644 --- a/zun_ui/static/cloud-shell/cloud-shell.controller.js +++ b/zun_ui/static/cloud-shell/cloud-shell.controller.js @@ -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