blob: c2ded32037b1693469c0a901b9143dae5f08c887 [file] [log] [blame]
Kieran McPeake9e64ab52019-06-07 10:22:29 +01001/*
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
17package org.onosproject.drivers.juniper;
18
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.driver.AbstractHandlerBehaviour;
21import org.onosproject.netconf.NetconfController;
22import org.onosproject.netconf.NetconfDevice;
23import org.onosproject.netconf.NetconfSession;
24import org.slf4j.Logger;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27import static org.slf4j.LoggerFactory.getLogger;
28
29public 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}