blob: eb4a0637c1f1dfde16ab32970ba5ef7fa6d774f6 [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.VlanId;
daniel parkb5817102018-02-15 00:18:51 +090024import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
25import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
26
27import java.util.Iterator;
28import java.util.List;
29import java.util.Set;
30import java.util.SortedSet;
31import java.util.stream.Collectors;
32
Jian Li5ecfd1a2018-12-10 11:41:03 +090033import static org.onosproject.cli.AbstractShellCommand.get;
34
daniel parkb5817102018-02-15 00:18:51 +090035/**
36 * Vlan Id Completer.
37 */
Ray Milkey86ad7bb2018-09-27 12:32:28 -070038@Service
daniel parkb5817102018-02-15 00:18:51 +090039public class VlanIdCompleter implements Completer {
40
41 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070042 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
daniel parkb5817102018-02-15 00:18:51 +090043 StringsCompleter delegate = new StringsCompleter();
Jian Li5ecfd1a2018-12-10 11:41:03 +090044 OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
daniel parkb5817102018-02-15 00:18:51 +090045 Set<VlanId> set = osNetService.externalPeerRouters().stream()
Jian Li5e2ad4a2018-07-16 13:40:53 +090046 .map(ExternalPeerRouter::vlanId)
daniel parkb5817102018-02-15 00:18:51 +090047 .collect(Collectors.toSet());
48 SortedSet<String> strings = delegate.getStrings();
49
50 Iterator<VlanId> it = set.iterator();
51
52 while (it.hasNext()) {
53 strings.add(it.next().toString());
54 }
55
Ray Milkey86ad7bb2018-09-27 12:32:28 -070056 return delegate.complete(session, commandLine, candidates);
daniel parkb5817102018-02-15 00:18:51 +090057
58 }
59}