blob: 63306b48d745a13d402e9fa8c9478a618c7c4a0b [file] [log] [blame]
oleksandr.yashchuk@plvision.eu3dbcaaf2019-03-13 14:44:46 +02001/*
2 * Copyright 2019-present Open Networking Foundation
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 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.Completion;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.Device;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.device.DeviceService;
26import org.onosproject.net.behaviour.BasicSystemOperations;
27
28/**
29 * Administratively reboots device.
30 */
31@Service
32@Command(scope = "onos", name = "device-reboot",
33 description = "Administratively reboots a device")
34public class DeviceRebootCommand extends AbstractShellCommand {
35 @Argument(index = 0, name = "deviceId", description = "Device ID",
36 required = true, multiValued = false)
37 @Completion(DeviceIdCompleter.class)
38 String deviceId = null;
39
40 @Override
41 protected void doExecute() {
42 Device dev = get(DeviceService.class).getDevice(DeviceId.deviceId(deviceId));
43 if (dev == null) {
44 print(" %s", "Device does not exist");
45 return;
46 }
47
48 if (dev.is(BasicSystemOperations.class)) {
49 print("Reboot for the device %s issued", deviceId);
50 dev.as(BasicSystemOperations.class)
51 .reboot().whenComplete((future, error) -> {
52 if (error == null) {
53 print("Reboot for the device %s succeed.", deviceId);
54 } else {
55 log.error("Exception while rebooting device " + deviceId, error);
56 }
57 });
58
59 } else {
60 log.error("Device does not support {} behaviour", BasicSystemOperations.class.getName());
61 }
62 }
63}