blob: a5fdb3f9c44287b8ba4299a90985e27ff758c196 [file] [log] [blame]
tom5f35f7c2014-09-08 18:38:19 -07001package org.onlab.onos.cli.net;
2
3import org.apache.karaf.shell.commands.Argument;
4import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.cli.AbstractShellCommand;
tomb41d1ac2014-09-24 01:51:24 -07006import org.onlab.onos.cluster.NodeId;
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07007import org.onlab.onos.mastership.MastershipAdminService;
tom5f35f7c2014-09-08 18:38:19 -07008import org.onlab.onos.net.MastershipRole;
tomb41d1ac2014-09-24 01:51:24 -07009
10import static org.onlab.onos.net.DeviceId.deviceId;
tom5f35f7c2014-09-08 18:38:19 -070011
12/**
13 * Sets role of the controller node for the given infrastructure device.
14 */
15@Command(scope = "onos", name = "device-role",
16 description = "Sets role of the controller node for the given infrastructure device")
17public class DeviceRoleCommand extends AbstractShellCommand {
18
19 @Argument(index = 0, name = "uri", description = "Device ID",
20 required = true, multiValued = false)
21 String uri = null;
22
tomb41d1ac2014-09-24 01:51:24 -070023 @Argument(index = 1, name = "node", description = "Node ID",
24 required = true, multiValued = false)
25 String node = null;
26
27 @Argument(index = 2, name = "role", description = "Mastership role",
tom5f35f7c2014-09-08 18:38:19 -070028 required = true, multiValued = false)
29 String role = null;
30
31 @Override
tom0872a172014-09-23 11:24:26 -070032 protected void execute() {
tomb41d1ac2014-09-24 01:51:24 -070033 MastershipAdminService service = get(MastershipAdminService.class);
tom5f35f7c2014-09-08 18:38:19 -070034 MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
tomb41d1ac2014-09-24 01:51:24 -070035 service.setRole(new NodeId(node), deviceId(uri), mastershipRole);
tom5f35f7c2014-09-08 18:38:19 -070036 }
37
38}