Committed by
Ray Milkey
ONOS-3325 - enable configuration of local IP via environment variables
Change-Id: Ia8df1c126a76c8060e869554316593598dc5ec3e
Showing
1 changed file
with
21 additions
and
1 deletions
... | @@ -55,6 +55,10 @@ public class StaticClusterMetadataStore | ... | @@ -55,6 +55,10 @@ public class StaticClusterMetadataStore |
55 | implements ClusterMetadataStore { | 55 | implements ClusterMetadataStore { |
56 | 56 | ||
57 | private final Logger log = getLogger(getClass()); | 57 | private final Logger log = getLogger(getClass()); |
58 | + | ||
59 | + private static final String ONOS_IP = "ONOS_IP"; | ||
60 | + private static final String ONOS_INTERFACE = "ONOS_INTERFACE"; | ||
61 | + private static final String DEFAULT_ONOS_INTERFACE = "eth0"; | ||
58 | private static final String CLUSTER_METADATA_FILE = "../config/cluster.json"; | 62 | private static final String CLUSTER_METADATA_FILE = "../config/cluster.json"; |
59 | private static final int DEFAULT_ONOS_PORT = 9876; | 63 | private static final int DEFAULT_ONOS_PORT = 9876; |
60 | private final File metadataFile = new File(CLUSTER_METADATA_FILE); | 64 | private final File metadataFile = new File(CLUSTER_METADATA_FILE); |
... | @@ -194,6 +198,22 @@ public class StaticClusterMetadataStore | ... | @@ -194,6 +198,22 @@ public class StaticClusterMetadataStore |
194 | 198 | ||
195 | 199 | ||
196 | private static String getSiteLocalAddress() { | 200 | private static String getSiteLocalAddress() { |
201 | + | ||
202 | + /* | ||
203 | + * If the IP ONOS should use is set via the environment variable we will assume it is valid and should be used. | ||
204 | + * Setting the IP address takes presidence over setting the interface via the environment. | ||
205 | + */ | ||
206 | + String useOnosIp = System.getenv(ONOS_IP); | ||
207 | + if (useOnosIp != null) { | ||
208 | + return useOnosIp; | ||
209 | + } | ||
210 | + | ||
211 | + // Read environment variables for IP interface information or set to default | ||
212 | + String useOnosInterface = System.getenv(ONOS_INTERFACE); | ||
213 | + if (useOnosInterface == null) { | ||
214 | + useOnosInterface = DEFAULT_ONOS_INTERFACE; | ||
215 | + } | ||
216 | + | ||
197 | Function<NetworkInterface, IpAddress> ipLookup = nif -> { | 217 | Function<NetworkInterface, IpAddress> ipLookup = nif -> { |
198 | for (InetAddress address : Collections.list(nif.getInetAddresses())) { | 218 | for (InetAddress address : Collections.list(nif.getInetAddresses())) { |
199 | if (address.isSiteLocalAddress()) { | 219 | if (address.isSiteLocalAddress()) { |
... | @@ -203,7 +223,7 @@ public class StaticClusterMetadataStore | ... | @@ -203,7 +223,7 @@ public class StaticClusterMetadataStore |
203 | return null; | 223 | return null; |
204 | }; | 224 | }; |
205 | try { | 225 | try { |
206 | - IpAddress ip = ipLookup.apply(NetworkInterface.getByName("eth0")); | 226 | + IpAddress ip = ipLookup.apply(NetworkInterface.getByName(useOnosInterface)); |
207 | if (ip != null) { | 227 | if (ip != null) { |
208 | return ip.toString(); | 228 | return ip.toString(); |
209 | } | 229 | } | ... | ... |
-
Please register or login to post a comment