2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netvirt.bgpmanager.commands;
11 import org.apache.karaf.shell.commands.Argument;
12 import org.apache.karaf.shell.commands.Command;
13 import org.apache.karaf.shell.commands.Option;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.netvirt.bgpmanager.BgpManager;
17 @Command(scope = "odl", name = "bgp-connect",
18 description = "Add or delete client connection to BGP Config Server")
19 public class Connect extends OsgiCommandSupport {
20 private static final String HOST = "--host";
21 private static final String PORT = "--port";
23 @Argument(name = "add|del", description = "The desired operation",
24 required = true, multiValued = false)
27 @Option(name = HOST, aliases = {"-h"},
28 description = "IP address of the server",
29 required = false, multiValued = false)
32 @Option(name = PORT, aliases = {"-p"},
33 description = "Thrift port", required = false,
37 private final BgpManager bgpManager;
39 public Connect(BgpManager bgpManager) {
40 this.bgpManager = bgpManager;
43 private Object usage() {
44 session.getConsole().println(
45 "usage: bgp-connect [" + HOST + " h] [" + PORT + " p] <add | del>");
50 protected Object doExecute() throws Exception {
53 if (host == null || port == null) {
54 session.getConsole().println("error: " + HOST + " and " + PORT + " needed");
57 if (!Commands.isValid(session.getConsole(), host, Commands.Validators.IPADDR, HOST)
58 || !Commands.isValid(session.getConsole(), port, Commands.Validators.INT, PORT)) {
61 // check: already connected?
62 bgpManager.startConfig(host, Integer.parseInt(port));
65 if (host != null || port != null) {
66 session.getConsole().println("note: option(s) not needed; ignored");
68 // check: nothing to stop?
69 bgpManager.stopConfig();