blob: c8795982eb9992afc765563508998e97d55ff78e [file] [log] [blame]
Jian Licf744442016-02-25 17:32:42 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey0068fd02018-10-11 15:45:39 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Jian Licf744442016-02-25 17:32:42 +090022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.region.RegionAdminService;
25import org.onosproject.net.region.RegionId;
26
27import java.util.List;
28import java.util.stream.Collectors;
29
30/**
31 * Add a set of devices into existing region.
32 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033@Service
Jian Licf744442016-02-25 17:32:42 +090034@Command(scope = "onos", name = "region-add-devices",
35 description = "Adds a set of devices into the region.")
36public class RegionAddDevicesCommand extends AbstractShellCommand {
37
38 @Argument(index = 0, name = "id", description = "Region ID",
39 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070040 @Completion(RegionIdCompleter.class)
Jian Licf744442016-02-25 17:32:42 +090041 String id = null;
42
43 @Argument(index = 1, name = "devIds", description = "Device IDs",
44 required = true, multiValued = true)
Ray Milkey0068fd02018-10-11 15:45:39 -070045 @Completion(DeviceIdCompleter.class)
Jian Licf744442016-02-25 17:32:42 +090046 List<String> devIds = null;
47
48 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070049 protected void doExecute() {
Jian Licf744442016-02-25 17:32:42 +090050 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}