ONOS-3325 - enable configuration of local IP via environment variables
Change-Id: Ia8df1c126a76c8060e869554316593598dc5ec3e
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java b/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java
index 9f6c413..e4a09ce 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java
@@ -55,6 +55,10 @@
implements ClusterMetadataStore {
private final Logger log = getLogger(getClass());
+
+ private static final String ONOS_IP = "ONOS_IP";
+ private static final String ONOS_INTERFACE = "ONOS_INTERFACE";
+ private static final String DEFAULT_ONOS_INTERFACE = "eth0";
private static final String CLUSTER_METADATA_FILE = "../config/cluster.json";
private static final int DEFAULT_ONOS_PORT = 9876;
private final File metadataFile = new File(CLUSTER_METADATA_FILE);
@@ -194,6 +198,22 @@
private static String getSiteLocalAddress() {
+
+ /*
+ * If the IP ONOS should use is set via the environment variable we will assume it is valid and should be used.
+ * Setting the IP address takes presidence over setting the interface via the environment.
+ */
+ String useOnosIp = System.getenv(ONOS_IP);
+ if (useOnosIp != null) {
+ return useOnosIp;
+ }
+
+ // Read environment variables for IP interface information or set to default
+ String useOnosInterface = System.getenv(ONOS_INTERFACE);
+ if (useOnosInterface == null) {
+ useOnosInterface = DEFAULT_ONOS_INTERFACE;
+ }
+
Function<NetworkInterface, IpAddress> ipLookup = nif -> {
for (InetAddress address : Collections.list(nif.getInetAddresses())) {
if (address.isSiteLocalAddress()) {
@@ -203,7 +223,7 @@
return null;
};
try {
- IpAddress ip = ipLookup.apply(NetworkInterface.getByName("eth0"));
+ IpAddress ip = ipLookup.apply(NetworkInterface.getByName(useOnosInterface));
if (ip != null) {
return ip.toString();
}
@@ -218,4 +238,4 @@
}
return IpAddress.valueOf(InetAddress.getLoopbackAddress()).toString();
}
-}
\ No newline at end of file
+}