andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [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.ControllerConfig; |
| 23 | import org.onosproject.net.driver.DriverHandler; |
| 24 | import org.onosproject.net.driver.DriverService; |
| 25 | |
| 26 | /** |
| 27 | * Sets role of the controller node for the given infrastructure device. |
| 28 | */ |
| 29 | @Command(scope = "onos", name = "device-controllers", |
| 30 | description = "gets the list of controllers for the given infrastructure device") |
| 31 | public class DeviceControllersCommand extends AbstractShellCommand { |
| 32 | |
| 33 | @Argument(index = 0, name = "uri", description = "Device ID", |
| 34 | required = true, multiValued = false) |
| 35 | String uri = null; |
| 36 | private DeviceId deviceId; |
| 37 | |
| 38 | @Override |
| 39 | protected void execute() { |
| 40 | DriverService service = get(DriverService.class); |
| 41 | deviceId = DeviceId.deviceId(uri); |
| 42 | DriverHandler h = service.createHandler(deviceId); |
| 43 | ControllerConfig config = h.behaviour(ControllerConfig.class); |
| 44 | config.getControllers().forEach(c -> print(c.target())); |
| 45 | } |
| 46 | |
| 47 | } |