blob: 8dfd0feeeacb8d8c46ec2264571b40880d70c686 [file] [log] [blame]
Jian Li62dbb6a2018-02-27 15:18:53 +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.openstacknode.cli;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import 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;
Jian Li62dbb6a2018-02-27 15:18:53 +090022import org.onosproject.cli.AbstractShellCommand;
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
31/**
32 * Openstack host completer.
33 */
34public class OpenstackHostnameCompleter implements Completer {
35
36 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070037 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
Jian Li62dbb6a2018-02-27 15:18:53 +090038 StringsCompleter delegate = new StringsCompleter();
39 OpenstackNodeService osNodeService = AbstractShellCommand.get(OpenstackNodeService.class);
40
41 Set<String> hostnames = osNodeService.nodes().stream()
42 .map(OpenstackNode::hostname)
43 .collect(Collectors.toSet());
44 SortedSet<String> strings = delegate.getStrings();
45
46 strings.addAll(hostnames);
47
Ray Milkey86ad7bb2018-09-27 12:32:28 -070048 return delegate.complete(session, commandLine, candidates);
Jian Li62dbb6a2018-02-27 15:18:53 +090049 }
50}