Reserve the vRouter IP from IP pool at network creation phase
Change-Id: I5ccbd83088f521f9386046efefa0d4f92a195c4c
(cherry picked from commit a98e311cbac2396e34ad167d7a8878d72685f90f)
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListIpAddressCommand.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListIpAddressCommand.java
index 343997b..e436f7c 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListIpAddressCommand.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/cli/KubevirtListIpAddressCommand.java
@@ -49,6 +49,12 @@
@Override
protected void doExecute() throws Exception {
KubevirtNetworkService service = get(KubevirtNetworkService.class);
+
+ if (networkId == null) {
+ error("No network identifier was specified");
+ return;
+ }
+
KubevirtNetwork network = service.network(networkId);
if (network == null) {
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java
index d88520a..1821564 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtNetworkHandler.java
@@ -33,6 +33,7 @@
import org.onosproject.core.CoreService;
import org.onosproject.kubevirtnetworking.api.KubevirtFlowRuleService;
import org.onosproject.kubevirtnetworking.api.KubevirtNetwork;
+import org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService;
import org.onosproject.kubevirtnetworking.api.KubevirtNetworkEvent;
import org.onosproject.kubevirtnetworking.api.KubevirtNetworkListener;
import org.onosproject.kubevirtnetworking.api.KubevirtNetworkService;
@@ -156,7 +157,7 @@
protected KubevirtNodeService nodeService;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
- protected KubevirtNetworkService networkService;
+ protected KubevirtNetworkAdminService networkService;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected KubevirtFlowRuleService flowService;
@@ -834,6 +835,13 @@
install);
}
+ private void reserveVrouterIp(KubevirtNetwork network) {
+ String networkId = network.networkId();
+ IpAddress vrouterIp = network.ipPool().start();
+
+ networkService.reserveIp(networkId, vrouterIp);
+ }
+
private class InternalRouterEventListener implements KubevirtRouterListener {
private boolean isRelevantHelper() {
return Objects.equals(localNodeId, leadershipService.getLeader(appId.name()));
@@ -1097,6 +1105,8 @@
initIntegrationTunnelBridge(network);
break;
case FLAT:
+ reserveVrouterIp(network);
+ break;
case VLAN:
break;
default:
@@ -1194,6 +1204,8 @@
setDefaultGatewayRuleToWorkerNodeWhenNodeCreated(node, network);
break;
case FLAT:
+ reserveVrouterIp(network);
+ break;
case VLAN:
default:
// do nothing