blob: 2ed04f8f78b4349313faed0c75a83c32b881acfc [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;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Jian Licf744442016-02-25 17:32:42 +090021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.region.RegionAdminService;
24import org.onosproject.net.region.RegionId;
25
26import java.util.List;
27import java.util.stream.Collectors;
28
29/**
30 * Add a set of devices into existing region.
31 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070032@Service
Jian Licf744442016-02-25 17:32:42 +090033@Command(scope = "onos", name = "region-add-devices",
34 description = "Adds a set of devices into the region.")
35public class RegionAddDevicesCommand 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 Milkeyd84f89b2018-08-17 14:54:17 -070046 protected void doExecute() {
Jian Licf744442016-02-25 17:32:42 +090047 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.addDevices(regionId, dids);
54 }
55}