Kieran McPeake | 9e64ab5 | 2019-06-07 10:22:29 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.drivers.juniper; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 21 | import org.onosproject.netconf.NetconfController; |
| 22 | import org.onosproject.netconf.NetconfDevice; |
| 23 | import org.onosproject.netconf.NetconfSession; |
| 24 | import org.slf4j.Logger; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | import static org.slf4j.LoggerFactory.getLogger; |
| 28 | |
| 29 | public class JuniperAbstractHandlerBehaviour extends AbstractHandlerBehaviour { |
| 30 | |
| 31 | private static final Logger log = getLogger(JuniperAbstractHandlerBehaviour.class); |
| 32 | |
| 33 | /** |
| 34 | * Lookup the current NETCONF session for specified device. |
| 35 | * @param deviceId id of device |
| 36 | * @return the current session (which may be null) |
| 37 | */ |
| 38 | NetconfSession lookupNetconfSession(final DeviceId deviceId) { |
| 39 | NetconfController controller = checkNotNull(handler().get(NetconfController.class)); |
| 40 | final NetconfDevice netconfDevice = controller.getDevicesMap().get(deviceId); |
| 41 | |
| 42 | if (netconfDevice == null) { |
| 43 | log.warn("NETCONF session to device {} not yet established, can be retried", deviceId); |
| 44 | return null; |
| 45 | } |
| 46 | |
| 47 | return netconfDevice.getSession(); |
| 48 | } |
| 49 | |
| 50 | } |