blob: 739b515aa333ae00bf6ca1cca8e6176982885184 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
tom5f35f7c2014-09-08 18:38:19 -070017
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.cluster.NodeId;
22import org.onosproject.mastership.MastershipAdminService;
23import org.onosproject.net.MastershipRole;
tomb41d1ac2014-09-24 01:51:24 -070024
Madan Jampania776fe22015-08-05 07:02:03 +053025import com.google.common.util.concurrent.Futures;
26
Brian O'Connorabafb502014-12-02 22:26:20 -080027import static org.onosproject.net.DeviceId.deviceId;
tom5f35f7c2014-09-08 18:38:19 -070028
29/**
30 * Sets role of the controller node for the given infrastructure device.
31 */
32@Command(scope = "onos", name = "device-role",
33 description = "Sets role of the controller node for the given infrastructure device")
34public class DeviceRoleCommand extends AbstractShellCommand {
35
36 @Argument(index = 0, name = "uri", description = "Device ID",
37 required = true, multiValued = false)
38 String uri = null;
39
tomb41d1ac2014-09-24 01:51:24 -070040 @Argument(index = 1, name = "node", description = "Node ID",
41 required = true, multiValued = false)
42 String node = null;
43
44 @Argument(index = 2, name = "role", description = "Mastership role",
tom5f35f7c2014-09-08 18:38:19 -070045 required = true, multiValued = false)
46 String role = null;
47
48 @Override
tom0872a172014-09-23 11:24:26 -070049 protected void execute() {
tomb41d1ac2014-09-24 01:51:24 -070050 MastershipAdminService service = get(MastershipAdminService.class);
tom5f35f7c2014-09-08 18:38:19 -070051 MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
Madan Jampania776fe22015-08-05 07:02:03 +053052 Futures.getUnchecked(service.setRole(new NodeId(node), deviceId(uri), mastershipRole));
tom5f35f7c2014-09-08 18:38:19 -070053 }
54
55}