blob: f7bffe436880c098bc3e03beaf6dc417fae4e29b [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
tom5f35f7c2014-09-08 18:38:19 -070016package org.onlab.onos.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onlab.onos.cli.AbstractShellCommand;
tomb41d1ac2014-09-24 01:51:24 -070021import org.onlab.onos.cluster.NodeId;
Yuta HIGUCHI80912e62014-10-12 00:15:47 -070022import org.onlab.onos.mastership.MastershipAdminService;
tom5f35f7c2014-09-08 18:38:19 -070023import org.onlab.onos.net.MastershipRole;
tomb41d1ac2014-09-24 01:51:24 -070024
25import static org.onlab.onos.net.DeviceId.deviceId;
tom5f35f7c2014-09-08 18:38:19 -070026
27/**
28 * Sets role of the controller node for the given infrastructure device.
29 */
30@Command(scope = "onos", name = "device-role",
31 description = "Sets role of the controller node for the given infrastructure device")
32public class DeviceRoleCommand extends AbstractShellCommand {
33
34 @Argument(index = 0, name = "uri", description = "Device ID",
35 required = true, multiValued = false)
36 String uri = null;
37
tomb41d1ac2014-09-24 01:51:24 -070038 @Argument(index = 1, name = "node", description = "Node ID",
39 required = true, multiValued = false)
40 String node = null;
41
42 @Argument(index = 2, name = "role", description = "Mastership role",
tom5f35f7c2014-09-08 18:38:19 -070043 required = true, multiValued = false)
44 String role = null;
45
46 @Override
tom0872a172014-09-23 11:24:26 -070047 protected void execute() {
tomb41d1ac2014-09-24 01:51:24 -070048 MastershipAdminService service = get(MastershipAdminService.class);
tom5f35f7c2014-09-08 18:38:19 -070049 MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
tomb41d1ac2014-09-24 01:51:24 -070050 service.setRole(new NodeId(node), deviceId(uri), mastershipRole);
tom5f35f7c2014-09-08 18:38:19 -070051 }
52
53}