use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project netconf by opendaylight.
the class CallhomeStatusReporter method handleUnableToConnectNetconfNode.
private void handleUnableToConnectNetconfNode(final NodeId nodeId) {
// The maximum configured number of reconnect attempts
// have been reached. No more reconnects will be
// attempted by the Netconf Connector.
LOG.debug("NETCONF Node: {} connection failed", nodeId.getValue());
Device opDev = readAndGetDevice(nodeId);
if (opDev == null) {
LOG.warn("No corresponding callhome device found - exiting.");
} else {
Device modifiedDevice = withFailedStatus(opDev);
if (modifiedDevice == null) {
return;
}
LOG.info("Setting failed status for callhome device id:{}.", nodeId);
writeDevice(nodeId, modifiedDevice);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project netconf by opendaylight.
the class CallhomeStatusReporter method asForceListedDevice.
void asForceListedDevice(final String id, final PublicKey serverKey) {
NodeId nid = new NodeId(id);
Device device = newDevice(id, serverKey, Device1.DeviceStatus.DISCONNECTED);
writeDevice(nid, device);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project netconf by opendaylight.
the class IetfZeroTouchCallHomeServerProvider method onDataTreeChanged.
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<AllowedDevices>> changes) {
// In case of any changes to the devices datatree, register the changed values with callhome server
// As of now, no way to add a new callhome client key to the CallHomeAuthorization instance since
// its created under CallHomeAuthorizationProvider.
// Will have to redesign a bit here.
// CallHomeAuthorization.
final ListenableFuture<Optional<AllowedDevices>> devicesFuture;
try (ReadTransaction roConfigTx = dataBroker.newReadOnlyTransaction()) {
devicesFuture = roConfigTx.read(LogicalDatastoreType.CONFIGURATION, IetfZeroTouchCallHomeServerProvider.ALL_DEVICES);
}
Set<InstanceIdentifier<?>> deletedDevices = new HashSet<>();
for (DataTreeModification<AllowedDevices> change : changes) {
DataObjectModification<AllowedDevices> rootNode = change.getRootNode();
switch(rootNode.getModificationType()) {
case DELETE:
deletedDevices.add(change.getRootPath().getRootIdentifier());
break;
default:
break;
}
}
handleDeletedDevices(deletedDevices);
try {
for (Device confDevice : getReadDevices(devicesFuture)) {
readAndUpdateStatus(confDevice);
}
} catch (ExecutionException | InterruptedException e) {
LOG.error("Error trying to read the whitelist devices", e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project netconf by opendaylight.
the class IetfZeroTouchCallHomeServerProvider method readAndUpdateStatus.
private void readAndUpdateStatus(final Device cfgDevice) throws InterruptedException, ExecutionException {
InstanceIdentifier<Device> deviceIID = InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class).child(Device.class, new DeviceKey(cfgDevice.getUniqueId()));
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.get().augmentation(Device1.class);
} else {
devStatus = new Device1Builder().setDeviceStatus(Device1.DeviceStatus.DISCONNECTED).build();
}
final Device opDevice = createOperationalDevice(cfgDevice, devStatus);
tx.merge(LogicalDatastoreType.OPERATIONAL, deviceIID, opDevice);
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.debug("Device {} status update committed", cfgDevice.key());
}
@Override
public void onFailure(final Throwable cause) {
LOG.warn("Failed to commit device {} status update", cfgDevice.key(), cause);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project netconf by opendaylight.
the class IetfZeroTouchCallHomeServerProvider method createOperationalDevice.
private Device createOperationalDevice(final Device cfgDevice, final Device1 devStatus) {
final DeviceBuilder deviceBuilder = new DeviceBuilder().addAugmentation(devStatus).setUniqueId(cfgDevice.getUniqueId());
if (cfgDevice.getTransport() instanceof Ssh) {
final String hostKey = ((Ssh) cfgDevice.getTransport()).getSshClientParams().getHostKey();
final SshClientParams params = new SshClientParamsBuilder().setHostKey(hostKey).build();
final Transport sshTransport = new SshBuilder().setSshClientParams(params).build();
deviceBuilder.setTransport(sshTransport);
} else if (cfgDevice.getTransport() instanceof Tls) {
deviceBuilder.setTransport(cfgDevice.getTransport());
} else if (cfgDevice.getSshHostKey() != null) {
deviceBuilder.setSshHostKey(cfgDevice.getSshHostKey());
}
return deviceBuilder.build();
}
Aggregations