blob: de58fa555e238f9a3b39cfab426b5bf2054f9698 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.cli.net.DeviceIdCompleter;
24import org.onosproject.net.DeviceId;
25import org.onosproject.netconf.NetconfController;
26import org.onosproject.netconf.NetconfDevice;
27import org.onosproject.netconf.NetconfException;
28
29/**
30 * Debug command to start subscription on specified device.
31 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070032@Service
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070033@Command(scope = "onos", name = "netconf-subscription-test",
34 description = "Debug command to start subscription on specified device")
35public 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 Milkeyd84f89b2018-08-17 14:54:17 -070051 protected void doExecute() {
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070052 NetconfController controller = get(NetconfController.class);
53 DeviceId did = DeviceId.deviceId(uri);
54
55 NetconfDevice netconfDevice = controller.getNetconfDevice(did);
56 if (netconfDevice == null) {
Yuta HIGUCHId31bc6e2017-05-03 17:23:34 -070057 print("%s not found or not connected to this node", did);
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070058 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}