blob: 30113d177d54cdc2b8010b74f5dddc145c697206 [file] [log] [blame]
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-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;
Ray Milkeyec20a292018-10-11 15:53:33 -070020import org.apache.karaf.shell.api.action.Completion;
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;
Ray Milkeyec20a292018-10-11 15:53:33 -070023import org.onosproject.cli.net.DeviceIdCompleter;
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070024import org.onosproject.net.DeviceId;
25import org.onosproject.net.behaviour.ConfigSetter;
26import org.onosproject.net.driver.DriverHandler;
27import org.onosproject.net.driver.DriverService;
28
29import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Command that sets the configuration included in the specified file to the
33 * specified device. It prints the response of the device.
34 *
35 * This is a temporary development tool for use until yang integration is complete.
36 * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
37 */
38//Temporary Developer tool, NOT TO BE USED in production or as example for
39// future commands.
40//FIXME Remove dependency to ConfigSetter.
Ray Milkey7a2dee52018-09-28 10:58:28 -070041@Service
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070042@Command(scope = "onos", name = "netconf-rpc-test",
43 description = "Debug tool to send NETCONF RPC request")
44public class NetconfRpcTestCommand extends AbstractShellCommand {
45
46 @Argument(index = 0, name = "uri", description = "Device ID",
47 required = true, multiValued = false)
48 private String uri = null;
49
50 @Argument(index = 1, name = "cfgFile", description = "File path to RPC XML",
51 required = true, multiValued = false)
Ray Milkeyec20a292018-10-11 15:53:33 -070052 @Completion(DeviceIdCompleter.class)
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070053 private String cfgFile = null;
54
55 private DeviceId deviceId;
56
57 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070058 protected void doExecute() {
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070059 DriverService service = get(DriverService.class);
60 deviceId = DeviceId.deviceId(uri);
61 DriverHandler h = service.createHandler(deviceId);
62 ConfigSetter config = h.behaviour(ConfigSetter.class);
63 checkNotNull(cfgFile, "Configuration file cannot be null");
64 print(config.setConfiguration(cfgFile));
65 }
66
67}