a500d0d8ae4551b3e0db856ab95df0f77bee9079
[onosfw.git] /
1 /*
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
17 package org.onosproject.cordvtn.cli;
18
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;
24
25 import java.util.NoSuchElementException;
26
27 /**
28  * Deletes OVSDB nodes from cordvtn.
29  */
30 @Command(scope = "onos", name = "ovsdb-delete",
31         description = "Deletes OVSDB nodes from cordvtn")
32 public class OvsdbNodeDeleteCommand 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
49             } catch (NoSuchElementException e) {
50                 print("Unable to find %s", host);
51                 continue;
52             }
53
54             service.deleteNode(ovsdb);
55         }
56     }
57 }