blob: eea9f44d8f8c7c59747daa1bf90826d5f1961295 [file] [log] [blame]
Hyunsun Moon838b19b2015-10-18 18:23:15 -07001/*
Brian O'Connor8e57fd52016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Hyunsun Moon838b19b2015-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
alshabibb4d31712016-06-01 18:51:03 -070017package org.opencord.cordvtn.cli;
Hyunsun Moon838b19b2015-10-18 18:23:15 -070018
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
Hyunsun Moon2c3f0ee2017-04-06 16:47:21 +090022import org.opencord.cordvtn.api.node.CordVtnNodeAdminService;
Hyunsun Moonfd5a24e2016-10-19 19:15:48 -070023import org.opencord.cordvtn.api.node.CordVtnNode;
Hyunsun Moon838b19b2015-10-18 18:23:15 -070024
Hyunsun Moon838b19b2015-10-18 18:23:15 -070025/**
Hyunsun Moon4edb0172015-11-07 22:08:43 -080026 * Deletes nodes from the service.
Hyunsun Moon838b19b2015-10-18 18:23:15 -070027 */
Hyunsun Moon4edb0172015-11-07 22:08:43 -080028@Command(scope = "onos", name = "cordvtn-node-delete",
29 description = "Deletes nodes from CORD VTN service")
30public class CordVtnNodeDeleteCommand extends AbstractShellCommand {
Hyunsun Moon838b19b2015-10-18 18:23:15 -070031
Hyunsun Moon4edb0172015-11-07 22:08:43 -080032 @Argument(index = 0, name = "hostnames", description = "Hostname(s)",
Hyunsun Moon838b19b2015-10-18 18:23:15 -070033 required = true, multiValued = true)
Hyunsun Moon4edb0172015-11-07 22:08:43 -080034 private String[] hostnames = null;
Hyunsun Moon838b19b2015-10-18 18:23:15 -070035
36 @Override
37 protected void execute() {
Hyunsun Moon2c3f0ee2017-04-06 16:47:21 +090038 CordVtnNodeAdminService nodeAdminService =
39 AbstractShellCommand.get(CordVtnNodeAdminService.class);
Hyunsun Moon838b19b2015-10-18 18:23:15 -070040
Hyunsun Moon4edb0172015-11-07 22:08:43 -080041 for (String hostname : hostnames) {
Hyunsun Moon2c3f0ee2017-04-06 16:47:21 +090042 CordVtnNode node = nodeAdminService.removeNode(hostname);
43 if (node == null) {
Hyunsun Moon4edb0172015-11-07 22:08:43 -080044 print("Unable to find %s", hostname);
Hyunsun Moon838b19b2015-10-18 18:23:15 -070045 }
Hyunsun Moon838b19b2015-10-18 18:23:15 -070046 }
47 }
48}