Aaron Kruglikov | 12faf8d | 2016-01-04 16:24:07 -0800 | [diff] [blame^] | 1 | package org.onosproject.driver.netconf; |
| 2 | |
| 3 | import com.google.common.base.Preconditions; |
| 4 | import org.onosproject.net.DeviceId; |
| 5 | import org.onosproject.net.behaviour.ConfigGetter; |
| 6 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 7 | import org.onosproject.net.driver.DriverHandler; |
| 8 | import org.onosproject.netconf.NetconfController; |
| 9 | import org.slf4j.Logger; |
| 10 | |
| 11 | import java.io.IOException; |
| 12 | |
| 13 | import 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 | |
| 24 | public 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 | } |