blob: 069383b48df4e2617e116fa2e3427c24a31be22b [file] [log] [blame]
Jian Li51728702019-05-17 18:38:56 +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.openstacknetworking.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.openstacknode.api.OpenstackNode;
24import org.onosproject.openstacknode.api.OpenstackNodeService;
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;
32import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE;
33
34/**
35 * Openstack host completer.
36 */
37@Service
38public class OpenstackComputeNodeCompleter implements Completer {
39
40 @Override
41 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
42 StringsCompleter delegate = new StringsCompleter();
43 OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
44
45 Set<String> hostnames = osNodeService.completeNodes(COMPUTE).stream()
46 .map(OpenstackNode::hostname)
47 .collect(Collectors.toSet());
48 SortedSet<String> strings = delegate.getStrings();
49
50 strings.addAll(hostnames);
51
52 return delegate.complete(session, commandLine, candidates);
53 }
54}