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