1cd789508SIftekharul Islam/** 2cd789508SIftekharul Islam * Controller for network 3cd789508SIftekharul Islam * 4cd789508SIftekharul Islam * @module app/configuration 5cd789508SIftekharul Islam * @exports networkController 6cd789508SIftekharul Islam * @name networkController 7cd789508SIftekharul Islam */ 8cd789508SIftekharul Islam 9cd789508SIftekharul Islamwindow.angular && (function(angular) { 10cd789508SIftekharul Islam 'use strict'; 11cd789508SIftekharul Islam 12d27bb135SAndrew Geissler angular.module('app.configuration').controller('networkController', [ 13dca79d73SGunnar Mills '$scope', '$window', 'APIUtils', 'dataService', '$route', '$q', 14dca79d73SGunnar Mills function($scope, $window, APIUtils, dataService, $route, $q) { 15cd789508SIftekharul Islam $scope.dataService = dataService; 162a489554SIftekharul Islam $scope.network = {}; 172a489554SIftekharul Islam $scope.interface = {}; 182a489554SIftekharul Islam $scope.networkDevice = false; 19ba5e3f34SAndrew Geissler $scope.hostname = ''; 20e9f5fe77SGunnar Mills $scope.defaultgateway = ''; 217ddc7274SGunnar Mills $scope.set_network_error = ''; 227ddc7274SGunnar Mills $scope.set_network_success = false; 237ddc7274SGunnar Mills $scope.selectedInterface = ''; 24d01504cfSGunnar Mills $scope.confirm_settings = false; 252a489554SIftekharul Islam 262a489554SIftekharul Islam $scope.selectInterface = function(interfaceId) { 272a489554SIftekharul Islam $scope.interface = $scope.network.interfaces[interfaceId]; 282a489554SIftekharul Islam $scope.selectedInterface = interfaceId; 292a489554SIftekharul Islam $scope.networkDevice = false; 30ba5e3f34SAndrew Geissler }; 317ddc7274SGunnar Mills $scope.setNetworkSettings = function() { 32d01504cfSGunnar Mills // Hides the confirm network settings modal 33d01504cfSGunnar Mills $scope.confirm_settings = false; 347ddc7274SGunnar Mills $scope.set_network_error = ''; 357ddc7274SGunnar Mills $scope.set_network_success = false; 36dca79d73SGunnar Mills var promises = []; 37dca79d73SGunnar Mills 387ddc7274SGunnar Mills // TODO openbmc/openbmc#3165: check if the network settings 397ddc7274SGunnar Mills // changed before setting 40dca79d73SGunnar Mills promises.push(setMACAddress()); 41dca79d73SGunnar Mills promises.push(setDefaultGateway()); 42*309e06abSGunnar Mills promises.push(setHostname()); 43*309e06abSGunnar Mills 44dca79d73SGunnar Mills $q.all(promises).finally(function() { 45dca79d73SGunnar Mills if (!$scope.set_network_error) { 46dca79d73SGunnar Mills $scope.set_network_success = true; 47dca79d73SGunnar Mills } 48dca79d73SGunnar Mills }); 49dca79d73SGunnar Mills 50dca79d73SGunnar Mills }; 51dca79d73SGunnar Mills 52dca79d73SGunnar Mills function setMACAddress() { 53dca79d73SGunnar Mills return APIUtils 547ddc7274SGunnar Mills .setMACAddress( 557ddc7274SGunnar Mills $scope.selectedInterface, $scope.interface.MACAddress) 567ddc7274SGunnar Mills .then( 57dca79d73SGunnar Mills function(data) {}, 587ddc7274SGunnar Mills function(error) { 59dca79d73SGunnar Mills console.log(JSON.stringify(error)); 607ddc7274SGunnar Mills $scope.set_network_error = 'MAC Address'; 617ddc7274SGunnar Mills }); 62dca79d73SGunnar Mills } 63dca79d73SGunnar Mills 64dca79d73SGunnar Mills function setDefaultGateway() { 65dca79d73SGunnar Mills return APIUtils.setDefaultGateway($scope.defaultgateway) 66dca79d73SGunnar Mills .then( 67dca79d73SGunnar Mills function(data) {}, 68dca79d73SGunnar Mills function(error) { 69dca79d73SGunnar Mills console.log(JSON.stringify(error)); 70dca79d73SGunnar Mills $scope.set_network_error = 'Default Gateway'; 71dca79d73SGunnar Mills }); 72dca79d73SGunnar Mills } 73*309e06abSGunnar Mills 74*309e06abSGunnar Mills function setHostname() { 75*309e06abSGunnar Mills return APIUtils.setHostname($scope.hostname) 76*309e06abSGunnar Mills .then( 77*309e06abSGunnar Mills function(data) {}, 78*309e06abSGunnar Mills function(error) { 79*309e06abSGunnar Mills console.log(JSON.stringify(error)); 80*309e06abSGunnar Mills $scope.set_network_error = 'Hostname'; 81*309e06abSGunnar Mills }); 82*309e06abSGunnar Mills } 83*309e06abSGunnar Mills 849a0094dcSGunnar Mills $scope.refresh = function() { 859a0094dcSGunnar Mills $route.reload(); 869a0094dcSGunnar Mills }; 872a489554SIftekharul Islam APIUtils.getNetworkInfo().then(function(data) { 882a489554SIftekharul Islam $scope.network = data.formatted_data; 892a489554SIftekharul Islam $scope.hostname = data.hostname; 90e9f5fe77SGunnar Mills $scope.defaultgateway = data.defaultgateway; 912a489554SIftekharul Islam if ($scope.network.interface_ids.length) { 922a489554SIftekharul Islam $scope.selectedInterface = $scope.network.interface_ids[0]; 93d27bb135SAndrew Geissler $scope.interface = 94d27bb135SAndrew Geissler $scope.network.interfaces[$scope.selectedInterface]; 952a489554SIftekharul Islam } 962a489554SIftekharul Islam }); 97cd789508SIftekharul Islam } 98ba5e3f34SAndrew Geissler ]); 99cd789508SIftekharul Islam 100cd789508SIftekharul Islam})(angular); 101