blob: 59cffb64e7a446fd2afef86d110030118691d075 [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
andreaeb70a942015-10-16 21:34:46 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.provider.netconf.device.impl;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.google.common.annotations.Beta;
21import com.google.common.collect.Sets;
22import org.onlab.packet.IpAddress;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.incubator.net.config.basics.ConfigException;
25import org.onosproject.net.config.Config;
26
27import java.util.Set;
28
29/**
30 * Configuration for Netconf provider.
Andrea Campanella34cf65c2017-04-12 13:51:32 +020031 * @deprecated 1.10.0 Kingfisher
andreaeb70a942015-10-16 21:34:46 -070032 */
33@Beta
Andrea Campanella34cf65c2017-04-12 13:51:32 +020034@Deprecated
andreaeb70a942015-10-16 21:34:46 -070035public class NetconfProviderConfig extends Config<ApplicationId> {
36
37 public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
38 private static final String IP = "ip";
39 private static final int DEFAULT_TCP_PORT = 830;
40 private static final String PORT = "port";
Konstantinos Kanonakisb3e97042016-11-15 11:33:07 -060041 private static final String NAME = "username";
andreaeb70a942015-10-16 21:34:46 -070042 private static final String PASSWORD = "password";
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060043 private static final String SSHKEY = "sshkey";
andreaeb70a942015-10-16 21:34:46 -070044
45 public Set<NetconfDeviceAddress> getDevicesAddresses() throws ConfigException {
46 Set<NetconfDeviceAddress> devicesAddresses = Sets.newHashSet();
andreaeb70a942015-10-16 21:34:46 -070047 try {
48 for (JsonNode node : array) {
49 String ip = node.path(IP).asText();
50 IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
51 int port = node.path(PORT).asInt(DEFAULT_TCP_PORT);
52 String name = node.path(NAME).asText();
53 String password = node.path(PASSWORD).asText();
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060054 String sshkey = node.path(SSHKEY).asText();
55 devicesAddresses.add(new NetconfDeviceAddress(ipAddr, port, name, password, sshkey));
andreaeb70a942015-10-16 21:34:46 -070056
57 }
58 } catch (IllegalArgumentException e) {
59 throw new ConfigException(CONFIG_VALUE_ERROR, e);
60 }
61
62 return devicesAddresses;
63 }
64
Andrea Campanella34cf65c2017-04-12 13:51:32 +020065 public class
66 NetconfDeviceAddress {
andreaeb70a942015-10-16 21:34:46 -070067 private final IpAddress ip;
68 private final int port;
69 private final String name;
70 private final String password;
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060071 private final String sshkey;
andreaeb70a942015-10-16 21:34:46 -070072
73 public NetconfDeviceAddress(IpAddress ip, int port, String name, String password) {
74 this.ip = ip;
75 this.port = port;
76 this.name = name;
77 this.password = password;
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060078 this.sshkey = "";
79 }
80
81 public NetconfDeviceAddress(IpAddress ip, int port, String name, String password, String sshkey) {
82 this.ip = ip;
83 this.port = port;
84 this.name = name;
85 this.password = password;
86 this.sshkey = sshkey;
andreaeb70a942015-10-16 21:34:46 -070087 }
88
89 public IpAddress ip() {
90 return ip;
91 }
92
93 public int port() {
94 return port;
95 }
96
97 public String name() {
98 return name;
99 }
100
101 public String password() {
102 return password;
103 }
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -0600104
105 public String sshkey() {
106 return sshkey;
107 }
andreaeb70a942015-10-16 21:34:46 -0700108 }
109
Andrea Campanella34cf65c2017-04-12 13:51:32 +0200110}