blob: 89560606ea0516e3e6ed7e61cc473456b2f3c479 [file] [log] [blame]
Aaron Kruglikov12faf8d2016-01-04 16:24:07 -08001package org.onosproject.driver.netconf;
2
3import com.google.common.base.Preconditions;
4import org.onosproject.net.DeviceId;
5import org.onosproject.net.behaviour.ConfigGetter;
6import org.onosproject.net.driver.AbstractHandlerBehaviour;
7import org.onosproject.net.driver.DriverHandler;
8import org.onosproject.netconf.NetconfController;
9import org.slf4j.Logger;
10
11import java.io.IOException;
12
13import static org.slf4j.LoggerFactory.getLogger;
14
15/**
16 * Gets the configuration of the specified type from the specified device. If a
17 * failure occurs it returns the error string found in UNABLE_TO_READ_CONFIG.
18 *
19 * This is a temporary development tool for use until yang integration is complete.
20 * This is not a properly specified behavior implementation. DO NOT USE AS AN EXAMPLE.
21 */
22//FIXME this should eventually be removed.
23
24public class NetconfConfigGetter extends AbstractHandlerBehaviour
25 implements ConfigGetter {
26
27 private final Logger log = getLogger(NetconfControllerConfig.class);
28
29 //FIXME the error string should be universal for all implementations of
30 // ConfigGetter
31 public static final String UNABLE_TO_READ_CONFIG = "config retrieval error";
32
33 @Override
34 public String getConfiguration(String type) {
35 DriverHandler handler = handler();
36 NetconfController controller = handler.get(NetconfController.class);
37 DeviceId ofDeviceId = handler.data().deviceId();
38 Preconditions.checkNotNull(controller, "Netconf controller is null");
39 try {
40 return controller.getDevicesMap().
41 get(ofDeviceId).
42 getSession().
43 getConfig(type);
44 } catch (IOException e) {
45 log.error("Configuration could not be retrieved {}",
46 e.getStackTrace().toString());
47 }
48 return UNABLE_TO_READ_CONFIG;
49 }
50
51}