Integrate callhome-status 45/105745/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Apr 2023 17:48:34 +0000 (19:48 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Apr 2023 17:49:43 +0000 (19:49 +0200)
callhome-status.yang as a standalone model does not make much sense,
integrate it into odl-netconf-callhome-server.yang, which simplifies
things a bit.

JIRA: NETCONF-1003
Change-Id: I133a54d95b87fd0f08fd458dd615ca27f22d412c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeAuthProviderImpl.java
apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallhomeStatusReporter.java
apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/IetfZeroTouchCallHomeServerProvider.java
apps/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/tls/TlsAllowedDevicesMonitorImpl.java
netconf/callhome-model/src/main/yang/callhome-status.yang [deleted file]
netconf/callhome-model/src/main/yang/odl-netconf-callhome-server.yang

index 5bd4004ea816cdda8d6a309e5b4189cbb214f27d..1fb765e176e1c11b5e743d45e92b87e15cc55125 100644 (file)
@@ -28,14 +28,14 @@ import org.opendaylight.netconf.callhome.protocol.AuthorizedKeysDecoder;
 import org.opendaylight.netconf.callhome.protocol.CallHomeAuthorization;
 import org.opendaylight.netconf.callhome.protocol.CallHomeAuthorization.Builder;
 import org.opendaylight.netconf.callhome.protocol.CallHomeAuthorizationProvider;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.NetconfCallhomeServer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.credentials.Credentials;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.Global;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.Global.MountPointNamingStrategy;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.NetconfCallhomeServer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.credentials.Credentials;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.AllowedDevices;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.Global;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.Global.MountPointNamingStrategy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.Device;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.Ssh;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
index 6a29ebb39b54c651ec71157818eeab9c9833e0ab..501c9de1ea1c13bc384de0683ea9ea78a78a6eff 100644 (file)
@@ -28,18 +28,16 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.callhome.protocol.AuthorizedKeysDecoder;
 import org.opendaylight.netconf.callhome.protocol.StatusRecorder;
 import org.opendaylight.netconf.topology.spi.NetconfNodeUtils;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1.DeviceStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.NetconfCallhomeServer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.SshBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.NetconfCallhomeServer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.AllowedDevices;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.Device;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.Device.DeviceStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.DeviceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.DeviceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.Ssh;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.SshBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
@@ -168,17 +166,17 @@ final class CallhomeStatusReporter implements DataTreeChangeListener<Node>, Stat
 
     void asForceListedDevice(final String id, final PublicKey serverKey) {
         NodeId nid = new NodeId(id);
-        Device device = newDevice(id, serverKey, Device1.DeviceStatus.DISCONNECTED);
+        Device device = newDevice(id, serverKey, DeviceStatus.DISCONNECTED);
         writeDevice(nid, device);
     }
 
     void asUnlistedDevice(final String id, final PublicKey serverKey) {
         NodeId nid = new NodeId(id);
-        Device device = newDevice(id, serverKey, Device1.DeviceStatus.FAILEDNOTALLOWED);
+        Device device = newDevice(id, serverKey, DeviceStatus.FAILEDNOTALLOWED);
         writeDevice(nid, device);
     }
 
-    private static Device newDevice(final String id, final PublicKey serverKey, final Device1.DeviceStatus status) {
+    private static Device newDevice(final String id, final PublicKey serverKey, final DeviceStatus status) {
         // used only for netconf devices that are connected via SSH transport and global credentials
         String sshEncodedKey = serverKey.toString();
         try {
@@ -192,7 +190,7 @@ final class CallhomeStatusReporter implements DataTreeChangeListener<Node>, Stat
             .setTransport(new SshBuilder()
                 .setSshClientParams(new SshClientParamsBuilder().setHostKey(sshEncodedKey).build())
                 .build())
-            .addAugmentation(new Device1Builder().setDeviceStatus(status).build())
+            .setDeviceStatus(status)
             .build();
     }
 
@@ -222,7 +220,7 @@ final class CallhomeStatusReporter implements DataTreeChangeListener<Node>, Stat
     }
 
     private static Device withConnectedStatus(final Device opDev) {
-        return deviceWithStatus(opDev, Device1.DeviceStatus.CONNECTED);
+        return deviceWithStatus(opDev, DeviceStatus.CONNECTED);
     }
 
     private static Device withFailedStatus(final Device opDev) {
@@ -240,7 +238,7 @@ final class CallhomeStatusReporter implements DataTreeChangeListener<Node>, Stat
     private static Device deviceWithStatus(final Device opDev, final DeviceStatus status) {
         final DeviceBuilder deviceBuilder = new DeviceBuilder()
             .setUniqueId(opDev.getUniqueId())
-            .addAugmentation(new Device1Builder().setDeviceStatus(status).build());
+            .setDeviceStatus(status);
         if (opDev.getTransport() != null) {
             deviceBuilder.setTransport(opDev.getTransport());
         } else {
index 1f990aeaabf68fff592ecfa3bbe3d8b0f7ee2c81..18559458e0cf6bd5306de38b282a280d72a32df8 100644 (file)
@@ -32,19 +32,18 @@ import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.callhome.protocol.NetconfCallHomeServer;
 import org.opendaylight.netconf.callhome.protocol.NetconfCallHomeServerBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.NetconfCallhomeServer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.Transport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.SshBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.NetconfCallhomeServer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.AllowedDevices;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.Device;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.Device.DeviceStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.DeviceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.DeviceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.Transport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.Ssh;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.SshBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.Tls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -213,13 +212,9 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT
         ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
         ListenableFuture<Optional<Device>> deviceFuture = tx.read(LogicalDatastoreType.OPERATIONAL, deviceIID);
 
-        final Device1 devStatus;
-        Optional<Device> opDevGet = deviceFuture.get();
-        if (opDevGet.isPresent()) {
-            devStatus = opDevGet.orElseThrow().augmentation(Device1.class);
-        } else {
-            devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build();
-        }
+        final DeviceStatus devStatus = deviceFuture.get()
+            .map(Device::getDeviceStatus)
+            .orElse(DeviceStatus.DISCONNECTED);
 
         final Device opDevice = createOperationalDevice(cfgDevice, devStatus);
         tx.merge(LogicalDatastoreType.OPERATIONAL, deviceIID, opDevice);
@@ -236,10 +231,10 @@ public class IetfZeroTouchCallHomeServerProvider implements AutoCloseable, DataT
         }, MoreExecutors.directExecutor());
     }
 
-    private static Device createOperationalDevice(final Device cfgDevice, final Device1 devStatus) {
+    private static Device createOperationalDevice(final Device cfgDevice, final DeviceStatus devStatus) {
         final DeviceBuilder deviceBuilder = new DeviceBuilder()
-            .addAugmentation(devStatus)
-            .setUniqueId(cfgDevice.getUniqueId());
+            .setUniqueId(cfgDevice.getUniqueId())
+            .setDeviceStatus(devStatus);
         if (cfgDevice.getTransport() instanceof Ssh ssh) {
             final String hostKey = ssh.getSshClientParams().getHostKey();
             final SshClientParams params = new SshClientParamsBuilder().setHostKey(hostKey).build();
index f968442e77a6b1e5e585cd14f57c5f75fada77d8..5617454aa9346f6027181a788ec69828a216fcc3 100644 (file)
@@ -36,10 +36,10 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.callhome.protocol.tls.TlsAllowedDevicesMonitor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.Keystore;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.trusted.certificates.TrustedCertificate;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.NetconfCallhomeServer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.NetconfCallhomeServer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.AllowedDevices;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.Device;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev230428.netconf.callhome.server.allowed.devices.device.transport.Tls;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.service.component.annotations.Activate;
diff --git a/netconf/callhome-model/src/main/yang/callhome-status.yang b/netconf/callhome-model/src/main/yang/callhome-status.yang
deleted file mode 100644 (file)
index e189c7b..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-module callhome-status{
-    namespace "urn:opendaylight:callhome:device-status";
-    prefix "callhome-status";
-
-    import odl-netconf-callhome-server { prefix callhome; revision-date "2020-10-15"; }
-
-    revision 2017-01-12 {
-        description "Initial revision";
-    }
-
-    augment "/callhome:netconf-callhome-server/callhome:allowed-devices/callhome:device"{
-        leaf device-status {
-          config false;
-          type enumeration {
-              enum CONNECTED;
-              enum FAILED_AUTH_FAILURE;
-              enum FAILED_NOT_ALLOWED;
-              enum FAILED;
-              enum DISCONNECTED;
-          }
-          default DISCONNECTED;
-        }
-    }
-}
index 74e28bb5140c0c461415afaa7c8fe46b1f7c6e1c..dab83dd79e1129757eaf542f989bbb4a5a2c202f 100644 (file)
@@ -12,6 +12,10 @@ module odl-netconf-callhome-server {
   description
    "This module defines the northbound interface for OpenDaylight NETCONF Callhome.";
 
+  revision 2023-04-28 {
+    description "This revision integrates device-status leaf, formerly hosted in callhome-device.yang";
+  }
+
   revision 2020-10-15 {
     description
      "This revision adds connectivity details for one of the supported transport protocols";
@@ -107,6 +111,18 @@ module odl-netconf-callhome-server {
         }
         unique transport/ssh/ssh-client-params/host-key;
         unique transport/tls/tls-client-params/certificate-id;
+
+        leaf device-status {
+          config false;
+          type enumeration {
+            enum CONNECTED;
+            enum FAILED_AUTH_FAILURE;
+            enum FAILED_NOT_ALLOWED;
+            enum FAILED;
+            enum DISCONNECTED;
+          }
+          default DISCONNECTED;
+        }
       }
     }
   }