Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [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.provider.nil.cli; |
| 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 | d543518 | 2018-10-11 16:18:51 -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; |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
Ray Milkey | d543518 | 2018-10-11 16:18:51 -0700 | [diff] [blame] | 23 | import org.onosproject.cli.UpDownCompleter; |
| 24 | import org.onosproject.cli.net.DeviceIdCompleter; |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.provider.nil.NullProviders; |
| 27 | |
| 28 | import static org.onosproject.cli.UpDownCompleter.DOWN; |
| 29 | import static org.onosproject.cli.UpDownCompleter.UP; |
| 30 | |
| 31 | /** |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 32 | * Downs or repairs a simulated device. |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 33 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 34 | @Service |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 35 | @Command(scope = "onos", name = "null-device", |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 36 | description = "Downs or repairs a simulated device") |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 37 | public class NullDeviceCommand extends AbstractShellCommand { |
| 38 | |
| 39 | @Argument(index = 0, name = "id", description = "Device identifier", |
| 40 | required = true, multiValued = false) |
Ray Milkey | d543518 | 2018-10-11 16:18:51 -0700 | [diff] [blame] | 41 | @Completion(DeviceIdCompleter.class) |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 42 | String id = null; |
| 43 | |
| 44 | @Argument(index = 1, name = "cmd", description = "up/down", |
| 45 | required = true, multiValued = false) |
Ray Milkey | d543518 | 2018-10-11 16:18:51 -0700 | [diff] [blame] | 46 | @Completion(UpDownCompleter.class) |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 47 | String cmd = null; |
| 48 | |
| 49 | |
| 50 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 51 | protected void doExecute() { |
Thomas Vachuska | 8e038eb | 2016-02-23 23:28:23 -0800 | [diff] [blame] | 52 | NullProviders service = get(NullProviders.class); |
| 53 | DeviceId deviceId = DeviceId.deviceId(id); |
| 54 | |
| 55 | if (cmd.equals(UP)) { |
| 56 | service.repairDevice(deviceId); |
| 57 | } else if (cmd.equals(DOWN)) { |
| 58 | service.failDevice(deviceId); |
| 59 | } else { |
| 60 | error("Illegal command %s; must be up or down", cmd); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | } |