Harold Huang | 222c6ec | 2017-06-02 15:02:49 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Harold Huang | 222c6ec | 2017-06-02 15:02:49 +0800 | [diff] [blame] | 3 | * |
| 4 | * 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 |
| 7 | * |
| 8 | * 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. |
| 15 | */ |
| 16 | package org.onosproject.cli.net.vnet; |
| 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Harold Huang | 222c6ec | 2017-06-02 15:02:49 +0800 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 24 | import org.onosproject.incubator.net.virtual.VirtualNetworkService; |
| 25 | import org.onosproject.mastership.MastershipAdminService; |
| 26 | |
| 27 | /** |
| 28 | * Forces virtual network device mastership rebalancing. |
| 29 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 30 | @Service |
Harold Huang | 222c6ec | 2017-06-02 15:02:49 +0800 | [diff] [blame] | 31 | @Command(scope = "onos", name = "vnet-balance-masters", |
| 32 | description = "Forces virtual network device mastership rebalancing") |
| 33 | public class VirtualNetworkBalanceMastersCommand extends AbstractShellCommand { |
| 34 | @Argument(index = 0, name = "networkId", description = "Network ID", |
| 35 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 36 | @Completion(VirtualNetworkCompleter.class) |
Harold Huang | 222c6ec | 2017-06-02 15:02:49 +0800 | [diff] [blame] | 37 | Long networkId = null; |
| 38 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 39 | protected void doExecute() { |
Harold Huang | 222c6ec | 2017-06-02 15:02:49 +0800 | [diff] [blame] | 40 | VirtualNetworkService vnetService = get(VirtualNetworkService.class); |
| 41 | MastershipAdminService mastershipAdminService = vnetService |
| 42 | .get(NetworkId.networkId(networkId), MastershipAdminService.class); |
| 43 | mastershipAdminService.balanceRoles(); |
| 44 | } |
| 45 | } |