blob: 2da13fe386326571c67bf1251bdc9923181439b4 [file] [log] [blame]
Jian Licf744442016-02-25 17:32:42 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Licf744442016-02-25 17:32:42 +09003 *
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 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.region.RegionAdminService;
23import org.onosproject.net.region.RegionId;
24
25import java.util.List;
26import 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.")
33public 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}