blob: 69557f572fb3b780715b5c3cefdfce6d9df60e7a [file] [log] [blame]
Thomas Vachuska8e038eb2016-02-23 23:28:23 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska8e038eb2016-02-23 23:28:23 -08003 *
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.provider.nil.cli;
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 Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuska8e038eb2016-02-23 23:28:23 -080021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.onosproject.provider.nil.NullProviders;
24
25import static org.onosproject.cli.UpDownCompleter.DOWN;
26import static org.onosproject.cli.UpDownCompleter.UP;
27
28/**
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020029 * Downs or repairs a simulated device.
Thomas Vachuska8e038eb2016-02-23 23:28:23 -080030 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070031@Service
Thomas Vachuska8e038eb2016-02-23 23:28:23 -080032@Command(scope = "onos", name = "null-device",
Thomas Vachuska5c6ed222016-06-29 11:02:22 +020033 description = "Downs or repairs a simulated device")
Thomas Vachuska8e038eb2016-02-23 23:28:23 -080034public class NullDeviceCommand extends AbstractShellCommand {
35
36 @Argument(index = 0, name = "id", description = "Device identifier",
37 required = true, multiValued = false)
38 String id = null;
39
40 @Argument(index = 1, name = "cmd", description = "up/down",
41 required = true, multiValued = false)
42 String cmd = null;
43
44
45 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070046 protected void doExecute() {
Thomas Vachuska8e038eb2016-02-23 23:28:23 -080047 NullProviders service = get(NullProviders.class);
48 DeviceId deviceId = DeviceId.deviceId(id);
49
50 if (cmd.equals(UP)) {
51 service.repairDevice(deviceId);
52 } else if (cmd.equals(DOWN)) {
53 service.failDevice(deviceId);
54 } else {
55 error("Illegal command %s; must be up or down", cmd);
56 }
57 }
58
59}