Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 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 | package org.onosproject.netconf.cli.impl; |
| 17 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.Option; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.cli.net.DeviceIdCompleter; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.netconf.NetconfController; |
| 26 | import org.onosproject.netconf.NetconfDevice; |
| 27 | import org.onosproject.netconf.NetconfException; |
| 28 | |
| 29 | /** |
| 30 | * Debug command to start subscription on specified device. |
| 31 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame^] | 32 | @Service |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 33 | @Command(scope = "onos", name = "netconf-subscription-test", |
| 34 | description = "Debug command to start subscription on specified device") |
| 35 | public class NetconfSubscriptionTestCommand extends AbstractShellCommand { |
| 36 | |
| 37 | // for OSGi |
| 38 | DeviceIdCompleter uriCompleter; |
| 39 | |
| 40 | @Argument(index = 0, name = "deviceId", description = "Device ID", |
| 41 | required = true, multiValued = false) |
| 42 | String uri = null; |
| 43 | |
| 44 | @Option(name = "--end", |
| 45 | description = "Ends subscription instead of starting", |
| 46 | required = false) |
| 47 | boolean end = false; |
| 48 | |
| 49 | |
| 50 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 51 | protected void doExecute() { |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 52 | NetconfController controller = get(NetconfController.class); |
| 53 | DeviceId did = DeviceId.deviceId(uri); |
| 54 | |
| 55 | NetconfDevice netconfDevice = controller.getNetconfDevice(did); |
| 56 | if (netconfDevice == null) { |
Yuta HIGUCHI | d31bc6e | 2017-05-03 17:23:34 -0700 | [diff] [blame] | 57 | print("%s not found or not connected to this node", did); |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | |
| 61 | if (!end) { |
| 62 | try { |
| 63 | netconfDevice.getSession().startSubscription(); |
| 64 | } catch (NetconfException e) { |
| 65 | log.error("Exception thrown", e); |
| 66 | print("starting subscription failed (see log for details)"); |
| 67 | } |
| 68 | } else { |
| 69 | try { |
| 70 | netconfDevice.getSession().endSubscription(); |
| 71 | } catch (NetconfException e) { |
| 72 | log.error("Exception thrown", e); |
| 73 | print("ending subscription failed (see log for details)"); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | } |