Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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.PortDiscovery; |
| 23 | import org.onosproject.net.driver.DriverHandler; |
| 24 | import org.onosproject.net.driver.DriverService; |
| 25 | |
| 26 | /** |
| 27 | * Command that gets the configuration of the specified type from the specified |
| 28 | * device. If configuration cannot be retrieved it prints an error string. |
| 29 | * |
| 30 | * This is a temporary development tool for use until yang integration is complete. |
| 31 | * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE. |
| 32 | */ |
| 33 | |
| 34 | @Command(scope = "onos", name = "device-ports", |
| 35 | description = "Gets the ports of the specified device.") |
| 36 | public class DevicePortGetterCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "uri", description = "Device ID", |
| 39 | required = true, multiValued = false) |
| 40 | String uri = null; |
| 41 | private DeviceId deviceId; |
| 42 | |
| 43 | @Override |
| 44 | protected void execute() { |
| 45 | DriverService service = get(DriverService.class); |
| 46 | deviceId = DeviceId.deviceId(uri); |
| 47 | DriverHandler h = service.createHandler(deviceId); |
| 48 | PortDiscovery portConfig = h.behaviour(PortDiscovery.class); |
| 49 | print(portConfig.getPorts().toString()); |
| 50 | } |
| 51 | |
| 52 | } |