andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.provider.netconf.device.impl; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.google.common.annotations.Beta; |
| 21 | import com.google.common.collect.Sets; |
| 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.incubator.net.config.basics.ConfigException; |
| 25 | import org.onosproject.net.config.Config; |
| 26 | |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * Configuration for Netconf provider. |
Andrea Campanella | 34cf65c | 2017-04-12 13:51:32 +0200 | [diff] [blame^] | 31 | * @deprecated 1.10.0 Kingfisher |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 32 | */ |
| 33 | @Beta |
Andrea Campanella | 34cf65c | 2017-04-12 13:51:32 +0200 | [diff] [blame^] | 34 | @Deprecated |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 35 | public 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 Kanonakis | b3e9704 | 2016-11-15 11:33:07 -0600 | [diff] [blame] | 41 | private static final String NAME = "username"; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 42 | private static final String PASSWORD = "password"; |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 43 | private static final String SSHKEY = "sshkey"; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 44 | |
| 45 | public Set<NetconfDeviceAddress> getDevicesAddresses() throws ConfigException { |
| 46 | Set<NetconfDeviceAddress> devicesAddresses = Sets.newHashSet(); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 47 | 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 Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 54 | String sshkey = node.path(SSHKEY).asText(); |
| 55 | devicesAddresses.add(new NetconfDeviceAddress(ipAddr, port, name, password, sshkey)); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 56 | |
| 57 | } |
| 58 | } catch (IllegalArgumentException e) { |
| 59 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 60 | } |
| 61 | |
| 62 | return devicesAddresses; |
| 63 | } |
| 64 | |
Andrea Campanella | 34cf65c | 2017-04-12 13:51:32 +0200 | [diff] [blame^] | 65 | public class |
| 66 | NetconfDeviceAddress { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 67 | private final IpAddress ip; |
| 68 | private final int port; |
| 69 | private final String name; |
| 70 | private final String password; |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 71 | private final String sshkey; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 72 | |
| 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 Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 78 | 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; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 87 | } |
| 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 Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 104 | |
| 105 | public String sshkey() { |
| 106 | return sshkey; |
| 107 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Andrea Campanella | 34cf65c | 2017-04-12 13:51:32 +0200 | [diff] [blame^] | 110 | } |