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 2016-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; |
Ray Milkey | ec20a29 | 2018-10-11 15:53:33 -0700 | [diff] [blame^] | 20 | import org.apache.karaf.shell.api.action.Completion; |
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; |
Ray Milkey | ec20a29 | 2018-10-11 15:53:33 -0700 | [diff] [blame^] | 23 | import org.onosproject.cli.net.DeviceIdCompleter; |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.behaviour.ConfigSetter; |
| 26 | import org.onosproject.net.driver.DriverHandler; |
| 27 | import org.onosproject.net.driver.DriverService; |
| 28 | |
| 29 | import 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 Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 41 | @Service |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 42 | @Command(scope = "onos", name = "netconf-rpc-test", |
| 43 | description = "Debug tool to send NETCONF RPC request") |
| 44 | public 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 Milkey | ec20a29 | 2018-10-11 15:53:33 -0700 | [diff] [blame^] | 52 | @Completion(DeviceIdCompleter.class) |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 53 | private String cfgFile = null; |
| 54 | |
| 55 | private DeviceId deviceId; |
| 56 | |
| 57 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 58 | protected void doExecute() { |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 59 | 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 | } |