Search in sources :

Example 1 with ServerKey

use of org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey in project lighty-netconf-simulator by PANTHEONtech.

the class ResetActionProcessor method execute.

@SuppressWarnings({ "rawtypes", "unchecked", "checkstyle:IllegalCatch" })
@Override
protected CompletableFuture<Response> execute(final Element requestXmlElement, final ActionDefinition paramActionDefinition) {
    this.actionDefinition = paramActionDefinition;
    final XmlNodeConverter xmlNodeConverter = getNetconfDeviceServices().getXmlNodeConverter();
    try {
        final XmlElement xmlElement = XmlElement.fromDomElement(requestXmlElement);
        final Element actionElement = findInputElement(xmlElement, this.actionDefinition.getQName());
        final Reader readerFromElement = RPCUtil.createReaderFromElement(actionElement);
        final ContainerNode deserializedNode = (ContainerNode) xmlNodeConverter.deserialize(this.actionDefinition.getInput(), readerFromElement);
        final Input input = this.adapterSerializer.fromNormalizedNodeActionInput(Reset.class, deserializedNode);
        final String key = findNameElement(xmlElement);
        Preconditions.checkNotNull(key);
        final Class listItem = Server.class;
        final Identifier listKey = new ServerKey(key);
        final KeyedInstanceIdentifier<Server, ServerKey> keydIID = (KeyedInstanceIdentifier<Server, ServerKey>) InstanceIdentifier.create(Collections.singletonList(IdentifiableItem.of(listItem, listKey)));
        final ListenableFuture<RpcResult<Output>> outputFuture = this.resetAction.invoke(keydIID, input);
        final CompletableFuture<Response> completableFuture = new CompletableFuture<>();
        Futures.addCallback(outputFuture, new FutureCallback<RpcResult<Output>>() {

            @Override
            public void onSuccess(final RpcResult<Output> result) {
                final NormalizedNode domOutput = ResetActionProcessor.this.adapterSerializer.toNormalizedNodeActionOutput(Reset.class, result.getResult());
                final List<NormalizedNode> list = new ArrayList<>();
                list.add(domOutput);
                completableFuture.complete(new ResponseData(list));
            }

            @Override
            public void onFailure(final Throwable throwable) {
            }
        }, Executors.newSingleThreadExecutor());
        return completableFuture;
    } catch (final TransformerException | DocumentedException | DeserializationException e) {
        throw new RuntimeException(e);
    }
}
Also used : Server(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.Server) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) Reader(java.io.Reader) DeserializationException(io.lighty.codecs.util.exception.DeserializationException) ServerKey(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey) Input(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.reset.Input) CompletableFuture(java.util.concurrent.CompletableFuture) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) DocumentedException(org.opendaylight.netconf.api.DocumentedException) Output(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.reset.Output) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Reset(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.Reset) TransformerException(javax.xml.transform.TransformerException) ResponseData(io.lighty.netconf.device.response.ResponseData) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Response(io.lighty.netconf.device.response.Response) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) XmlNodeConverter(io.lighty.codecs.util.XmlNodeConverter) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)

Example 2 with ServerKey

use of org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey in project netconf by opendaylight.

the class CallhomeStatusReporter method asUnlistedDevice.

void asUnlistedDevice(final String id, final PublicKey serverKey) {
    NodeId nid = new NodeId(id);
    Device device = newDevice(id, serverKey, Device1.DeviceStatus.FAILEDNOTALLOWED);
    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 3 with ServerKey

use of org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey 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 4 with ServerKey

use of org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey in project netconf by opendaylight.

the class CallHomeAuthProviderImpl method provideAuth.

@Override
public CallHomeAuthorization provideAuth(final SocketAddress remoteAddress, final PublicKey serverKey) {
    Device deviceSpecific = deviceConfig.get(serverKey);
    String sessionName;
    Credentials deviceCred;
    if (deviceSpecific != null) {
        sessionName = deviceSpecific.getUniqueId();
        if (deviceSpecific.getTransport() instanceof Ssh) {
            final SshClientParams clientParams = ((Ssh) deviceSpecific.getTransport()).getSshClientParams();
            deviceCred = clientParams.getCredentials();
        } else {
            deviceCred = deviceSpecific.getCredentials();
        }
    } else {
        String syntheticId = fromRemoteAddress(remoteAddress);
        if (globalConfig.allowedUnknownKeys()) {
            sessionName = syntheticId;
            deviceCred = null;
            statusReporter.asForceListedDevice(syntheticId, serverKey);
        } else {
            Device opDevice = deviceOp.get(serverKey);
            if (opDevice == null) {
                statusReporter.asUnlistedDevice(syntheticId, serverKey);
            } else {
                LOG.info("Repeating rejection of unlisted device with id of {}", opDevice.getUniqueId());
            }
            return CallHomeAuthorization.rejected();
        }
    }
    final Credentials credentials = deviceCred != null ? deviceCred : globalConfig.getCredentials();
    if (credentials == null) {
        LOG.info("No credentials found for {}, rejecting.", remoteAddress);
        return CallHomeAuthorization.rejected();
    }
    Builder authBuilder = CallHomeAuthorization.serverAccepted(sessionName, credentials.getUsername());
    for (String password : credentials.getPasswords()) {
        authBuilder.addPassword(password);
    }
    return authBuilder.build();
}
Also used : 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) Device(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device) Builder(org.opendaylight.netconf.callhome.protocol.CallHomeAuthorization.Builder) Ssh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh) Credentials(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.credentials.Credentials)

Example 5 with ServerKey

use of org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey in project netconf by opendaylight.

the class CallhomeStatusReporter method newDevice.

private static Device newDevice(final String id, final PublicKey serverKey, final Device1.DeviceStatus status) {
    // used only for netconf devices that are connected via SSH transport and global credentials
    String sshEncodedKey = serverKey.toString();
    try {
        sshEncodedKey = AuthorizedKeysDecoder.encodePublicKey(serverKey);
    } catch (IOException e) {
        LOG.warn("Unable to encode public key to ssh format.", e);
    }
    final SshClientParams sshParams = new SshClientParamsBuilder().setHostKey(sshEncodedKey).build();
    final Transport transport = new SshBuilder().setSshClientParams(sshParams).build();
    return new DeviceBuilder().setUniqueId(id).withKey(new DeviceKey(id)).setTransport(transport).addAugmentation(new Device1Builder().setDeviceStatus(status).build()).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) Device1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.callhome.device.status.rev170112.Device1Builder) IOException(java.io.IOException) DeviceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceKey) Transport(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.Transport)

Aggregations

Device (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device)3 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)2 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)2 XmlNodeConverter (io.lighty.codecs.util.XmlNodeConverter)1 DeserializationException (io.lighty.codecs.util.exception.DeserializationException)1 Response (io.lighty.netconf.device.response.Response)1 ResponseData (io.lighty.netconf.device.response.ResponseData)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TransformerException (javax.xml.transform.TransformerException)1 DocumentedException (org.opendaylight.netconf.api.DocumentedException)1 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)1 Builder (org.opendaylight.netconf.callhome.protocol.CallHomeAuthorization.Builder)1 Server (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.Server)1 ServerKey (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey)1 Reset (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.Reset)1 Input (org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.reset.Input)1