blob: 1dd3777e0e85e3ce911a3c0d7ac643690109dc91 [file] [log] [blame]
daniel parkb5817102018-02-15 00:18:51 +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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import 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;
daniel parkb5817102018-02-15 00:18:51 +090023import org.onlab.packet.IpAddress;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
26import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
27
28import java.util.Iterator;
29import java.util.List;
30import java.util.Set;
31import java.util.SortedSet;
32import java.util.stream.Collectors;
33
34/**
35 * IP Address Completer.
36 */
Ray Milkey86ad7bb2018-09-27 12:32:28 -070037@Service
daniel parkb5817102018-02-15 00:18:51 +090038public class IpAddressCompleter implements Completer {
39
40 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070041 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
daniel parkb5817102018-02-15 00:18:51 +090042 StringsCompleter delegate = new StringsCompleter();
43 OpenstackNetworkService osNetService = AbstractShellCommand.get(OpenstackNetworkService.class);
44 Set<IpAddress> set = osNetService.externalPeerRouters().stream()
Jian Li5e2ad4a2018-07-16 13:40:53 +090045 .map(ExternalPeerRouter::ipAddress)
daniel parkb5817102018-02-15 00:18:51 +090046 .collect(Collectors.toSet());
47 SortedSet<String> strings = delegate.getStrings();
48
49 Iterator<IpAddress> it = set.iterator();
50
51 while (it.hasNext()) {
52 strings.add(it.next().toString());
53 }
54
Ray Milkey86ad7bb2018-09-27 12:32:28 -070055 return delegate.complete(session, commandLine, candidates);
daniel parkb5817102018-02-15 00:18:51 +090056
57 }
58}