tom | 5f35f7c | 2014-09-08 18:38:19 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onlab.onos.cli.AbstractShellCommand; |
| 6 | import org.onlab.onos.net.DeviceId; |
| 7 | import org.onlab.onos.net.MastershipRole; |
| 8 | import org.onlab.onos.net.device.DeviceAdminService; |
| 9 | |
| 10 | /** |
| 11 | * Sets role of the controller node for the given infrastructure device. |
| 12 | */ |
| 13 | @Command(scope = "onos", name = "device-role", |
| 14 | description = "Sets role of the controller node for the given infrastructure device") |
| 15 | public class DeviceRoleCommand extends AbstractShellCommand { |
| 16 | |
| 17 | @Argument(index = 0, name = "uri", description = "Device ID", |
| 18 | required = true, multiValued = false) |
| 19 | String uri = null; |
| 20 | |
| 21 | @Argument(index = 1, name = "role", description = "Mastership role", |
| 22 | required = true, multiValued = false) |
| 23 | String role = null; |
| 24 | |
| 25 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame^] | 26 | protected void execute() { |
tom | 5f35f7c | 2014-09-08 18:38:19 -0700 | [diff] [blame] | 27 | MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase()); |
| 28 | getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri), |
| 29 | mastershipRole); |
tom | 5f35f7c | 2014-09-08 18:38:19 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | } |