blob: 3036c7046339af3a7410cad3670f139c5302b0f2 [file] [log] [blame]
Brian Stanke5df14472016-03-11 19:34:38 -05001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Brian Stanke5df14472016-03-11 19:34:38 -05003 *
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
17package org.onosproject.cli.net.vnet;
18
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.incubator.net.virtual.TenantId;
22import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService;
23import org.onosproject.utils.Comparators;
24
25import java.util.ArrayList;
26import java.util.Collections;
27import java.util.List;
28
29/**
30 * Lists all tenants.
31 */
32@Command(scope = "onos", name = "vnet-tenants",
33 description = "Lists all virtual network tenants.")
34public class TenantListCommand extends AbstractShellCommand {
35
36 private static final String FMT_TENANT = "tenantId=%s";
37
38 @Override
39 protected void execute() {
40 VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
41 List<TenantId> tenants = new ArrayList<>();
42 tenants.addAll(service.getTenantIds());
43 Collections.sort(tenants, Comparators.TENANT_ID_COMPARATOR);
44
45 tenants.forEach(this::printTenant);
46 }
47
48 private void printTenant(TenantId tenantId) {
49 print(FMT_TENANT, tenantId.id());
50 }
51}