daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package org.onosproject.openstacknetworking.cli; |
| 17 | |
| 18 | import com.google.common.collect.Lists; |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Jian Li | db521c1 | 2018-11-19 17:42:35 +0900 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.openstacknetworking.api.ExternalPeerRouter; |
daniel park | 32b4220 | 2018-03-14 16:53:44 +0900 | [diff] [blame] | 25 | import org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService; |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 26 | |
| 27 | import java.util.List; |
| 28 | |
| 29 | /** |
| 30 | * Deletes external peer router. |
| 31 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 32 | @Service |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 33 | @Command(scope = "onos", name = "openstack-delete-peer-router", |
| 34 | description = "Delete external peer router") |
| 35 | public class DeleteExternalPeerRouterCommand extends AbstractShellCommand { |
| 36 | @Argument(index = 0, name = "ip address", description = "ip address", |
| 37 | required = true, multiValued = false) |
Jian Li | db521c1 | 2018-11-19 17:42:35 +0900 | [diff] [blame] | 38 | @Completion(IpAddressCompleter.class) |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 39 | private String ipAddress = null; |
| 40 | |
| 41 | private static final String FORMAT = "%-20s%-20s%-20s"; |
| 42 | private static final String NO_ELEMENT = "There's no external peer router information with given ip address"; |
| 43 | |
| 44 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 45 | protected void doExecute() { |
daniel park | 32b4220 | 2018-03-14 16:53:44 +0900 | [diff] [blame] | 46 | OpenstackNetworkAdminService service = AbstractShellCommand.get(OpenstackNetworkAdminService.class); |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 47 | |
| 48 | if (service.externalPeerRouters().stream() |
Jian Li | 5e2ad4a | 2018-07-16 13:40:53 +0900 | [diff] [blame] | 49 | .noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) { |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 50 | print(NO_ELEMENT); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | try { |
| 55 | service.deleteExternalPeerRouter(ipAddress); |
| 56 | } catch (IllegalArgumentException e) { |
Daniel Park | a3ffbdb | 2018-11-28 13:51:39 +0900 | [diff] [blame] | 57 | log.error("Exception occurred because of {}", e); |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 58 | } |
| 59 | print(FORMAT, "Router IP", "Mac Address", "VLAN ID"); |
| 60 | List<ExternalPeerRouter> routers = Lists.newArrayList(service.externalPeerRouters()); |
| 61 | |
| 62 | for (ExternalPeerRouter router: routers) { |
Jian Li | 5e2ad4a | 2018-07-16 13:40:53 +0900 | [diff] [blame] | 63 | print(FORMAT, router.ipAddress(), |
| 64 | router.macAddress().toString(), |
| 65 | router.vlanId()); |
daniel park | eeb8e04 | 2018-02-21 14:06:58 +0900 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | } |
| 69 | } |