Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8e57fd5 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 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 | |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 17 | package org.opencord.cordvtn.cli; |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
Hyunsun Moon | 2c3f0ee | 2017-04-06 16:47:21 +0900 | [diff] [blame] | 22 | import org.opencord.cordvtn.api.node.CordVtnNodeAdminService; |
Hyunsun Moon | fd5a24e | 2016-10-19 19:15:48 -0700 | [diff] [blame] | 23 | import org.opencord.cordvtn.api.node.CordVtnNode; |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 24 | |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 25 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 26 | * Deletes nodes from the service. |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 27 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 28 | @Command(scope = "onos", name = "cordvtn-node-delete", |
| 29 | description = "Deletes nodes from CORD VTN service") |
| 30 | public class CordVtnNodeDeleteCommand extends AbstractShellCommand { |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 31 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 32 | @Argument(index = 0, name = "hostnames", description = "Hostname(s)", |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 33 | required = true, multiValued = true) |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 34 | private String[] hostnames = null; |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 35 | |
| 36 | @Override |
| 37 | protected void execute() { |
Hyunsun Moon | 2c3f0ee | 2017-04-06 16:47:21 +0900 | [diff] [blame] | 38 | CordVtnNodeAdminService nodeAdminService = |
| 39 | AbstractShellCommand.get(CordVtnNodeAdminService.class); |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 40 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 41 | for (String hostname : hostnames) { |
Hyunsun Moon | 2c3f0ee | 2017-04-06 16:47:21 +0900 | [diff] [blame] | 42 | CordVtnNode node = nodeAdminService.removeNode(hostname); |
| 43 | if (node == null) { |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 44 | print("Unable to find %s", hostname); |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 45 | } |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |