blob: c3b49e1e2268de1c990938eb465948c2d99b50f4 [file] [log] [blame]
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -07003 *
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;
Hyunsun Moon7f4ed9d2016-04-14 16:13:42 -070022import org.onosproject.cordvtn.impl.CordVtnNodeManager;
23import org.onosproject.cordvtn.api.CordVtnNode;
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070024
25import java.util.NoSuchElementException;
26
27/**
Hyunsun Moon8539b042015-11-07 22:08:43 -080028 * Deletes nodes from the service.
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070029 */
Hyunsun Moon8539b042015-11-07 22:08:43 -080030@Command(scope = "onos", name = "cordvtn-node-delete",
31 description = "Deletes nodes from CORD VTN service")
32public class CordVtnNodeDeleteCommand extends AbstractShellCommand {
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070033
Hyunsun Moon8539b042015-11-07 22:08:43 -080034 @Argument(index = 0, name = "hostnames", description = "Hostname(s)",
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070035 required = true, multiValued = true)
Hyunsun Moon8539b042015-11-07 22:08:43 -080036 private String[] hostnames = null;
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070037
38 @Override
39 protected void execute() {
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080040 CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class);
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070041
Hyunsun Moon8539b042015-11-07 22:08:43 -080042 for (String hostname : hostnames) {
43 CordVtnNode node;
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070044 try {
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080045 node = nodeManager.getNodes()
Hyunsun Moon8539b042015-11-07 22:08:43 -080046 .stream()
47 .filter(n -> n.hostname().equals(hostname))
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070048 .findFirst().get();
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070049 } catch (NoSuchElementException e) {
Hyunsun Moon8539b042015-11-07 22:08:43 -080050 print("Unable to find %s", hostname);
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070051 continue;
52 }
53
Hyunsun Moonb77b60f2016-01-15 20:03:18 -080054 nodeManager.deleteNode(node);
Hyunsun Moon4f02b3a2015-10-18 18:23:15 -070055 }
56 }
57}