2  * Copyright 2015 Open Networking Laboratory
 
   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
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17 package org.onosproject.cordvtn.cli;
 
  19 import org.apache.karaf.shell.commands.Argument;
 
  20 import org.apache.karaf.shell.commands.Command;
 
  21 import org.onosproject.cli.AbstractShellCommand;
 
  22 import org.onosproject.cordvtn.CordVtnService;
 
  23 import org.onosproject.cordvtn.OvsdbNode;
 
  25 import java.util.NoSuchElementException;
 
  30 @Command(scope = "onos", name = "ovsdb-disconnect",
 
  31         description = "Disconnects OVSDBs")
 
  32 public class OvsdbNodeDisconnectCommand extends AbstractShellCommand {
 
  34     @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)",
 
  35             required = true, multiValued = true)
 
  36     private String[] hosts = null;
 
  39     protected void execute() {
 
  40         CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
 
  42         for (String host : hosts) {
 
  45                 ovsdb = service.getNodes().stream()
 
  46                         .filter(node -> node.host().equals(host))
 
  48             } catch (NoSuchElementException e) {
 
  49                 print("Unable to find %s", host);
 
  53             if (!service.isNodeConnected(ovsdb)) {
 
  54                 print("OVSDB %s is already in disconnected state, do nothing", host);
 
  56                 service.disconnect(ovsdb);