Marc De Leenheer | 57a5af0 | 2016-12-02 20:54:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | package org.onosproject.provider.tl1.device.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.incubator.net.config.basics.ConfigException; |
| 23 | import org.onosproject.net.config.Config; |
| 24 | import org.onosproject.tl1.impl.DefaultTl1Device; |
| 25 | import org.onosproject.tl1.Tl1Device; |
| 26 | |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * Configuration for TL1 provider. |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 31 | * @deprecated 1.10.0 Kingfisher |
| 32 | * |
Marc De Leenheer | 57a5af0 | 2016-12-02 20:54:41 -0800 | [diff] [blame] | 33 | */ |
Andrea Campanella | 59b549d | 2017-04-14 21:58:16 +0200 | [diff] [blame] | 34 | @Deprecated |
Marc De Leenheer | 57a5af0 | 2016-12-02 20:54:41 -0800 | [diff] [blame] | 35 | public class Tl1ProviderConfig extends Config<ApplicationId> { |
| 36 | public static final String CONFIG_VALUE_ERROR = "Error parsing config value"; |
| 37 | private static final String IP = "ip"; |
| 38 | private static final String PORT = "port"; |
| 39 | private static final String USERNAME = "username"; |
| 40 | private static final String PASSWORD = "password"; |
| 41 | |
| 42 | Set<Tl1Device> readDevices() throws ConfigException { |
| 43 | Set<Tl1Device> devices = Sets.newHashSet(); |
| 44 | |
| 45 | try { |
| 46 | for (JsonNode node : array) { |
| 47 | String ip = node.path(IP).asText(); |
| 48 | IpAddress ipAddress = IpAddress.valueOf(ip); |
| 49 | int port = node.path(PORT).asInt(); |
| 50 | String username = node.path(USERNAME).asText(); |
| 51 | String password = node.path(PASSWORD).asText(); |
| 52 | devices.add(new DefaultTl1Device(ipAddress, port, username, password)); |
| 53 | } |
| 54 | } catch (IllegalArgumentException e) { |
| 55 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 56 | } |
| 57 | |
| 58 | return devices; |
| 59 | } |
| 60 | } |