blob: 16251d27ca8f845dbcc21522f28da1003e2bb25e [file] [log] [blame]
Jian Liee039592019-08-26 14:54:43 +09001/*
2 * Copyright 2019-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.k8snetworking.cli;
17
18import org.apache.karaf.shell.api.console.CommandLine;
19import org.apache.karaf.shell.api.console.Completer;
20import org.apache.karaf.shell.api.console.Session;
21import org.apache.karaf.shell.support.completers.StringsCompleter;
22import org.onosproject.k8snetworking.api.K8sNetwork;
23import org.onosproject.k8snetworking.api.K8sNetworkService;
24
25import java.util.List;
26import java.util.Set;
27import java.util.SortedSet;
28import java.util.stream.Collectors;
29
30import static org.onosproject.cli.AbstractShellCommand.get;
31
32/**
33 * Kubernetes network ID completer.
34 */
35public class K8sNetworkIdCompleter implements Completer {
36 @Override
37 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
38 StringsCompleter delegate = new StringsCompleter();
39 K8sNetworkService networkService = get(K8sNetworkService.class);
40
41 Set<String> netNames = networkService.networks().stream().map(K8sNetwork::name)
42 .collect(Collectors.toSet());
43 SortedSet<String> strings = delegate.getStrings();
44
45 strings.addAll(netNames);
46
47 return delegate.complete(session, commandLine, candidates);
48 }
49}