From 164902c0cb76723bf607248a5ea4c104efb22963 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 10 Aug 2016 18:11:36 +1200 Subject: [PATCH] feat(ui): display swarm host IP instead of swarm hostname in containers view --- app/components/containers/containers.html | 2 +- .../containers/containersController.js | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/components/containers/containers.html b/app/components/containers/containers.html index 0a7ca115a..844d247ea 100644 --- a/app/components/containers/containers.html +++ b/app/components/containers/containers.html @@ -89,7 +89,7 @@ {{ container|swarmcontainername}} {{ container|containername}} {{ container.IP ? container.IP : '-' }} - {{ container|swarmhostname}} + {{ container.hostIP }} {{ container.Image }} {{ container.Command|truncate:60 }} diff --git a/app/components/containers/containersController.js b/app/components/containers/containersController.js index b7662e243..0db7b4dc8 100644 --- a/app/components/containers/containersController.js +++ b/app/components/containers/containersController.js @@ -1,6 +1,6 @@ angular.module('containers', []) -.controller('ContainersController', ['$scope', 'Container', 'Settings', 'Messages', 'Config', 'errorMsgFilter', -function ($scope, Container, Settings, Messages, Config, errorMsgFilter) { +.controller('ContainersController', ['$scope', 'Container', 'Info', 'Settings', 'Messages', 'Config', 'errorMsgFilter', +function ($scope, Container, Info, Settings, Messages, Config, errorMsgFilter) { $scope.state = {}; $scope.state.displayAll = Settings.displayAll; @@ -27,6 +27,9 @@ function ($scope, Container, Settings, Messages, Config, errorMsgFilter) { if (model.IP) { $scope.state.displayIP = true; } + if ($scope.swarm) { + model.hostIP = $scope.swarm_hosts[_.split(container.Names[0], '/')[1]]; + } return model; }); $('#loadContainersSpinner').hide(); @@ -154,10 +157,32 @@ function ($scope, Container, Settings, Messages, Config, errorMsgFilter) { }); }; + function retrieveSwarmHostsInfo(data) { + var swarm_hosts = {}; + var systemStatus = data.SystemStatus; + var node_count = parseInt(systemStatus[3][1], 10); + var node_offset = 4; + for (i = 0; i < node_count; i++) { + var host = {}; + host.name = _.trim(systemStatus[node_offset][0]); + host.ip = _.split(systemStatus[node_offset][1], ':')[0]; + swarm_hosts[host.name] = host.ip; + node_offset += 9; + } + return swarm_hosts; + } + $scope.swarm = false; Config.$promise.then(function (c) { hiddenLabels = c.hiddenLabels; $scope.swarm = c.swarm; - update({all: Settings.displayAll ? 1 : 0}); + if (c.swarm) { + Info.get({}, function (d) { + $scope.swarm_hosts = retrieveSwarmHostsInfo(d); + update({all: Settings.displayAll ? 1 : 0}); + }); + } else { + update({all: Settings.displayAll ? 1 : 0}); + } }); }]);