blob: 8a373c4c89045863989b4b42886e9cbdbf663ce1 [file] [log] [blame]
Aaron Kruglikov7adb89e2016-01-06 15:21:28 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Aaron Kruglikov7adb89e2016-01-06 15:21:28 -08003 *
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
Andrea Campanella238d96e2016-01-20 11:52:02 -080017package org.onosproject.drivers.netconf;
Aaron Kruglikov12faf8d2016-01-04 16:24:07 -080018
19import com.google.common.base.Preconditions;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.behaviour.ConfigGetter;
22import org.onosproject.net.driver.AbstractHandlerBehaviour;
23import org.onosproject.net.driver.DriverHandler;
24import org.onosproject.netconf.NetconfController;
25import org.slf4j.Logger;
26
27import java.io.IOException;
28
29import static org.slf4j.LoggerFactory.getLogger;
30
31/**
32 * Gets the configuration of the specified type from the specified device. If a
33 * failure occurs it returns the error string found in UNABLE_TO_READ_CONFIG.
Aaron Kruglikov12faf8d2016-01-04 16:24:07 -080034 * This is a temporary development tool for use until yang integration is complete.
35 * This is not a properly specified behavior implementation. DO NOT USE AS AN EXAMPLE.
36 */
37//FIXME this should eventually be removed.
38
39public class NetconfConfigGetter extends AbstractHandlerBehaviour
40 implements ConfigGetter {
41
Andrea Campanella950310c2016-02-12 18:14:38 -080042 private final Logger log = getLogger(getClass());
Aaron Kruglikov12faf8d2016-01-04 16:24:07 -080043
44 //FIXME the error string should be universal for all implementations of
45 // ConfigGetter
46 public static final String UNABLE_TO_READ_CONFIG = "config retrieval error";
47
48 @Override
49 public String getConfiguration(String type) {
50 DriverHandler handler = handler();
51 NetconfController controller = handler.get(NetconfController.class);
52 DeviceId ofDeviceId = handler.data().deviceId();
53 Preconditions.checkNotNull(controller, "Netconf controller is null");
54 try {
55 return controller.getDevicesMap().
56 get(ofDeviceId).
57 getSession().
58 getConfig(type);
59 } catch (IOException e) {
60 log.error("Configuration could not be retrieved {}",
Andrea Campanella950310c2016-02-12 18:14:38 -080061 e.getMessage());
Aaron Kruglikov12faf8d2016-01-04 16:24:07 -080062 }
63 return UNABLE_TO_READ_CONFIG;
64 }
65
66}