This file is indexed.

/usr/share/maas/web/static/js/angular/controllers/nodes_list.js is in maas-region-api 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
/* Copyright 2015-2018 Canonical Ltd.  This software is licensed under the
 * GNU Affero General Public License version 3 (see the file LICENSE).
 *
 * MAAS Nodes List Controller
 */

angular.module('MAAS').controller('NodesListController', [
    '$scope', '$interval', '$rootScope', '$routeParams', '$location',
    'MachinesManager', 'DevicesManager', 'ControllersManager',
    'GeneralManager', 'ManagerHelperService', 'SearchService',
    'ZonesManager', 'UsersManager', 'ServicesManager', 'ScriptsManager',
    'SwitchesManager',
    function($scope, $interval, $rootScope, $routeParams, $location,
        MachinesManager, DevicesManager, ControllersManager, GeneralManager,
        ManagerHelperService, SearchService, ZonesManager, UsersManager,
        ServicesManager, ScriptsManager, SwitchesManager) {

        // Mapping of device.ip_assignment to viewable text.
        var DEVICE_IP_ASSIGNMENT = {
            external: "External",
            dynamic: "Dynamic",
            "static": "Static"
        };

        // Set title and page.
        $rootScope.title = "Machines";
        $rootScope.page = "machines";

        // Set initial values.
        $scope.MAAS_config = MAAS_config;
        $scope.machines = MachinesManager.getItems();
        $scope.zones = ZonesManager.getItems();
        $scope.devices = DevicesManager.getItems();
        $scope.controllers = ControllersManager.getItems();
        $scope.switches = SwitchesManager.getItems();
        $scope.showswitches = $routeParams.switches === 'on';
        $scope.currentpage = "machines";
        $scope.osinfo = {};
        $scope.scripts = ScriptsManager.getItems();
        $scope.loading = true;

        $scope.tabs = {};
        // Machines tab.
        $scope.tabs.machines = {};
        $scope.tabs.machines.pagetitle = "Machines";
        $scope.tabs.machines.currentpage = "machines";
        $scope.tabs.machines.manager = MachinesManager;
        $scope.tabs.machines.previous_search = "";
        $scope.tabs.machines.search = "";
        $scope.tabs.machines.searchValid = true;
        $scope.tabs.machines.selectedItems = MachinesManager.getSelectedItems();
        $scope.tabs.machines.metadata = MachinesManager.getMetadata();
        $scope.tabs.machines.filters = SearchService.getEmptyFilter();
        $scope.tabs.machines.actionOption = null;
        $scope.tabs.machines.takeActionOptions = [];
        $scope.tabs.machines.actionErrorCount = 0;
        $scope.tabs.machines.actionProgress = {
            total: 0,
            completed: 0,
            errors: {},
            showing_confirmation: false,
            affected_nodes: 0
        };
        $scope.tabs.machines.osSelection = {
            osystem: null,
            release: null,
            hwe_kernel: null
        };
        $scope.tabs.machines.zoneSelection = null;
        $scope.tabs.machines.commissionOptions = {
            enableSSH: false,
            skipNetworking: false,
            skipStorage: false,
            updateFirmware: false,
            configureHBA: false
        };
        $scope.tabs.machines.releaseOptions = {};
        $scope.tabs.machines.commissioningSelection = [];
        $scope.tabs.machines.testSelection = [];

        // Device tab.
        $scope.tabs.devices = {};
        $scope.tabs.devices.pagetitle = "Devices";
        $scope.tabs.devices.currentpage = "devices";
        $scope.tabs.devices.manager = DevicesManager;
        $scope.tabs.devices.previous_search = "";
        $scope.tabs.devices.search = "";
        $scope.tabs.devices.searchValid = true;
        $scope.tabs.devices.selectedItems = DevicesManager.getSelectedItems();
        $scope.tabs.devices.filtered_items = [];
        $scope.tabs.devices.predicate = 'fqdn';
        $scope.tabs.devices.allViewableChecked = false;
        $scope.tabs.devices.metadata = DevicesManager.getMetadata();
        $scope.tabs.devices.filters = SearchService.getEmptyFilter();
        $scope.tabs.devices.column = 'fqdn';
        $scope.tabs.devices.actionOption = null;
        $scope.tabs.devices.takeActionOptions = [];
        $scope.tabs.devices.actionErrorCount = 0;
        $scope.tabs.devices.actionProgress = {
            total: 0,
            completed: 0,
            errors: {},
            showing_confirmation: false,
            affected_nodes: 0
        };
        $scope.tabs.devices.zoneSelection = null;

        // Controller tab.
        $scope.tabs.controllers = {};
        $scope.tabs.controllers.pagetitle = "Controllers";
        $scope.tabs.controllers.currentpage = "controllers";
        $scope.tabs.controllers.manager = ControllersManager;
        $scope.tabs.controllers.previous_search = "";
        $scope.tabs.controllers.search = "";
        $scope.tabs.controllers.searchValid = true;
        $scope.tabs.controllers.selectedItems =
            ControllersManager.getSelectedItems();
        $scope.tabs.controllers.filtered_items = [];
        $scope.tabs.controllers.predicate = 'fqdn';
        $scope.tabs.controllers.allViewableChecked = false;
        $scope.tabs.controllers.metadata = ControllersManager.getMetadata();
        $scope.tabs.controllers.filters = SearchService.getEmptyFilter();
        $scope.tabs.controllers.column = 'fqdn';
        $scope.tabs.controllers.actionOption = null;
        // Rack controllers contain all options
        $scope.tabs.controllers.takeActionOptions = [];
        $scope.tabs.controllers.actionErrorCount = 0;
        $scope.tabs.controllers.actionProgress = {
            total: 0,
            completed: 0,
            errors: {},
            showing_confirmation: false,
            affected_nodes: 0
        };
        $scope.tabs.controllers.zoneSelection = null;
        $scope.tabs.controllers.syncStatuses = {};
        $scope.tabs.controllers.addController = false;
        $scope.tabs.controllers.registerUrl = MAAS_config.register_url;
        $scope.tabs.controllers.registerSecret = MAAS_config.register_secret;

        // Switch tab.
        $scope.tabs.switches = {};
        $scope.tabs.switches.pagetitle = "Switches";
        $scope.tabs.switches.currentpage = "switches";
        $scope.tabs.switches.manager = SwitchesManager;
        $scope.tabs.switches.previous_search = "";
        $scope.tabs.switches.search = "";
        $scope.tabs.switches.searchValid = true;
        $scope.tabs.switches.selectedItems = SwitchesManager.getSelectedItems();
        $scope.tabs.switches.predicate = 'fqdn';
        $scope.tabs.switches.allViewableChecked = false;
        $scope.tabs.switches.metadata = SwitchesManager.getMetadata();
        $scope.tabs.switches.filters = SearchService.getEmptyFilter();
        $scope.tabs.switches.column = 'fqdn';
        $scope.tabs.switches.actionOption = null;
        $scope.tabs.switches.takeActionOptions = [];
        $scope.tabs.switches.actionErrorCount = 0;
        $scope.tabs.switches.actionProgress = {
            total: 0,
            completed: 0,
            errors: {},
            showing_confirmation: false,
            affected_nodes: 0
        };
        $scope.tabs.switches.osSelection = {
            osystem: null,
            release: null,
            hwe_kernel: null
        };
        $scope.tabs.switches.zoneSelection = null;
        $scope.tabs.switches.commissioningSelection = [];
        $scope.tabs.switches.commissionOptions = {
            enableSSH: false,
            skipNetworking: false,
            skipStorage: false,
            updateFirmware: false,
            configureHBA: false
        };
        $scope.tabs.switches.releaseOptions = {};


        // Options for add hardware dropdown.
        $scope.addHardwareOption = null;
        $scope.addHardwareOptions = [
            {
                name: "machine",
                title: "Machine"
            },
            {
                name: "chassis",
                title: "Chassis"
            }
        ];

        // This will hold the AddHardwareController once it is initialized.
        // The controller will set this variable as it's always a child of
        // this scope.
        $scope.addHardwareScope = null;

        // This will hold the AddDeviceController once it is initialized.
        // The controller will set this variable as it's always a child of
        // this scope.
        $scope.addDeviceScope = null;

        // When the addHardwareScope is hidden it will emit this event. We
        // clear the call to action button, so it can be used again.
        $scope.$on("addHardwareHidden", function() {
            $scope.addHardwareOption = null;
        });

        // Return true if the tab is in viewing selected mode.
        function isViewingSelected(tab) {
            var search = $scope.tabs[tab].search.toLowerCase();
            return search === "in:(selected)" || search === "in:selected";
        }

        // Sets the search bar to only show selected.
        function enterViewSelected(tab) {
            $scope.tabs[tab].previous_search = $scope.tabs[tab].search;
            $scope.tabs[tab].search = "in:(Selected)";
        }

        // Clear search bar from viewing selected.
        function leaveViewSelected(tab) {
            if(isViewingSelected(tab)) {
                $scope.tabs[tab].search = $scope.tabs[tab].previous_search;
                $scope.updateFilters(tab);
            }
        }

        // Called to update `allViewableChecked`.
        function updateAllViewableChecked(tab) {
            // Not checked when the filtered nodes are empty.
            if($scope.tabs[tab].filtered_items.length === 0) {
                $scope.tabs[tab].allViewableChecked = false;
                return;
            }

            // Loop through all filtered nodes and see if all are checked.
            var i;
            for(i = 0; i < $scope.tabs[tab].filtered_items.length; i++) {
                if(!$scope.tabs[tab].filtered_items[i].$selected) {
                    $scope.tabs[tab].allViewableChecked = false;
                    return;
                }
            }
            $scope.tabs[tab].allViewableChecked = true;
        }

        function clearAction(tab) {
            resetActionProgress(tab);
            leaveViewSelected(tab);
            $scope.tabs[tab].actionOption = null;
            $scope.tabs[tab].zoneSelection = null;
            if(tab === "machines" || tab === "switches") {
                // Possible for this to be called before the osSelect
                // direction is initialized. In that case it has not
                // created the $reset function on the model object.
                if(angular.isFunction(
                    $scope.tabs[tab].osSelection.$reset)) {
                    $scope.tabs[tab].osSelection.$reset();
                }
                $scope.tabs[tab].commissionOptions.enableSSH = false;
                $scope.tabs[tab].commissionOptions.skipNetworking = false;
                $scope.tabs[tab].commissionOptions.skipStorage = false;
                $scope.tabs[tab].commissionOptions.updateFirmware = false;
                $scope.tabs[tab].commissionOptions.configureHBA = false;
            }
            $scope.tabs[tab].commissioningSelection = [];
            $scope.tabs[tab].testSelection = [];
        }

        // Clear the action if required.
        function shouldClearAction(tab) {
            if($scope.tabs[tab].selectedItems.length === 0) {
                clearAction(tab);
            }
            if($scope.tabs[tab].actionOption && !isViewingSelected(tab)) {
                $scope.tabs[tab].actionOption = null;
            }
        }

        // Called when the filtered_items are updated. Checks if the
        // filtered_items are empty and if the search still matches the
        // previous search. This will reset the search when no nodes match
        // the current filter.
        function removeEmptyFilter(tab) {
            if($scope.tabs[tab].filtered_items.length === 0 &&
                $scope.tabs[tab].search !== "" &&
                $scope.tabs[tab].search === $scope.tabs[tab].previous_search) {
                $scope.tabs[tab].search = "";
                $scope.updateFilters(tab);
            }
        }

        // Update the number of selected items which have an error based on the
        // current selected action.
        function updateActionErrorCount(tab) {
            var i;
            $scope.tabs[tab].actionErrorCount = 0;
            for(i = 0; i < $scope.tabs[tab].selectedItems.length; i++) {
                var supported = $scope.supportsAction(
                    $scope.tabs[tab].selectedItems[i], tab);
                if(!supported) {
                    $scope.tabs[tab].actionErrorCount += 1;
                }
                $scope.tabs[tab].selectedItems[i].action_failed = false;
            }
        }

        // Reset actionProgress on tab to zero.
        function resetActionProgress(tab) {
            var progress = $scope.tabs[tab].actionProgress;
            progress.completed = progress.total = 0;
            progress.errors = {};
            progress.showing_confirmation = false;
            progress.affected_nodes = 0;
        }

        // Add error to action progress and group error messages by nodes.
        function addErrorToActionProgress(tab, error, node) {
            var progress = $scope.tabs[tab].actionProgress;
            progress.completed += 1;
            var nodes = progress.errors[error];
            if(angular.isUndefined(nodes)) {
                progress.errors[error] = [node];
            } else {
                nodes.push(node);
            }
        }

        // After an action has been performed check if we can leave all nodes
        // selected or if an error occured and we should only show the failed
        // nodes.
        function updateSelectedItems(tab) {
            if(!$scope.hasActionsFailed(tab)) {
                if(!$scope.hasActionsInProgress(tab)) {
                     clearAction(tab);
                     enterViewSelected(tab);
                }
                return;
            }
            angular.forEach($scope.tabs[tab].manager.getItems(),
                    function(node) {
                if(node.action_failed === false) {
                    $scope.tabs[tab].manager.unselectItem(node.system_id);
                }
            });
        }

        // Toggles between the current tab.
        $scope.toggleTab = function(tab) {
            $rootScope.title = $scope.tabs[tab].pagetitle;
            $rootScope.page = tab;
            $scope.currentpage = tab;

            switch(tab) {
            case 'machines':
                $scope.osinfo = GeneralManager.getData('osinfo');
                $scope.tabs.machines.takeActionOptions = GeneralManager.getData(
                    'machine_actions');
                break;
            case 'devices':
                $scope.tabs.devices.takeActionOptions = GeneralManager.getData(
                    'device_actions');
                break;
            case 'controllers':
                $scope.tabs.controllers.takeActionOptions =
                    GeneralManager.getData('rack_controller_actions');
                break;
            case 'switches':
                // XXX: Which actions should there be?
                $scope.tabs.switches.takeActionOptions = GeneralManager.getData(
                    "machine_actions");
                break;
            }
        };

        // Clear the search bar.
        $scope.clearSearch = function(tab) {
            $scope.tabs[tab].search = "";
            $scope.updateFilters(tab);
        };

        // Mark a node as selected or unselected.
        $scope.toggleChecked = function(node, tab) {
            if(tab !== 'machines' && tab !== 'switches') {
                if($scope.tabs[tab].manager.isSelected(node.system_id)) {
                    $scope.tabs[tab].manager.unselectItem(node.system_id);
                } else {
                    $scope.tabs[tab].manager.selectItem(node.system_id);
                }
                updateAllViewableChecked(tab);
            }
            updateActionErrorCount(tab);
            shouldClearAction(tab);
        };

        // Select all viewable nodes or deselect all viewable nodes.
        $scope.toggleCheckAll = function(tab) {
            if(tab !== 'machines' && tab !== 'switches') {
                if($scope.tabs[tab].allViewableChecked) {
                    angular.forEach(
                        $scope.tabs[tab].filtered_items, function(node) {
                            $scope.tabs[tab].manager.unselectItem(
                                node.system_id);
                    });
                } else {
                    angular.forEach(
                        $scope.tabs[tab].filtered_items, function(node) {
                            $scope.tabs[tab].manager.selectItem(
                                node.system_id);
                    });
                }
                updateAllViewableChecked(tab);
            }
            updateActionErrorCount(tab);
            shouldClearAction(tab);
        };

        $scope.onNodeListingChanged = function(nodes, tab) {
            if(nodes.length === 0 &&
                $scope.tabs[tab].search !== "" &&
                $scope.tabs[tab].search === $scope.tabs[tab].previous_search) {
                $scope.tabs[tab].search = "";
                $scope.updateFilters(tab);
            }
        };

        // When the filtered nodes change update if all check buttons
        // should be checked or not.
        $scope.$watchCollection("tabs.devices.filtered_items", function() {
            updateAllViewableChecked("devices");
            removeEmptyFilter("devices");
        });
        $scope.$watchCollection("tabs.controllers.filtered_items", function() {
            updateAllViewableChecked("controllers");
            removeEmptyFilter("controllers");
        });

        // Shows the current selection.
        $scope.showSelected = function(tab) {
            enterViewSelected(tab);
            $scope.updateFilters(tab);
        };

        // Adds or removes a filter to the search.
        $scope.toggleFilter = function(type, value, tab) {
            // Don't allow a filter to be changed when an action is
            // in progress.
            if(angular.isObject($scope.tabs[tab].actionOption)) {
                return;
            }
            $scope.tabs[tab].filters = SearchService.toggleFilter(
                $scope.tabs[tab].filters, type, value, true);
            $scope.tabs[tab].search = SearchService.filtersToString(
                $scope.tabs[tab].filters);
        };

        // Return True if the filter is active.
        $scope.isFilterActive = function(type, value, tab) {
            return SearchService.isFilterActive(
                $scope.tabs[tab].filters, type, value, true);
        };

        // Update the filters object when the search bar is updated.
        $scope.updateFilters = function(tab) {
            var filters = SearchService.getCurrentFilters(
                $scope.tabs[tab].search);
            if(filters === null) {
                $scope.tabs[tab].filters = SearchService.getEmptyFilter();
                $scope.tabs[tab].searchValid = false;
            } else {
                $scope.tabs[tab].filters = filters;
                $scope.tabs[tab].searchValid = true;
            }
            shouldClearAction(tab);
        };

        // Sorts the table by predicate.
        $scope.sortTable = function(predicate, tab) {
            $scope.tabs[tab].predicate = predicate;
            $scope.tabs[tab].reverse = !$scope.tabs[tab].reverse;
        };

        // Sets the viewable column or sorts.
        $scope.selectColumnOrSort = function(predicate, tab) {
            if($scope.tabs[tab].column !== predicate) {
                $scope.tabs[tab].column = predicate;
            } else {
                $scope.sortTable(predicate, tab);
            }
        };

        // Return True if the node supports the action.
        $scope.supportsAction = function(node, tab) {
            if(!$scope.tabs[tab].actionOption) {
                return true;
            }
            return node.actions.indexOf(
                $scope.tabs[tab].actionOption.name) >= 0;
        };

        // Called when the action option gets changed.
        $scope.actionOptionSelected = function(tab) {
            updateActionErrorCount(tab);
            enterViewSelected(tab);

            // Hide the add hardware/device section.
            if (tab === 'machines') {
                if(angular.isObject($scope.addHardwareScope)) {
                    $scope.addHardwareScope.hide();
                }
            } else if(tab === 'devices') {
                if(angular.isObject($scope.addDeviceScope)) {
                    $scope.addDeviceScope.hide();
                }
            }
        };

        // Return True if there is an action error.
        $scope.isActionError = function(tab) {
            if(angular.isObject($scope.tabs[tab].actionOption) &&
                $scope.tabs[tab].actionOption.name === "deploy" &&
                $scope.tabs[tab].actionErrorCount === 0 &&
                ($scope.osinfo.osystems.length === 0 ||
                UsersManager.getSSHKeyCount() === 0)) {
                return true;
            }
            return $scope.tabs[tab].actionErrorCount !== 0;
        };

        // Return True if unable to deploy because of missing images.
        $scope.isDeployError = function(tab) {
            if($scope.tabs[tab].actionErrorCount !== 0) {
                return false;
            }
            if(angular.isObject($scope.tabs[tab].actionOption) &&
                $scope.tabs[tab].actionOption.name === "deploy" &&
                $scope.osinfo.osystems.length === 0) {
                return true;
            }
            return false;
        };

        // Return True if unable to deploy because of missing ssh keys.
        $scope.isSSHKeyError = function(tab) {
            if($scope.tabs[tab].actionErrorCount !== 0) {
                return false;
            }
            if(angular.isObject($scope.tabs[tab].actionOption) &&
                $scope.tabs[tab].actionOption.name === "deploy" &&
                UsersManager.getSSHKeyCount() === 0) {
                return true;
            }
            return false;
        };

        // Called when the current action is cancelled.
        $scope.actionCancel = function(tab) {
            resetActionProgress(tab);
            leaveViewSelected(tab);
            $scope.tabs[tab].actionOption = null;
        };

        // Perform the action on all nodes.
        $scope.actionGo = function(tab) {
            var extra = {};
            var i;
            // Set deploy parameters if a deploy or set zone action.
            if($scope.tabs[tab].actionOption.name === "deploy" &&
                angular.isString($scope.tabs[tab].osSelection.osystem) &&
                angular.isString($scope.tabs[tab].osSelection.release)) {

                // Set extra. UI side the release is structured os/release, but
                // when it is sent over the websocket only the "release" is
                // sent.
                extra.osystem = $scope.tabs[tab].osSelection.osystem;
                var release = $scope.tabs[tab].osSelection.release;
                release = release.split("/");
                release = release[release.length-1];
                extra.distro_series = release;
                // hwe_kernel is optional so only include it if its specified
                if(angular.isString($scope.tabs[tab].osSelection.hwe_kernel) &&
                   ($scope.tabs[tab].osSelection.hwe_kernel.indexOf('hwe-')
                    >= 0 ||
                    $scope.tabs[tab].osSelection.hwe_kernel.indexOf('ga-')
                    >= 0)) {
                    extra.hwe_kernel = $scope.tabs[tab].osSelection.hwe_kernel;
                }
            } else if($scope.tabs[tab].actionOption.name === "set-zone" &&
                angular.isNumber($scope.tabs[tab].zoneSelection.id)) {
                // Set the zone parameter.
                extra.zone_id = $scope.tabs[tab].zoneSelection.id;
            } else if($scope.tabs[tab].actionOption.name === "commission") {
                // Set the commission options.
                extra.enable_ssh = (
                    $scope.tabs[tab].commissionOptions.enableSSH);
                extra.skip_networking = (
                    $scope.tabs[tab].commissionOptions.skipNetworking);
                extra.skip_storage = (
                    $scope.tabs[tab].commissionOptions.skipStorage);
                extra.commissioning_scripts = [];
                for(i=0;i<$scope.tabs[tab].commissioningSelection.length;i++) {
                    extra.commissioning_scripts.push(
                        $scope.tabs[tab].commissioningSelection[i].id);
                }
                if($scope.tabs[tab].commissionOptions.updateFirmware) {
                    extra.commissioning_scripts.push('update_firmware')
                }
                if($scope.tabs[tab].commissionOptions.configureHBA) {
                    extra.commissioning_scripts.push('configure_hba')
                }
                if(extra.commissioning_scripts.length === 0) {
                    // Tell the region not to run any custom commissioning
                    // scripts.
                    extra.commissioning_scripts.push('none');
                }
                extra.testing_scripts = [];
                for(i=0;i<$scope.tabs[tab].testSelection.length;i++) {
                    extra.testing_scripts.push(
                        $scope.tabs[tab].testSelection[i].id);
                }
                if(extra.testing_scripts.length === 0) {
                    // Tell the region not to run any tests.
                    extra.testing_scripts.push('none');
                }
            } else if($scope.tabs[tab].actionOption.name === "test") {
                if(!$scope.tabs[tab].actionProgress.showing_confirmation) {
                    var progress = $scope.tabs[tab].actionProgress;
                    for(i=0;i<$scope.tabs[tab].selectedItems.length;i++) {
                        if($scope.tabs[tab].selectedItems[i].status_code === 6)
                        {
                            progress.showing_confirmation = true;
                            progress.affected_nodes++;
                        }
                    }
                    if($scope.tabs[tab].actionProgress.affected_nodes != 0) {
                        return;
                    }
                }
                // Set the test options.
                extra.enable_ssh = (
                    $scope.tabs[tab].commissionOptions.enableSSH);
                extra.testing_scripts = [];
                for(i=0;i<$scope.tabs[tab].testSelection.length;i++) {
                    extra.testing_scripts.push(
                        $scope.tabs[tab].testSelection[i].id);
                }
                if(extra.testing_scripts.length === 0) {
                    // Tell the region not to run any tests.
                    extra.testing_scripts.push('none');
                }
            } else if($scope.tabs[tab].actionOption.name === "release") {
                // Set the release options.
                extra.erase = (
                    $scope.tabs[tab].releaseOptions.erase);
                extra.secure_erase = (
                    $scope.tabs[tab].releaseOptions.secureErase);
                extra.quick_erase = (
                    $scope.tabs[tab].releaseOptions.quickErase);
            }

            // Setup actionProgress.
            resetActionProgress(tab);
            $scope.tabs[tab].actionProgress.total =
                $scope.tabs[tab].selectedItems.length;

            // Perform the action on all selected items.
            angular.forEach($scope.tabs[tab].selectedItems, function(node) {
                $scope.tabs[tab].manager.performAction(
                    node, $scope.tabs[tab].actionOption.name,
                    extra).then(function() {
                        $scope.tabs[tab].actionProgress.completed += 1;
                        node.action_failed = false;
                        updateSelectedItems(tab);
                    }, function(error) {
                        addErrorToActionProgress(tab, error, node);
                        node.action_failed = true;
                        updateSelectedItems(tab);
                    });
            });
        };

        // Returns true when actions are being performed.
        $scope.hasActionsInProgress = function(tab) {
            var progress = $scope.tabs[tab].actionProgress;
            return progress.total > 0 && progress.completed !== progress.total;
        };

        // Returns true if any of the actions have failed.
        $scope.hasActionsFailed = function(tab) {
            return Object.keys(
                $scope.tabs[tab].actionProgress.errors).length > 0;
        };

        // Called to when the addHardwareOption has changed.
        $scope.addHardwareOptionChanged = function() {
            if($scope.addHardwareOption) {
                $scope.addHardwareScope.show(
                    $scope.addHardwareOption.name);
            }
        };

        // Called when the add device button is pressed.
        $scope.addDevice = function() {
            $scope.addDeviceScope.show();
        };

        // Called when the cancel add device button is pressed.
        $scope.cancelAddDevice = function() {
            $scope.addDeviceScope.cancel();
        };

        // Get the display text for device ip assignment type.
        $scope.getDeviceIPAssignment = function(ipAssignment) {
            return DEVICE_IP_ASSIGNMENT[ipAssignment];
        };

        // Return true if the authenticated user is super user.
        $scope.isSuperUser = function() {
            return UsersManager.isSuperUser();
        };

        $scope.hasCustomCommissioningScripts = function() {
            var i;
            for(i=0;i<$scope.scripts.length;i++) {
                if($scope.scripts[i].script_type === 0) {
                    return true;
                }
            }
            return false;
        };

        // Reload osinfo when the page reloads
        $scope.$on("$routeChangeSuccess", function () {
            GeneralManager.loadItems();
        });

        // Switch to the specified tab, if specified.
        angular.forEach(
            ["machines", "devices", "controllers", "switches"],
            function(node_type) {
                if($location.path().indexOf("/" + node_type) !== -1) {
                    $scope.toggleTab(node_type);
                }
            });

        // The ScriptsManager is only needed for selecting testing or
        // commissioning scripts.
        var page_managers = [$scope.tabs[$scope.currentpage].manager];
        if($scope.currentpage === "machines" ||
                $scope.currentpage === "controllers") {
            page_managers.push(ScriptsManager);
        }

        // Load the required managers for this controller. The ServicesManager
        // is required by the maasControllerStatus directive that is used
        // in the partial for this controller.
        ManagerHelperService.loadManagers($scope, [
            GeneralManager, ZonesManager, UsersManager,
            ServicesManager].concat(page_managers)).then(function() {
                $scope.loading = false;
            });


        // Stop polling and save the current filter when the scope is destroyed.
        $scope.$on("$destroy", function() {
            $interval.cancel($scope.statusPoll);
            SearchService.storeFilters(
                "machines", $scope.tabs.machines.filters);
            SearchService.storeFilters("devices", $scope.tabs.devices.filters);
            SearchService.storeFilters(
                "controllers", $scope.tabs.controllers.filters);
            SearchService.storeFilters(
                "switches", $scope.tabs.switches.filters);
        });

        // Restore the filters if any saved.
        var machinesFilter = SearchService.retrieveFilters("machines");
        if(angular.isObject(machinesFilter)) {
            $scope.tabs.machines.search = SearchService.filtersToString(
                machinesFilter);
            $scope.updateFilters("machines");
        }
        var devicesFilter = SearchService.retrieveFilters("devices");
        if(angular.isObject(devicesFilter)) {
            $scope.tabs.devices.search = SearchService.filtersToString(
                devicesFilter);
            $scope.updateFilters("devices");
        }
        var controllersFilter = SearchService.retrieveFilters("controllers");
        if(angular.isObject(controllersFilter)) {
            $scope.tabs.controllers.search = SearchService.filtersToString(
                controllersFilter);
            $scope.updateFilters("controllers");
        }
        var switchesFilter = SearchService.retrieveFilters("switches");
        if(angular.isObject(switchesFilter)) {
            $scope.tabs.switches.search = SearchService.filtersToString(
                switchesFilter);
            $scope.updateFilters("switches");
        }

        // Set the query if the present in $routeParams.
        var query = $routeParams.query;
        if(angular.isString(query)) {
            $scope.tabs[$scope.currentpage].search = query;
            $scope.updateFilters($scope.currentpage);
        }
    }]);