Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [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; |
| 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; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.region.RegionAdminService; |
| 24 | import org.onosproject.net.region.RegionId; |
| 25 | |
| 26 | import java.util.List; |
| 27 | import java.util.stream.Collectors; |
| 28 | |
| 29 | /** |
| 30 | * Remove a set of devices from existing region. |
| 31 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 32 | @Service |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 33 | @Command(scope = "onos", name = "region-remove-devices", |
| 34 | description = "Removes a set of devices from the region.") |
| 35 | public class RegionRemoveDevicesCommand extends AbstractShellCommand { |
| 36 | |
| 37 | @Argument(index = 0, name = "id", description = "Region ID", |
| 38 | required = true, multiValued = false) |
| 39 | String id = null; |
| 40 | |
| 41 | @Argument(index = 1, name = "devIds", description = "Device IDs", |
| 42 | required = true, multiValued = true) |
| 43 | List<String> devIds = null; |
| 44 | |
| 45 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 46 | protected void doExecute() { |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 47 | RegionAdminService service = get(RegionAdminService.class); |
| 48 | RegionId regionId = RegionId.regionId(id); |
| 49 | |
| 50 | List<DeviceId> dids = devIds.stream().map(s -> |
| 51 | DeviceId.deviceId(s)).collect(Collectors.toList()); |
| 52 | |
| 53 | service.removeDevices(regionId, dids); |
| 54 | } |
| 55 | } |