blob: bb68be8ec39ae7233f1b8aca188b6c4a977ea0dc [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.cluster.NodeId;
23import org.onosproject.mastership.MastershipAdminService;
24import org.onosproject.net.MastershipRole;
tomb41d1ac2014-09-24 01:51:24 -070025
Madan Jampania776fe22015-08-05 07:02:03 +053026import com.google.common.util.concurrent.Futures;
27
Brian O'Connorabafb502014-12-02 22:26:20 -080028import static org.onosproject.net.DeviceId.deviceId;
tom5f35f7c2014-09-08 18:38:19 -070029
30/**
31 * Sets role of the controller node for the given infrastructure device.
32 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033@Service
tom5f35f7c2014-09-08 18:38:19 -070034@Command(scope = "onos", name = "device-role",
35 description = "Sets role of the controller node for the given infrastructure device")
36public class DeviceRoleCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "uri", description = "Device ID",
39 required = true, multiValued = false)
40 String uri = null;
41
tomb41d1ac2014-09-24 01:51:24 -070042 @Argument(index = 1, name = "node", description = "Node ID",
43 required = true, multiValued = false)
44 String node = null;
45
46 @Argument(index = 2, name = "role", description = "Mastership role",
tom5f35f7c2014-09-08 18:38:19 -070047 required = true, multiValued = false)
48 String role = null;
49
50 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070051 protected void doExecute() {
tomb41d1ac2014-09-24 01:51:24 -070052 MastershipAdminService service = get(MastershipAdminService.class);
tom5f35f7c2014-09-08 18:38:19 -070053 MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
Madan Jampania776fe22015-08-05 07:02:03 +053054 Futures.getUnchecked(service.setRole(new NodeId(node), deviceId(uri), mastershipRole));
tom5f35f7c2014-09-08 18:38:19 -070055 }
56
57}