Merge lp:~blake-rouse/maas/fix-1503474 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 4467
Proposed branch: lp:~blake-rouse/maas/fix-1503474
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 224 lines (+163/-1)
3 files modified
src/maasserver/static/js/angular/controllers/node_details.js (+54/-1)
src/maasserver/static/js/angular/controllers/tests/test_node_details.js (+84/-0)
src/maasserver/static/partials/node-details.html (+25/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1503474
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+276722@code.launchpad.net

Commit message

Add the children devices on the node details page.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Codewise, this lgtm! I have not tested it though. just one quick question. This section will only show up when there are containers associated right?

review: Approve
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Oh, and for what I can see, we are showing device name, mac address, right? What about the IP address?

Revision history for this message
Blake Rouse (blake-rouse) wrote :

It only shows up when atleast one exists. Yes IP address is shown.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/static/js/angular/controllers/node_details.js'
2--- src/maasserver/static/js/angular/controllers/node_details.js 2015-11-02 03:34:34 +0000
3+++ src/maasserver/static/js/angular/controllers/node_details.js 2015-11-05 02:32:14 +0000
4@@ -38,7 +38,7 @@
5 skipStorage: false
6 };
7 $scope.checkingPower = false;
8-
9+ $scope.devices = [];
10
11 // Holds errors that are displayed on the details page.
12 $scope.errors = {
13@@ -361,6 +361,56 @@
14 }
15 }
16
17+ // Update the devices array on the scope based on the device children
18+ // on the node.
19+ function updateDevices() {
20+ $scope.devices = [];
21+ angular.forEach($scope.node.devices, function(child) {
22+ var device = {
23+ name: child.fqdn
24+ };
25+
26+ // Add the interfaces to the device object if any exists.
27+ if(angular.isArray(child.interfaces) &&
28+ child.interfaces.length > 0) {
29+ angular.forEach(child.interfaces, function(nic, nicIdx) {
30+ var deviceWithMAC = angular.copy(device);
31+ deviceWithMAC.mac_address = nic.mac_address;
32+
33+ // Remove device name so it is not duplicated in the
34+ // table since this is another MAC address on this
35+ // device.
36+ if(nicIdx > 0) {
37+ deviceWithMAC.name = "";
38+ }
39+
40+ // Add this links to the device object if any exists.
41+ if(angular.isArray(nic.links) &&
42+ nic.links.length > 0) {
43+ angular.forEach(nic.links, function(link, lIdx) {
44+ var deviceWithLink = angular.copy(
45+ deviceWithMAC);
46+ deviceWithLink.ip_address = link.ip_address;
47+
48+ // Remove the MAC address so it is not
49+ // duplicated in the table since this is
50+ // another link on this interface.
51+ if(lIdx > 0) {
52+ deviceWithLink.mac_address = "";
53+ }
54+
55+ $scope.devices.push(deviceWithLink);
56+ });
57+ } else {
58+ $scope.devices.push(deviceWithMAC);
59+ }
60+ });
61+ } else {
62+ $scope.devices.push(device);
63+ }
64+ });
65+ }
66+
67 // Starts the watchers on the scope.
68 function startWatching() {
69 // Update the title and name when the node fqdn changes.
70@@ -369,6 +419,9 @@
71 updateName();
72 });
73
74+ // Update the devices on the node.
75+ $scope.$watch("node.devices", updateDevices);
76+
77 // Update the availableActionOptions when the node actions change.
78 $scope.$watch("node.actions", updateAvailableActionOptions);
79
80
81=== modified file 'src/maasserver/static/js/angular/controllers/tests/test_node_details.js'
82--- src/maasserver/static/js/angular/controllers/tests/test_node_details.js 2015-11-02 03:34:34 +0000
83+++ src/maasserver/static/js/angular/controllers/tests/test_node_details.js 2015-11-05 02:32:14 +0000
84@@ -204,6 +204,8 @@
85 skipNetworking: false,
86 skipStorage: false
87 });
88+ expect($scope.checkingPower).toBe(false);
89+ expect($scope.devices).toEqual([]);
90 });
91
92 it("sets initial values for summary section", function() {
93@@ -625,6 +627,7 @@
94
95 expect(watches).toEqual([
96 "node.fqdn",
97+ "node.devices",
98 "node.actions",
99 "node.nodegroup.id",
100 "node.architecture",
101@@ -668,6 +671,87 @@
102 [["architectures"], ["hwe_kernels"], ["osinfo"]]);
103 });
104
105+ it("updates $scope.devices", function() {
106+ var setActiveDefer = $q.defer();
107+ spyOn(NodesManager, "setActiveItem").and.returnValue(
108+ setActiveDefer.promise);
109+ var defer = $q.defer();
110+ var controller = makeController(defer);
111+
112+ node.devices = [
113+ {
114+ fqdn: "device1.maas",
115+ interfaces: []
116+ },
117+ {
118+ fqdn: "device2.maas",
119+ interfaces: [
120+ {
121+ mac_address: "00:11:22:33:44:55",
122+ links: []
123+ }
124+ ]
125+ },
126+ {
127+ fqdn: "device3.maas",
128+ interfaces: [
129+ {
130+ mac_address: "00:11:22:33:44:66",
131+ links: []
132+ },
133+ {
134+ mac_address: "00:11:22:33:44:77",
135+ links: [
136+ {
137+ ip_address: "192.168.122.1"
138+ },
139+ {
140+ ip_address: "192.168.122.2"
141+ },
142+ {
143+ ip_address: "192.168.122.3"
144+ }
145+ ]
146+ }
147+ ]
148+ }
149+ ];
150+
151+ defer.resolve();
152+ $rootScope.$digest();
153+ setActiveDefer.resolve(node);
154+ $rootScope.$digest();
155+
156+ expect($scope.devices).toEqual([
157+ {
158+ name: "device1.maas"
159+ },
160+ {
161+ name: "device2.maas",
162+ mac_address: "00:11:22:33:44:55"
163+ },
164+ {
165+ name: "device3.maas",
166+ mac_address: "00:11:22:33:44:66"
167+ },
168+ {
169+ name: "",
170+ mac_address: "00:11:22:33:44:77",
171+ ip_address: "192.168.122.1"
172+ },
173+ {
174+ name: "",
175+ mac_address: "",
176+ ip_address: "192.168.122.2"
177+ },
178+ {
179+ name: "",
180+ mac_address: "",
181+ ip_address: "192.168.122.3"
182+ }
183+ ]);
184+ });
185+
186 describe("tagsAutocomplete", function() {
187
188 it("calls TagsManager.autocomplete with query", function() {
189
190=== modified file 'src/maasserver/static/partials/node-details.html'
191--- src/maasserver/static/partials/node-details.html 2015-11-04 19:22:30 +0000
192+++ src/maasserver/static/partials/node-details.html 2015-11-05 02:32:14 +0000
193@@ -272,6 +272,31 @@
194 </form>
195 </div>
196 </div>
197+ <div class="row" data-ng-show="devices.length">
198+ <div class="inner-wrapper">
199+ <div class="twelve-col">
200+ <h2 class="title">Containers and VMs</h2>
201+ </div>
202+ <div class="twelve-col">
203+ <div class="table">
204+ <header class="table__head">
205+ <div class="table__row">
206+ <div class="table__header table__column--30">Name</div>
207+ <div class="table__header table__column--30">MAC</div>
208+ <div class="table__header table__column--40">IP Address</div>
209+ </div>
210+ </header>
211+ <main class="table__body" data-selected-rows>
212+ <div class="table__row" data-ng-repeat="device in devices">
213+ <div class="table__data table__column--30">{$ device.name $}</div>
214+ <div class="table__data table__column--30">{$ device.mac_address $}</div>
215+ <div class="table__data table__column--40">{$ device.ip_address $}</div>
216+ </div>
217+ </main>
218+ </div>
219+ </div>
220+ </div>
221+ </div>
222 <div class="row ng-hide" data-ng-show="isSuperUser()">
223 <div class="inner-wrapper">
224 <form class="disabled">