blob: 225582b692afde12f92bf43533a215cb37c631ab [file] [log] [blame]
Jimo Jung14e87bf2018-09-03 16:28:13 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.openstackvtap.cli;
17
18import com.google.common.collect.ImmutableSet;
Ray Milkeyd5425682018-10-23 10:21:33 -070019import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Jimo Jung14e87bf2018-09-03 16:28:13 +090021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.net.DeviceId;
23import org.onosproject.openstacknode.api.OpenstackNode;
24import org.onosproject.openstacknode.api.OpenstackNodeService;
25import org.onosproject.openstackvtap.api.OpenstackVtapAdminService;
26import org.onosproject.openstackvtap.api.OpenstackVtapNetwork;
27
28import java.util.Objects;
29import java.util.Set;
30import java.util.stream.Collectors;
31
32/**
33 * Lists openstack vtap networks.
34 */
Ray Milkeyd5425682018-10-23 10:21:33 -070035@Service
Jimo Jung14e87bf2018-09-03 16:28:13 +090036@Command(scope = "onos", name = "openstack-vtap-network-list",
37 description = "OpenstackVtap network list")
38public class OpenstackVtapNetworkListCommand extends AbstractShellCommand {
39
40 private final OpenstackVtapAdminService osVtapAdminService = get(OpenstackVtapAdminService.class);
41 private final OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
42
43 private static final String FORMAT = "mode [%s], networkId [%d], serverIp [%s]";
44 private static final String FORMAT_NODES = " openstack nodes: %s";
45
46 @Override
Ray Milkeyd5425682018-10-23 10:21:33 -070047 protected void doExecute() {
Jimo Jung14e87bf2018-09-03 16:28:13 +090048 OpenstackVtapNetwork vtapNetwork = osVtapAdminService.getVtapNetwork();
49 if (vtapNetwork != null) {
50 print(FORMAT,
51 vtapNetwork.mode().toString(),
52 vtapNetwork.networkId() != null ? vtapNetwork.networkId() : "N/A",
53 vtapNetwork.serverIp().toString());
54 print(FORMAT_NODES, osNodeNames(osVtapAdminService.getVtapNetworkDevices()));
55 }
56 }
57
58 private Set<String> osNodeNames(Set<DeviceId> deviceIds) {
59 if (deviceIds == null) {
60 return ImmutableSet.of();
61 } else {
62 return deviceIds.parallelStream()
63 .map(osNodeService::node)
64 .filter(Objects::nonNull)
65 .map(OpenstackNode::hostname)
66 .collect(Collectors.toSet());
67 }
68 }
69
70}