blob: f15b58c15ceec0fe7892629b742a597381670681 [file] [log] [blame]
Aaron Kruglikov7adb89e2016-01-06 15:21:28 -08001/*
2 * Copyright 2015-2016 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
Aaron Kruglikov12faf8d2016-01-04 16:24:07 -080017package org.onosproject.driver.netconf;
18
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.
34 *
35 * This is a temporary development tool for use until yang integration is complete.
36 * This is not a properly specified behavior implementation. DO NOT USE AS AN EXAMPLE.
37 */
38//FIXME this should eventually be removed.
39
40public class NetconfConfigGetter extends AbstractHandlerBehaviour
41 implements ConfigGetter {
42
43 private final Logger log = getLogger(NetconfControllerConfig.class);
44
45 //FIXME the error string should be universal for all implementations of
46 // ConfigGetter
47 public static final String UNABLE_TO_READ_CONFIG = "config retrieval error";
48
49 @Override
50 public String getConfiguration(String type) {
51 DriverHandler handler = handler();
52 NetconfController controller = handler.get(NetconfController.class);
53 DeviceId ofDeviceId = handler.data().deviceId();
54 Preconditions.checkNotNull(controller, "Netconf controller is null");
55 try {
56 return controller.getDevicesMap().
57 get(ofDeviceId).
58 getSession().
59 getConfig(type);
60 } catch (IOException e) {
61 log.error("Configuration could not be retrieved {}",
62 e.getStackTrace().toString());
63 }
64 return UNABLE_TO_READ_CONFIG;
65 }
66
67}