Add and Update IPV4 address
This allows user to add IPV4 addresses
and updates logic for editing IPV4
addresses.
Resolves openbmc/phosphor-webui#12
Tested: Added, removed and modified IPV4
addresses, called API to verify that
addresses had been correctly modified.
Verified that if address had not been
modified, no change was made for that
address.
Change-Id: I3dd25565f4f610dce2023e23348f6eb8d00add3d
Signed-off-by: beccabroek <beccabroek@gmail.com>
diff --git a/app/configuration/controllers/network-controller.js b/app/configuration/controllers/network-controller.js
index a9546d4..92da0b2 100644
--- a/app/configuration/controllers/network-controller.js
+++ b/app/configuration/controllers/network-controller.js
@@ -44,6 +44,11 @@
$scope.interface.Nameservers.splice(index, 1);
};
+ $scope.addIpv4Field = function() {
+ $scope.interface.ipv4.values.push(
+ {Address: '', PrefixLength: '', Gateway: ''});
+ };
+
$scope.removeIpv4Address = function(index) {
// Check if the IPV4 being removed has an id. This indicates that it is
// an existing address and needs to be removed in the back end.
@@ -91,7 +96,7 @@
if (!$scope.interface.DHCPEnabled) {
// Delete existing IPV4 addresses that were removed
promises.push(removeIPV4s());
- // Update any changed IPV4 addresses
+ // Update any changed IPV4 addresses and add new
for (var i in $scope.interface.ipv4.values) {
if (!APIUtils.validIPV4IP(
$scope.interface.ipv4.values[i].Address)) {
@@ -117,13 +122,18 @@
$scope.loading = false;
return;
}
- 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 ($scope.interface.ipv4.values[i].update_address ||
+ $scope.interface.ipv4.values[i].update_gateway ||
+ $scope.interface.ipv4.values[i].update_prefix) {
+ // If IPV4 has an id it means it already exists in the back end,
+ // and in order to update it is required to remove previous IPV4
+ // address and add new one. See openbmc/openbmc/issues/2163.
+ // TODO: update to use PUT once issue 2163 is resolved.
+ if ($scope.interface.ipv4.values[i].id) {
+ promises.push(updateIPV4(i));
+ } else {
+ promises.push(addIPV4(i));
+ }
}
}
}
@@ -227,12 +237,29 @@
});
}
- function setIPV4(index) {
+ function addIPV4(index) {
+ 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 updateIPV4(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])
+ $scope.selectedInterface,
+ $scope.interface.ipv4.values[index].id)
.then(
function(data) {
return APIUtils
@@ -278,9 +305,12 @@
// page
$scope.old_interface = JSON.parse(JSON.stringify($scope.interface));
}
- // Add id values to corresponding IPV4 objects
+ // Add id values and update flags to corresponding IPV4 objects
for (var i = 0; i < $scope.interface.ipv4.values.length; i++) {
$scope.interface.ipv4.values[i].id = $scope.interface.ipv4.ids[i];
+ $scope.interface.ipv4.values[i].update_address = false;
+ $scope.interface.ipv4.values[i].update_gateway = false;
+ $scope.interface.ipv4.values[i].update_prefix = false;
}
});
}