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

Add OS info to LXD pods in pod list. #1061

Merged
merged 2 commits into from
Apr 30, 2020
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
37 changes: 31 additions & 6 deletions legacy/src/app/controllers/pods_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -171,6 +186,7 @@ function PodsListController(
// checked or not.
$scope.$watchCollection("pods", function() {
updateAllViewableChecked();
$scope.loadDetails();
});

// Sorts the table by predicate.
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down
50 changes: 50 additions & 0 deletions legacy/src/app/controllers/tests/test_pods_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
});
14 changes: 12 additions & 2 deletions legacy/src/app/partials/pods-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ <h3 class="p-heading-icon__title p-heading--four u-no-max-width u-sv3">You have
</div>
<div class="u-align--right">Owners</div>
</th>
<th class="p-table__cell" aria-label="Operating system" title="OS">
<div>OS</div>
</th>
<th class="p-table__cell" title="Resource pool">
<div>Resource pool</div>
<div>AZ</div>
Expand Down Expand Up @@ -303,8 +306,15 @@ <h3 class="p-heading-icon__title p-heading--four u-no-max-width u-sv3">You have
{$ pod.composed_machines_count $}
</div>
<div class="p-double-row__muted-row u-align--right">
<span ng-if="ownersMap.get(pod.id)">{$ ownersMap.get(pod.id).length $}</span>
<i class="p-icon--spinner u-animation--spin u-no-margin" ng-if="!ownersMap.get(pod.id)"></i>
<span ng-if="!loading">{$ ownersMap.get(pod.id).length $}</span>
<i class="p-icon--spinner u-animation--spin u-no-margin" ng-if="loading"></i>
</div>
</div>
</td>
<td class="p-table__cell p-double-row" aria-label="Operating system" title="OS">
<div class="p-double-row">
<div class="p-double-row__main-row">
<span class="u-text-overflow" title="{$ getPodOSName(pod) $}">{$ getPodOSName(pod) $}</span>
</div>
</div>
</td>
Expand Down
14 changes: 9 additions & 5 deletions legacy/src/scss/tables/_patterns_table-pods.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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%);
}
}
}
Expand Down