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