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; |
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; |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.region.RegionAdminService; |
| 25 | import org.onosproject.net.region.RegionId; |
| 26 | |
| 27 | import java.util.List; |
| 28 | import java.util.stream.Collectors; |
| 29 | |
| 30 | /** |
| 31 | * Add a set of devices into existing region. |
| 32 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 33 | @Service |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 34 | @Command(scope = "onos", name = "region-add-devices", |
| 35 | description = "Adds a set of devices into the region.") |
| 36 | public class RegionAddDevicesCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "id", description = "Region ID", |
| 39 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 40 | @Completion(RegionIdCompleter.class) |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 41 | String id = null; |
| 42 | |
| 43 | @Argument(index = 1, name = "devIds", description = "Device IDs", |
| 44 | required = true, multiValued = true) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 45 | @Completion(DeviceIdCompleter.class) |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 46 | List<String> devIds = null; |
| 47 | |
| 48 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 49 | protected void doExecute() { |
Jian Li | cf74444 | 2016-02-25 17:32:42 +0900 | [diff] [blame] | 50 | RegionAdminService service = get(RegionAdminService.class); |
| 51 | RegionId regionId = RegionId.regionId(id); |
| 52 | |
| 53 | List<DeviceId> dids = devIds.stream().map(s -> |
| 54 | DeviceId.deviceId(s)).collect(Collectors.toList()); |
| 55 | |
| 56 | service.addDevices(regionId, dids); |
| 57 | } |
| 58 | } |