blob: 14e44e088e02c22b6896c58e353840ad4390f11b [file] [log] [blame]
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16
17package org.onosproject.cordvtn.cli;
18
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.cordvtn.CordVtnService;
23import org.onosproject.cordvtn.OvsdbNode;
24
25import java.util.NoSuchElementException;
26
27/**
28 * Disconnects OVSDBs.
29 */
30@Command(scope = "onos", name = "ovsdb-disconnect",
31 description = "Disconnects OVSDBs")
32public class OvsdbNodeDisconnectCommand extends AbstractShellCommand {
33
34 @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)",
35 required = true, multiValued = true)
36 private String[] hosts = null;
37
38 @Override
39 protected void execute() {
40 CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
41
42 for (String host : hosts) {
43 OvsdbNode ovsdb;
44 try {
45 ovsdb = service.getNodes().stream()
46 .filter(node -> node.host().equals(host))
47 .findFirst().get();
48 } catch (NoSuchElementException e) {
49 print("Unable to find %s", host);
50 continue;
51 }
52
53 if (!service.isNodeConnected(ovsdb)) {
54 print("OVSDB %s is already in disconnected state, do nothing", host);
55 } else {
56 service.disconnect(ovsdb);
57 }
58 }
59 }
60}