blob: 45d642c81bba0f474afc74c16056a561f2a24eaa [file] [log] [blame]
jiangrui264dede2015-11-28 14:02:34 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui264dede2015-11-28 14:02:34 +08003 *
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.vtnrsc.cli.router;
17
18import java.util.Set;
19
Ray Milkey86ad7bb2018-09-27 12:32:28 -070020import org.apache.karaf.shell.api.action.Command;
21import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
jiangrui264dede2015-11-28 14:02:34 +080023import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.vtnrsc.Router;
25import org.onosproject.vtnrsc.RouterId;
26import org.onosproject.vtnrsc.router.RouterService;
27
28import com.google.common.collect.Sets;
29
30/**
31 * Supports for remove a router.
32 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070033@Service
jiangrui264dede2015-11-28 14:02:34 +080034@Command(scope = "onos", name = "router-remove", description = "Supports for removing a router")
35public class RouterRemoveCommand extends AbstractShellCommand {
36 @Option(name = "-i", aliases = "--id", description = "The router identifier",
37 required = false, multiValued = false)
38 String id = null;
39
40 @Option(name = "-n", aliases = "--routerName", description = "The name of router",
41 required = false, multiValued = false)
42 String routerName = null;
43
44 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070045 protected void doExecute() {
jiangrui264dede2015-11-28 14:02:34 +080046 RouterService service = get(RouterService.class);
47 if (id == null && routerName == null) {
48 print(null, "one of id, routerName should not be null");
49 }
50 try {
51 Set<RouterId> routerSet = Sets.newHashSet();
52 if (id != null) {
53 routerSet.add(RouterId.valueOf(id));
54 service.removeRouters(routerSet);
55 } else {
56 Iterable<Router> routers = service.getRouters();
57 if (routers == null) {
58 return;
59 }
60 for (Router router : routers) {
61 if (router.name().equals(routerName)) {
62 routerSet.add(router.id());
63 service.removeRouters(routerSet);
64 return;
65 }
66 }
67 }
68 } catch (Exception e) {
69 print(null, e.getMessage());
70 }
71 }
72
73}