blob: 03d5f26e73e6b6e5c6963a115066cbd6af3f904d [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;
Ray Milkey0068fd02018-10-11 15:45:39 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.cli.AbstractShellCommand;
Ray Milkey0068fd02018-10-11 15:45:39 -070023import org.onosproject.cli.NodeIdCompleter;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.cluster.NodeId;
25import org.onosproject.mastership.MastershipAdminService;
26import org.onosproject.net.MastershipRole;
tomb41d1ac2014-09-24 01:51:24 -070027
Madan Jampania776fe22015-08-05 07:02:03 +053028import com.google.common.util.concurrent.Futures;
29
Brian O'Connorabafb502014-12-02 22:26:20 -080030import static org.onosproject.net.DeviceId.deviceId;
tom5f35f7c2014-09-08 18:38:19 -070031
32/**
33 * Sets role of the controller node for the given infrastructure device.
34 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070035@Service
tom5f35f7c2014-09-08 18:38:19 -070036@Command(scope = "onos", name = "device-role",
37 description = "Sets role of the controller node for the given infrastructure device")
38public class DeviceRoleCommand extends AbstractShellCommand {
39
40 @Argument(index = 0, name = "uri", description = "Device ID",
41 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070042 @Completion(DeviceIdCompleter.class)
tom5f35f7c2014-09-08 18:38:19 -070043 String uri = null;
44
tomb41d1ac2014-09-24 01:51:24 -070045 @Argument(index = 1, name = "node", description = "Node ID",
46 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070047 @Completion(NodeIdCompleter.class)
tomb41d1ac2014-09-24 01:51:24 -070048 String node = null;
49
50 @Argument(index = 2, name = "role", description = "Mastership role",
tom5f35f7c2014-09-08 18:38:19 -070051 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070052 @Completion(RoleCompleter.class)
tom5f35f7c2014-09-08 18:38:19 -070053 String role = null;
54
55 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070056 protected void doExecute() {
tomb41d1ac2014-09-24 01:51:24 -070057 MastershipAdminService service = get(MastershipAdminService.class);
tom5f35f7c2014-09-08 18:38:19 -070058 MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
Madan Jampania776fe22015-08-05 07:02:03 +053059 Futures.getUnchecked(service.setRole(new NodeId(node), deviceId(uri), mastershipRole));
tom5f35f7c2014-09-08 18:38:19 -070060 }
61
62}