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 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.region.RegionAdminService; |
| 23 | import org.onosproject.net.region.RegionId; |
| 24 | |
| 25 | import java.util.List; |
| 26 | import java.util.stream.Collectors; |
| 27 | |
| 28 | /** |
| 29 | * Add a set of devices into existing region. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "region-add-devices", |
| 32 | description = "Adds a set of devices into the region.") |
| 33 | public class RegionAddDevicesCommand extends AbstractShellCommand { |
| 34 | |
| 35 | @Argument(index = 0, name = "id", description = "Region ID", |
| 36 | required = true, multiValued = false) |
| 37 | String id = null; |
| 38 | |
| 39 | @Argument(index = 1, name = "devIds", description = "Device IDs", |
| 40 | required = true, multiValued = true) |
| 41 | List<String> devIds = null; |
| 42 | |
| 43 | @Override |
| 44 | protected void execute() { |
| 45 | RegionAdminService service = get(RegionAdminService.class); |
| 46 | RegionId regionId = RegionId.regionId(id); |
| 47 | |
| 48 | List<DeviceId> dids = devIds.stream().map(s -> |
| 49 | DeviceId.deviceId(s)).collect(Collectors.toList()); |
| 50 | |
| 51 | service.addDevices(regionId, dids); |
| 52 | } |
| 53 | } |