Search in sources :

Example 71 with 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 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);
    }
}
Also used : Device(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device)

Example 72 with 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 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);
}
Also used : Device(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)

Example 73 with 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);
    }
}
Also used : Optional(java.util.Optional) Device(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device) AllowedDevices(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 74 with 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 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());
}
Also used : Optional(java.util.Optional) Device(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device) Device1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1Builder) AllowedDevices(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.AllowedDevices) Device1(org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1) ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) DeviceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceKey) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 75 with 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 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();
}
Also used : DeviceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceBuilder) SshClientParams(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams) SshClientParamsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder) SshBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.SshBuilder) Ssh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh) Tls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls) Transport(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.Transport)

Aggregations

ArrayList (java.util.ArrayList)50 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)34 L2GatewayDevice (org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)30 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)29 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)25 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)24 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)24 List (java.util.List)21 ExecutionException (java.util.concurrent.ExecutionException)18 Collection (java.util.Collection)16 Map (java.util.Map)16 Collections (java.util.Collections)15 HashMap (java.util.HashMap)15 Test (org.junit.Test)14 BigInteger (java.math.BigInteger)13 Set (java.util.Set)13 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)13 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12