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