2 * Copyright (c) 2016 Brocade Communication Systems and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.callhome.mount;
10 import java.net.InetAddress;
11 import java.net.UnknownHostException;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.netconf.callhome.server.CallHomeStatusRecorder;
15 import org.opendaylight.netconf.callhome.server.ssh.CallHomeSshAuthProvider;
16 import org.opendaylight.netconf.callhome.server.ssh.CallHomeSshServer;
17 import org.osgi.service.component.annotations.Activate;
18 import org.osgi.service.component.annotations.Component;
19 import org.osgi.service.component.annotations.Deactivate;
20 import org.osgi.service.component.annotations.Reference;
21 import org.osgi.service.metatype.annotations.AttributeDefinition;
22 import org.osgi.service.metatype.annotations.Designate;
23 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 @Component(service = { }, configurationPid = "org.opendaylight.netconf.callhome.mount.ssh.server")
28 @Designate(ocd = IetfZeroTouchCallHomeServerProvider.Configuration.class)
30 public final class IetfZeroTouchCallHomeServerProvider implements AutoCloseable {
32 @ObjectClassDefinition
33 public @interface Configuration {
35 String host() default "0.0.0.0";
37 @AttributeDefinition(min = "1", max = "65535")
38 int port() default 4334;
41 private static final Logger LOG = LoggerFactory.getLogger(IetfZeroTouchCallHomeServerProvider.class);
42 private final CallHomeSshServer server;
46 public IetfZeroTouchCallHomeServerProvider(
47 final @Reference CallHomeMountService mountService,
48 final @Reference CallHomeSshAuthProvider authProvider,
49 final @Reference CallHomeStatusRecorder statusRecorder,
50 final Configuration configuration) {
52 LOG.info("Starting Call-Home SSH server at {}:{}", configuration.host(), configuration.port());
55 server = CallHomeSshServer.builder()
56 .withAddress(InetAddress.getByName(configuration.host()))
57 .withPort(configuration.port())
58 .withAuthProvider(authProvider)
59 .withStatusRecorder(statusRecorder)
60 .withSessionContextManager(mountService.createSshSessionContextManager())
62 } catch (UnknownHostException e) {
63 throw new IllegalArgumentException("Invalid address", e);
66 LOG.info("Call-Home SSH server started successfully");
71 public void close() throws Exception {
75 LOG.info("Call-Home SSH server stopped.");