blob: 25a7858b0d709b16591c16085e50d6f3e5214947 [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;
Ray Milkey86ad7bb2018-09-27 12:32:28 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
daniel parkeeb8e042018-02-21 14:06:58 +090022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
daniel park32b42202018-03-14 16:53:44 +090024import org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService;
daniel parkeeb8e042018-02-21 14:06:58 +090025
26import java.util.List;
27
28/**
29 * Deletes external peer router.
30 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070031@Service
daniel parkeeb8e042018-02-21 14:06:58 +090032@Command(scope = "onos", name = "openstack-delete-peer-router",
33 description = "Delete external peer router")
34public class DeleteExternalPeerRouterCommand extends AbstractShellCommand {
35 @Argument(index = 0, name = "ip address", description = "ip address",
36 required = true, multiValued = false)
37 private String ipAddress = null;
38
39 private static final String FORMAT = "%-20s%-20s%-20s";
40 private static final String NO_ELEMENT = "There's no external peer router information with given ip address";
41
42 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070043 protected void doExecute() {
daniel park32b42202018-03-14 16:53:44 +090044 OpenstackNetworkAdminService service = AbstractShellCommand.get(OpenstackNetworkAdminService.class);
daniel parkeeb8e042018-02-21 14:06:58 +090045
46 if (service.externalPeerRouters().stream()
Jian Li5e2ad4a2018-07-16 13:40:53 +090047 .noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
daniel parkeeb8e042018-02-21 14:06:58 +090048 print(NO_ELEMENT);
49 return;
50 }
51
52 try {
53 service.deleteExternalPeerRouter(ipAddress);
54 } catch (IllegalArgumentException e) {
55 log.error("Exception occurred because of {}", e.toString());
56 }
57 print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
58 List<ExternalPeerRouter> routers = Lists.newArrayList(service.externalPeerRouters());
59
60 for (ExternalPeerRouter router: routers) {
Jian Li5e2ad4a2018-07-16 13:40:53 +090061 print(FORMAT, router.ipAddress(),
62 router.macAddress().toString(),
63 router.vlanId());
daniel parkeeb8e042018-02-21 14:06:58 +090064 }
65
66 }
67}