blob: 4d311c8995ae75c6ae365b07417e77115ba24c58 [file] [log] [blame]
Jian Lic94b7ee2021-02-22 21:48:32 +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.KubevirtPodService;
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 * Kubevirt POD completer.
34 */
35@Service
36public class KubevirtPodCompleter implements Completer {
37 @Override
38 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
39 StringsCompleter delegate = new StringsCompleter();
40 KubevirtPodService podService = get(KubevirtPodService.class);
41
42 Set<String> podNames = podService.pods().stream()
43 .map(p -> p.getMetadata().getName()).collect(Collectors.toSet());
44 SortedSet<String> strings = delegate.getStrings();
45
46 strings.addAll(podNames);
47
48 return delegate.complete(session, commandLine, candidates);
49 }
50}