Andreas Papazois | c93117d | 2016-01-13 15:19:27 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Andreas Papazois | c93117d | 2016-01-13 15:19:27 +0200 | [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.cli.net; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.behaviour.ConfigSetter; |
| 23 | import org.onosproject.net.driver.DriverHandler; |
| 24 | import org.onosproject.net.driver.DriverService; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Command that sets the configuration included in the specified file to the |
| 30 | * specified device. It prints the response of the device. |
| 31 | * |
| 32 | * This is a temporary development tool for use until yang integration is complete. |
| 33 | * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE. |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 34 | * |
| 35 | * @deprecated in 1.10.0 |
Andreas Papazois | c93117d | 2016-01-13 15:19:27 +0200 | [diff] [blame] | 36 | */ |
| 37 | //Temporary Developer tool, NOT TO BE USED in production or as example for |
| 38 | // future commands. |
| 39 | //FIXME this should eventually be removed. |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 40 | @Deprecated |
Andreas Papazois | c93117d | 2016-01-13 15:19:27 +0200 | [diff] [blame] | 41 | @Command(scope = "onos", name = "device-setconfiguration", |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 42 | description = "[Deprecated]Sets the configuration of the specified file to the " + |
Andreas Papazois | c93117d | 2016-01-13 15:19:27 +0200 | [diff] [blame] | 43 | "specified device.") |
| 44 | public class DeviceConfigSetterCommand extends AbstractShellCommand { |
| 45 | |
| 46 | @Argument(index = 0, name = "uri", description = "Device ID", |
| 47 | required = true, multiValued = false) |
| 48 | private String uri = null; |
| 49 | @Argument(index = 1, name = "cfgFile", description = "Configuration file", |
| 50 | required = true, multiValued = false) |
| 51 | private String cfgFile = null; |
| 52 | private DeviceId deviceId; |
| 53 | |
| 54 | @Override |
| 55 | protected void execute() { |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 56 | print("[WARN] This command was marked deprecated in 1.10.0"); |
Andreas Papazois | c93117d | 2016-01-13 15:19:27 +0200 | [diff] [blame] | 57 | DriverService service = get(DriverService.class); |
| 58 | deviceId = DeviceId.deviceId(uri); |
| 59 | DriverHandler h = service.createHandler(deviceId); |
| 60 | ConfigSetter config = h.behaviour(ConfigSetter.class); |
| 61 | checkNotNull(cfgFile, "Configuration file cannot be null"); |
| 62 | print(config.setConfiguration(cfgFile)); |
| 63 | } |
| 64 | |
| 65 | } |