blob: 91b011bbeba263bd6d41dcee42b08dedea45b884 [file] [log] [blame]
Jian Li3ba5c582021-01-14 11:30:36 +09001/*
2 * Copyright 2021-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.kubevirtnetworking.cli;
17
18import org.apache.karaf.shell.api.action.lifecycle.Service;
19import org.apache.karaf.shell.api.console.CommandLine;
20import org.apache.karaf.shell.api.console.Completer;
21import org.apache.karaf.shell.api.console.Session;
22import org.apache.karaf.shell.support.completers.StringsCompleter;
23import org.onosproject.kubevirtnetworking.api.KubevirtNetwork;
24import org.onosproject.kubevirtnetworking.api.KubevirtNetworkService;
25
26import java.util.List;
27import java.util.Set;
28import java.util.SortedSet;
29import java.util.stream.Collectors;
30
31import static org.onosproject.cli.AbstractShellCommand.get;
32
33/**
34 * Kubevirt network ID completer.
35 */
36@Service
37public class KubevirtNetworkIdCompleter implements Completer {
38 @Override
39 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
40 StringsCompleter delegate = new StringsCompleter();
41 KubevirtNetworkService networkService = get(KubevirtNetworkService.class);
42
43 Set<String> netIds = networkService.networks().stream().map(KubevirtNetwork::networkId)
44 .collect(Collectors.toSet());
45 SortedSet<String> strings = delegate.getStrings();
46
47 strings.addAll(netIds);
48
49 return delegate.complete(session, commandLine, candidates);
50 }
51}