Support multi-physnet networking model for kubevirt
Change-Id: Ic245d48dd2e801080c388cf752860fd2f82aa780
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
index 291db11..186ca90 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/NetworkAttachmentDefinitionWatcher.java
@@ -207,7 +207,9 @@
KubevirtNetwork network = parseKubevirtNetwork(resource);
if (network != null) {
- adminService.createNetwork(network);
+ if (adminService.network(network.networkId()) == null) {
+ adminService.createNetwork(network);
+ }
}
}
diff --git a/apps/kubevirt-node/BUILD b/apps/kubevirt-node/BUILD
index 633bea2..038cae3 100644
--- a/apps/kubevirt-node/BUILD
+++ b/apps/kubevirt-node/BUILD
@@ -1,6 +1,7 @@
BUNDLES = JACKSON + [
"//apps/kubevirt-node/api:onos-apps-kubevirt-node-api",
"//apps/kubevirt-node/app:onos-apps-kubevirt-node-app",
+ "@json//jar",
"@commons_net//jar",
"@k8s_client//jar",
"@k8s_model//jar",
diff --git a/apps/kubevirt-node/app/BUILD b/apps/kubevirt-node/app/BUILD
index ffb35e5..71936ea 100644
--- a/apps/kubevirt-node/app/BUILD
+++ b/apps/kubevirt-node/app/BUILD
@@ -3,6 +3,7 @@
"//protocols/ovsdb/api:onos-protocols-ovsdb-api",
"//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc",
"//apps/kubevirt-node/api:onos-apps-kubevirt-node-api",
+ "@json//jar",
"@k8s_client//jar",
"@k8s_model//jar",
"@k8s_model_common//jar",
diff --git a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/impl/DefaultKubevirtApiConfigHandler.java b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/impl/DefaultKubevirtApiConfigHandler.java
index cfd95b6..9a6d110 100644
--- a/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/impl/DefaultKubevirtApiConfigHandler.java
+++ b/apps/kubevirt-node/app/src/main/java/org/onosproject/kubevirtnode/impl/DefaultKubevirtApiConfigHandler.java
@@ -18,6 +18,9 @@
import io.fabric8.kubernetes.api.model.Node;
import io.fabric8.kubernetes.api.model.NodeAddress;
import io.fabric8.kubernetes.client.KubernetesClient;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.onlab.packet.IpAddress;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.LeadershipService;
@@ -66,8 +69,9 @@
private static final String INTERNAL_IP = "InternalIP";
private static final String K8S_ROLE = "node-role.kubernetes.io";
- private static final String DEFAULT_PHY_NETWORK = "physical.network";
- private static final String DEFAULT_PHY_INTERFACE = "physical.interface";
+ private static final String PHYSNET_CONFIG_KEY = "physnet-config";
+ private static final String NETWORK_KEY = "network";
+ private static final String INTERFACE_KEY = "interface";
private static final long SLEEP_MS = 10000; // we wait 10s
@@ -166,12 +170,26 @@
// start to parse kubernetes annotation
Map<String, String> annots = node.getMetadata().getAnnotations();
- String physnet = annots.get(DEFAULT_PHY_NETWORK);
- String physintf = annots.get(DEFAULT_PHY_INTERFACE);
-
+ String physnetConfig = annots.get(PHYSNET_CONFIG_KEY);
Set<KubevirtPhyInterface> phys = new HashSet<>();
- if (physnet != null && physintf != null) {
- phys.add(DefaultKubevirtPhyInterface.builder().network(physnet).intf(physintf).build());
+ try {
+ if (physnetConfig != null) {
+ JSONArray configJson = new JSONArray(physnetConfig);
+
+ for (int i = 0; i < configJson.length(); i++) {
+ JSONObject object = configJson.getJSONObject(i);
+ String network = object.getString(NETWORK_KEY);
+ String intf = object.getString(INTERFACE_KEY);
+
+ if (network != null && intf != null) {
+ phys.add(DefaultKubevirtPhyInterface.builder()
+ .network(network).intf(intf).build());
+ }
+
+ }
+ }
+ } catch (JSONException e) {
+ log.error("Failed to parse network status object", e);
}
return DefaultKubevirtNode.builder()