blob: 893605fd6a7fcc5be67964863ce9f6612d0dcd3c [file] [log] [blame]
Jian Li1c10cf22021-03-05 01:32:04 +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.KubevirtSecurityGroup;
24import org.onosproject.kubevirtnetworking.api.KubevirtSecurityGroupService;
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 security group name completer.
35 */
36@Service
37public class KubevirtSecurityGroupCompleter implements Completer {
38 @Override
39 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
40 StringsCompleter delegate = new StringsCompleter();
41 KubevirtSecurityGroupService service = get(KubevirtSecurityGroupService.class);
42
43 Set<String> sgNames = service.securityGroups().stream()
44 .map(KubevirtSecurityGroup::name).collect(Collectors.toSet());
45
46 SortedSet<String> strings = delegate.getStrings();
47
48 strings.addAll(sgNames);
49
50 return delegate.complete(session, commandLine, candidates);
51 }
52}