blob: 0ef386151d9ec639381db1e2a7dd827a2043a451 [file] [log] [blame]
daniel parkeeb8e042018-02-21 14:06:58 +09001/*
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 */
16package org.onosproject.openstacknetworking.cli;
17
18import com.google.common.collect.Lists;
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
daniel park32b42202018-03-14 16:53:44 +090023import org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService;
daniel parkeeb8e042018-02-21 14:06:58 +090024
25import java.util.List;
26
27/**
28 * Deletes external peer router.
29 */
30@Command(scope = "onos", name = "openstack-delete-peer-router",
31 description = "Delete external peer router")
32public class DeleteExternalPeerRouterCommand extends AbstractShellCommand {
33 @Argument(index = 0, name = "ip address", description = "ip address",
34 required = true, multiValued = false)
35 private String ipAddress = null;
36
37 private static final String FORMAT = "%-20s%-20s%-20s";
38 private static final String NO_ELEMENT = "There's no external peer router information with given ip address";
39
40 @Override
41 protected void execute() {
daniel park32b42202018-03-14 16:53:44 +090042 OpenstackNetworkAdminService service = AbstractShellCommand.get(OpenstackNetworkAdminService.class);
daniel parkeeb8e042018-02-21 14:06:58 +090043
44 if (service.externalPeerRouters().stream()
Jian Li5e2ad4a2018-07-16 13:40:53 +090045 .noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
daniel parkeeb8e042018-02-21 14:06:58 +090046 print(NO_ELEMENT);
47 return;
48 }
49
50 try {
51 service.deleteExternalPeerRouter(ipAddress);
52 } catch (IllegalArgumentException e) {
53 log.error("Exception occurred because of {}", e.toString());
54 }
55 print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
56 List<ExternalPeerRouter> routers = Lists.newArrayList(service.externalPeerRouters());
57
58 for (ExternalPeerRouter router: routers) {
Jian Li5e2ad4a2018-07-16 13:40:53 +090059 print(FORMAT, router.ipAddress(),
60 router.macAddress().toString(),
61 router.vlanId());
daniel parkeeb8e042018-02-21 14:06:58 +090062 }
63
64 }
65}