From 2e6f9e32c897d6ca5a25149e7b93775bfb128ee0 Mon Sep 17 00:00:00 2001 From: Caleb Ellis Date: Thu, 30 Apr 2020 15:07:32 +1000 Subject: [PATCH] Add OS info to LXD pods in pod list. (#1061) * Add OS info to LXD pods in pod list. * Move OS short name generator to separate function --- legacy/src/app/controllers/pods_list.js | 37 +++++++++++--- .../app/controllers/tests/test_pods_list.js | 50 +++++++++++++++++++ legacy/src/app/partials/pods-list.html | 14 +++++- .../src/scss/tables/_patterns_table-pods.scss | 14 ++++-- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/legacy/src/app/controllers/pods_list.js b/legacy/src/app/controllers/pods_list.js index b61bccecc9..0c1b4b8f6e 100644 --- a/legacy/src/app/controllers/pods_list.js +++ b/legacy/src/app/controllers/pods_list.js @@ -4,6 +4,20 @@ * MAAS Pods List Controller */ +const getOSShortName = (node, osInfo) => { + if (node) { + const baseString = `${node.osystem}/${node.distro_series}`; + const releaseArr = osInfo.releases.find( + (release) => release[0] === baseString + ); + if (releaseArr && node.osystem === "ubuntu") { + return releaseArr[1].split('"')[0].trim(); // Remove "Adjective Animal" + } + return (releaseArr && releaseArr[1]) || baseString; + } + return "Unknown"; +}; + /* @ngInject */ function PodsListController( $scope, @@ -67,6 +81,7 @@ function PodsListController( memory_over_commit_ratio: 1 } }; + $scope.osInfo = GeneralManager.getData("osinfo"); $scope.powerTypes = GeneralManager.getData("power_types"); $scope.zones = ZonesManager.getItems(); $scope.pools = ResourcePoolsManager.getItems(); @@ -171,6 +186,7 @@ function PodsListController( // checked or not. $scope.$watchCollection("pods", function() { updateAllViewableChecked(); + $scope.loadDetails(); }); // Sorts the table by predicate. @@ -420,8 +436,13 @@ function PodsListController( ) { return; } + const item = items.find(item => item.id === itemId); + return item && item.name; + }; - return items.find(item => item.id === itemId).name; + $scope.getPodOSName = (pod) => { + const podHost = $scope.hostMap.get(pod.id); + return getOSShortName(podHost, $scope.osInfo); }; $scope.getPowerIconClass = (pod) => { @@ -482,6 +503,14 @@ function PodsListController( } }; + $scope.loadDetails = () => { + $scope.pods.forEach((pod) => { + $scope.defaultPoolMap.set(pod.id, $scope.getDefaultPoolData(pod)) + $scope.hostMap.set(pod.id, $scope.getPodHost(pod)); + $scope.ownersMap.set(pod.id, $scope.getPodOwners(pod)); + }); + }; + // Load the required managers for this controller. ManagerHelperService.loadManagers($scope, [ PodsManager, @@ -504,11 +533,7 @@ function PodsListController( $scope.addPod(); } - $scope.pods.forEach((pod) => { - $scope.defaultPoolMap.set(pod.id, $scope.getDefaultPoolData(pod)) - $scope.hostMap.set(pod.id, $scope.getPodHost(pod)); - $scope.ownersMap.set(pod.id, $scope.getPodOwners(pod)); - }); + $scope.loadDetails(); $scope.loading = false; diff --git a/legacy/src/app/controllers/tests/test_pods_list.js b/legacy/src/app/controllers/tests/test_pods_list.js index 95d65077dc..11d8603be2 100644 --- a/legacy/src/app/controllers/tests/test_pods_list.js +++ b/legacy/src/app/controllers/tests/test_pods_list.js @@ -815,4 +815,54 @@ describe("PodsListController", function() { expect($scope.getPodHost(pod)).toEqual(hostController); }); }); + + describe("getPodOSName", () => { + it("returns host's OS info", () => { + makeController(); + const pod = { id: 1, host: "abc" }; + $scope.hostMap.set(1, { + system_id: "abc", + distro_series: "centos70", + osystem: "centos", + }); + $scope.osInfo = { + releases: [["centos/centos70", "CentOS 7"]], + }; + expect($scope.getPodOSName(pod)).toEqual("CentOS 7"); + }); + + it("returns trimmed host OS info if OS is ubuntu", () => { + makeController(); + const pod = { id: 1, host: "abc" }; + $scope.hostMap.set(1, { + system_id: "abc", + distro_series: "bionic", + osystem: "ubuntu", + }); + $scope.osInfo = { + releases: [["ubuntu/bionic", 'Ubuntu 18.04 LTS "Bionic Beaver"']], + }; + expect($scope.getPodOSName(pod)).toEqual("Ubuntu 18.04 LTS"); + }); + + it("returns unformatted OS info if MAAS does not know about the release", () => { + makeController(); + const pod = { id: 1, host: "abc" }; + $scope.hostMap.set(1, { + system_id: "abc", + distro_series: "focal", + osystem: "ubuntu", + }); + $scope.osInfo = { + releases: [["ubuntu/bionic", 'Ubuntu 18.04 LTS "Bionic Beaver"']], + }; + expect($scope.getPodOSName(pod)).toEqual("ubuntu/focal"); + }); + + it("returns unknown if the pod does not have a host", () => { + makeController(); + const pod = { id: 1, host: undefined }; + expect($scope.getPodOSName(pod)).toEqual("Unknown"); + }); + }); }); diff --git a/legacy/src/app/partials/pods-list.html b/legacy/src/app/partials/pods-list.html index d9090995ef..b1feded7c7 100644 --- a/legacy/src/app/partials/pods-list.html +++ b/legacy/src/app/partials/pods-list.html @@ -231,6 +231,9 @@

You have
Owners
+ +
OS
+
Resource pool
AZ
@@ -303,8 +306,15 @@

You have {$ pod.composed_machines_count $}
- {$ ownersMap.get(pod.id).length $} - + {$ ownersMap.get(pod.id).length $} + +
+ + + +
+
+ {$ getPodOSName(pod) $}
diff --git a/legacy/src/scss/tables/_patterns_table-pods.scss b/legacy/src/scss/tables/_patterns_table-pods.scss index 2cc56e4371..ca9b4fc188 100644 --- a/legacy/src/scss/tables/_patterns_table-pods.scss +++ b/legacy/src/scss/tables/_patterns_table-pods.scss @@ -3,7 +3,7 @@ .p-table__row { .p-table__cell { &:nth-of-type(1) { - @include breakpoint-widths(60%, 35%, 25%, 20%); + @include breakpoint-widths(60%, 35%, 20%, 16%); } &:nth-of-type(2) { @@ -15,7 +15,7 @@ } &:nth-of-type(4) { - @include breakpoint-widths(0, 0, 15%, 8%); + @include breakpoint-widths(0, 0, 0%, 7%); padding-right: $sph-inner; } @@ -24,15 +24,19 @@ } &:nth-of-type(6) { - @include breakpoint-widths(0, 0, 0, 12%); + @include breakpoint-widths(0, 0, 20%, 11%); } &:nth-of-type(7) { - @include breakpoint-widths(0, 0, 0, 12%); + @include breakpoint-widths(0, 0, 0, 10%); } &:nth-of-type(8) { - @include breakpoint-widths(0, 0, 0, 12%); + @include breakpoint-widths(0, 0, 0, 10%); + } + + &:nth-of-type(9) { + @include breakpoint-widths(0, 0, 0, 10%); } } }