Set IPV4 interfaces
If a gateway, netmask, or IP address of an IPV4 interface changes on
the page, when the user hits "Save changes" and confirms the popup,
delete the old IPV4 interface and create a new one with the new
values. After talking with Ratan, deleting then adding is the
the correct way to change IPV4 interfaces.
More information can be found in the network README up for review:
https://gerrit.openbmc-project.xyz/#/c/6872/
Tested: Changed IPV4 interface properties on a Witherspoon.
Also tested a Witherspoon in DHCP mode then moved over to a static
IP.
Change-Id: Idc0026aa01533ea327b53efc57e21147c4b68967
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index c8617d3..9f1cc23 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -225,6 +225,46 @@
return response.data;
});
},
+ deleteIPV4: function(interfaceName, networkID) {
+ return $http({
+ method: 'POST',
+ url: DataService.getHost() +
+ '/xyz/openbmc_project/network/' + interfaceName +
+ '/ipv4/' + networkID + '/action/Delete',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({'data': []})
+ })
+ .then(function(response) {
+ return response.data;
+ });
+ },
+ addIPV4: function(
+ interfaceName, ipAddress, netmaskPrefixLength, gateway) {
+ return $http({
+ method: 'POST',
+ url: DataService.getHost() +
+ '/xyz/openbmc_project/network/' + interfaceName +
+ '/action/IP',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true,
+ data: JSON.stringify({
+ 'data': [
+ 'xyz.openbmc_project.Network.IP.Protocol.IPv4',
+ ipAddress, +netmaskPrefixLength, gateway
+ ]
+ })
+ })
+ .then(function(response) {
+ return response.data;
+ });
+ },
getLEDState: function() {
var deferred = $q.defer();
$http({
diff --git a/app/configuration/controllers/network-controller.js b/app/configuration/controllers/network-controller.js
index 5708ec8..5a6912f 100644
--- a/app/configuration/controllers/network-controller.js
+++ b/app/configuration/controllers/network-controller.js
@@ -14,6 +14,7 @@
function($scope, $window, APIUtils, dataService, $route, $q) {
$scope.dataService = dataService;
$scope.network = {};
+ $scope.old_interface = {};
$scope.interface = {};
$scope.networkDevice = false;
$scope.hostname = '';
@@ -25,6 +26,8 @@
$scope.selectInterface = function(interfaceId) {
$scope.interface = $scope.network.interfaces[interfaceId];
+ // Copy the interface so we know later if changes were made to the page
+ $scope.old_interface = JSON.parse(JSON.stringify($scope.interface));
$scope.selectedInterface = interfaceId;
$scope.networkDevice = false;
};
@@ -47,6 +50,20 @@
promises.push(setHostname());
}
+ // Set IPV4 IP Addresses, Netmask Prefix Lengths, and Gateways
+ if (!$scope.interface.DHCPEnabled) {
+ for (var i in $scope.interface.ipv4.values) {
+ if ($scope.interface.ipv4.values[i].Address !=
+ $scope.old_interface.ipv4.values[i].Address ||
+ $scope.interface.ipv4.values[i].PrefixLength !=
+ $scope.old_interface.ipv4.values[i].PrefixLength ||
+ $scope.interface.ipv4.values[i].Gateway !=
+ $scope.old_interface.ipv4.values[i].Gateway) {
+ promises.push(setIPV4(i));
+ }
+ }
+ }
+
if (promises.length) {
$q.all(promises).finally(function() {
if (!$scope.set_network_error) {
@@ -89,6 +106,35 @@
});
}
+ function setIPV4(index) {
+ // The correct way to edit an IPV4 interface is to remove it and then
+ // add a new one
+ return APIUtils
+ .deleteIPV4(
+ $scope.selectedInterface, $scope.interface.ipv4.ids[index])
+ .then(
+ function(data) {
+ return APIUtils
+ .addIPV4(
+ $scope.selectedInterface,
+ $scope.interface.ipv4.values[index].Address,
+ $scope.interface.ipv4.values[index].PrefixLength,
+ $scope.interface.ipv4.values[index].Gateway)
+ .then(
+ function(data) {},
+ function(error) {
+ console.log(JSON.stringify(error));
+ $scope.set_network_error =
+ $scope.interface.ipv4.values[index].Address;
+ });
+ },
+ function(error) {
+ console.log(JSON.stringify(error));
+ $scope.set_network_error =
+ $scope.interface.ipv4.values[index].Address;
+ });
+ }
+
$scope.refresh = function() {
$route.reload();
};
@@ -101,6 +147,9 @@
$scope.selectedInterface = $scope.network.interface_ids[0];
$scope.interface =
$scope.network.interfaces[$scope.selectedInterface];
+ // Copy the interface so we know later if changes were made to the
+ // page
+ $scope.old_interface = JSON.parse(JSON.stringify($scope.interface));
}
});
}