Aaron Kruglikov | 7adb89e | 2016-01-06 15:21:28 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 17 | package org.onosproject.drivers.netconf; |
Aaron Kruglikov | 12faf8d | 2016-01-04 16:24:07 -0800 | [diff] [blame] | 18 | |
| 19 | import com.google.common.base.Preconditions; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.behaviour.ConfigGetter; |
| 22 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 23 | import org.onosproject.net.driver.DriverHandler; |
| 24 | import org.onosproject.netconf.NetconfController; |
| 25 | import org.slf4j.Logger; |
| 26 | |
| 27 | import java.io.IOException; |
| 28 | |
| 29 | import 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 Kruglikov | 12faf8d | 2016-01-04 16:24:07 -0800 | [diff] [blame] | 34 | * 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 | |
| 39 | public class NetconfConfigGetter extends AbstractHandlerBehaviour |
| 40 | implements ConfigGetter { |
| 41 | |
Andrea Campanella | 950310c | 2016-02-12 18:14:38 -0800 | [diff] [blame^] | 42 | private final Logger log = getLogger(getClass()); |
Aaron Kruglikov | 12faf8d | 2016-01-04 16:24:07 -0800 | [diff] [blame] | 43 | |
| 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 Campanella | 950310c | 2016-02-12 18:14:38 -0800 | [diff] [blame^] | 61 | e.getMessage()); |
Aaron Kruglikov | 12faf8d | 2016-01-04 16:24:07 -0800 | [diff] [blame] | 62 | } |
| 63 | return UNABLE_TO_READ_CONFIG; |
| 64 | } |
| 65 | |
| 66 | } |