From d7e246d3d5500415a0b09d1337465657abccc630 Mon Sep 17 00:00:00 2001 From: agosain Date: Fri, 8 Feb 2019 13:31:42 -0800 Subject: [PATCH] Add flexible mount point naming strategy The user can now configure mount point names to either contain IP address and port (default), or just the IP address. Change-Id: Iea07f49ace2f9d0c5826e08791847e414c261403 Signed-off-by: agosain Signed-off-by: Robert Varga (cherry picked from commit 5855a337cbe0657c8dfd9ef3fba2d2d94939965a) --- .../yang/odl-netconf-callhome-server.yang | 9 ++++++++ .../mount/CallHomeAuthProviderImpl.java | 22 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/netconf/callhome-model/src/main/yang/odl-netconf-callhome-server.yang b/netconf/callhome-model/src/main/yang/odl-netconf-callhome-server.yang index 52a9b0f4c3..4a4d168316 100644 --- a/netconf/callhome-model/src/main/yang/odl-netconf-callhome-server.yang +++ b/netconf/callhome-model/src/main/yang/odl-netconf-callhome-server.yang @@ -43,6 +43,15 @@ module odl-netconf-callhome-server { type boolean; default false; } + + leaf mount-point-naming-strategy { + type enumeration { + enum IP_PORT; + enum IP_ONLY; + } + default IP_PORT; + description "Mount name will be chosen as per this strategy in the absence of per device settings. Default is IP_PORT"; + } } container allowed-devices { diff --git a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java index 9a345b02f3..eda8ba2dd6 100644 --- a/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java +++ b/netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java @@ -8,7 +8,6 @@ package org.opendaylight.netconf.callhome.mount; import com.google.common.collect.Iterables; -import com.google.common.net.InetAddresses; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -33,6 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.credentials.Credentials; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.AllowedDevices; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.Global; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.Global.MountPointNamingStrategy; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.Device; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -119,10 +119,20 @@ public class CallHomeAuthProviderImpl implements CallHomeAuthorizationProvider, deviceOpReg.close(); } - private static String fromRemoteAddress(final SocketAddress remoteAddress) { + private String fromRemoteAddress(final SocketAddress remoteAddress) { if (remoteAddress instanceof InetSocketAddress) { InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; - return InetAddresses.toAddrString(socketAddress.getAddress()) + ":" + socketAddress.getPort(); + String ip = socketAddress.getAddress().getHostAddress(); + + final MountPointNamingStrategy strat = globalConfig.getMountPointNamingStrategy(); + switch (strat) { + case IPONLY: + return ip; + case IPPORT: + return ip + ":" + socketAddress.getPort(); + default: + throw new IllegalStateException("Unhandled naming strategy " + strat); + } } return remoteAddress.toString(); } @@ -256,5 +266,11 @@ public class CallHomeAuthProviderImpl implements CallHomeAuthorizationProvider, final Global local = current; return local != null ? local.getCredentials() : null; } + + MountPointNamingStrategy getMountPointNamingStrategy() { + final Global local = current; + final MountPointNamingStrategy strat = local != null ? local.getMountPointNamingStrategy() : null; + return strat == null ? MountPointNamingStrategy.IPPORT : strat; + } } } -- 2.36.6