blob: 8acc69e478f4ef4bafbc1fc7b2e62050b332eeed [file] [log] [blame]
Iftekharul Islamcd789502017-04-19 14:37:55 -05001/**
2 * Controller for network
3 *
4 * @module app/configuration
5 * @exports networkController
6 * @name networkController
Iftekharul Islamcd789502017-04-19 14:37:55 -05007 */
8
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07009window.angular && (function(angular) {
10 'use strict';
Iftekharul Islamcd789502017-04-19 14:37:55 -050011
Andrew Geisslerd27bb132018-05-24 11:07:27 -070012 angular.module('app.configuration').controller('networkController', [
Gunnar Mills9a0094d2018-05-02 21:50:56 -050013 '$scope', '$window', 'APIUtils', 'dataService', '$route',
14 function($scope, $window, APIUtils, dataService, $route) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -070015 $scope.dataService = dataService;
16 $scope.network = {};
17 $scope.interface = {};
18 $scope.networkDevice = false;
19 $scope.hostname = '';
Gunnar Millse9f5fe72018-05-04 13:43:10 -050020 $scope.defaultgateway = '';
Gunnar Mills7ddc7272018-04-12 16:12:03 -050021 $scope.set_network_error = '';
22 $scope.set_network_success = false;
23 $scope.selectedInterface = '';
Gunnar Millsd01504c2018-05-03 13:01:51 -050024 $scope.confirm_settings = false;
Iftekharul Islam2a489552017-11-02 13:23:08 -050025
Andrew Geisslerd27bb132018-05-24 11:07:27 -070026 $scope.selectInterface = function(interfaceId) {
27 $scope.interface = $scope.network.interfaces[interfaceId];
28 $scope.selectedInterface = interfaceId;
29 $scope.networkDevice = false;
30 };
Gunnar Mills7ddc7272018-04-12 16:12:03 -050031 $scope.setNetworkSettings = function() {
Gunnar Millsd01504c2018-05-03 13:01:51 -050032 // Hides the confirm network settings modal
33 $scope.confirm_settings = false;
Gunnar Mills7ddc7272018-04-12 16:12:03 -050034 $scope.set_network_error = '';
35 $scope.set_network_success = false;
36 // TODO openbmc/openbmc#3165: check if the network settings
37 // changed before setting
38 APIUtils
39 .setMACAddress(
40 $scope.selectedInterface, $scope.interface.MACAddress)
41 .then(
42 function(data) {
43 $scope.set_network_success = true;
44 },
45 function(error) {
46 console.log(error);
47 $scope.set_network_error = 'MAC Address';
48 });
49 };
Gunnar Mills9a0094d2018-05-02 21:50:56 -050050 $scope.refresh = function() {
51 $route.reload();
52 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -070053 APIUtils.getNetworkInfo().then(function(data) {
54 $scope.network = data.formatted_data;
55 $scope.hostname = data.hostname;
Gunnar Millse9f5fe72018-05-04 13:43:10 -050056 $scope.defaultgateway = data.defaultgateway;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070057 if ($scope.network.interface_ids.length) {
58 $scope.selectedInterface = $scope.network.interface_ids[0];
59 $scope.interface =
60 $scope.network.interfaces[$scope.selectedInterface];
61 }
62 });
63 }
64 ]);
Iftekharul Islamcd789502017-04-19 14:37:55 -050065
66})(angular);