blob: 0b2d89f790b6b342783f733bbdd8270f75249709 [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.ArrayList;
19import java.util.List;
20import java.util.Set;
21
Ray Milkey86ad7bb2018-09-27 12:32:28 -070022import org.apache.karaf.shell.api.action.Argument;
23import org.apache.karaf.shell.api.action.Command;
24import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070025import org.apache.karaf.shell.api.action.lifecycle.Service;
jiangrui264dede2015-11-28 14:02:34 +080026import org.onosproject.cli.AbstractShellCommand;
27import org.onosproject.vtnrsc.DefaultRouter;
28import org.onosproject.vtnrsc.Router;
29import org.onosproject.vtnrsc.Router.Status;
30import org.onosproject.vtnrsc.RouterId;
31import org.onosproject.vtnrsc.TenantId;
32import org.onosproject.vtnrsc.VirtualPortId;
33import org.onosproject.vtnrsc.router.RouterService;
34
35import com.google.common.collect.Sets;
36
37/**
38 * Supports for update a router.
39 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070040@Service
jiangrui264dede2015-11-28 14:02:34 +080041@Command(scope = "onos", name = "router-update", description = "Supports for updating a router")
42public class RouterUpdateCommand extends AbstractShellCommand {
43 @Argument(index = 0, name = "id", description = "The router identifier",
44 required = true, multiValued = false)
45 String id = null;
46
47 @Option(name = "-r", aliases = "--routerName", description = "The name of router",
48 required = false, multiValued = false)
49 String routerName = null;
50
51 @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of router",
52 required = false, multiValued = false)
53 String tenantId = null;
54
55 @Option(name = "-g", aliases = "--gatewayPortId", description = "The gatewayPort identifier of router",
56 required = false, multiValued = false)
57 String gatewayPortId = null;
58
59 @Option(name = "-e", aliases = "--externalGatewayInfo", description = "The externalGatewayInfo of router",
60 required = false, multiValued = false)
61 String externalGatewayInfo = null;
62
63 @Option(name = "-s", aliases = "--status", description = "The status of router",
64 required = false, multiValued = false)
65 String status = null;
66
67 @Option(name = "-a", aliases = "--adminStateUp", description = "The boolean adminStateUp of router",
68 required = false, multiValued = false)
69 boolean adminStateUp = true;
70
71 @Option(name = "-d", aliases = "--distributed", description = "The boolean distributed of router",
72 required = false, multiValued = false)
73 boolean distributed = false;
74
75 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070076 protected void doExecute() {
jiangrui264dede2015-11-28 14:02:34 +080077 RouterService service = get(RouterService.class);
78 RouterId routerId = RouterId.valueOf(id);
79 Router router = get(RouterService.class).getRouter(routerId);
80 try {
81 List<String> routes = new ArrayList<String>();
82 Router routerObj = new DefaultRouter(
83 RouterId.valueOf(id),
84 routerName == null ? router.name() : routerName,
85 adminStateUp,
86 status == null ? Status.ACTIVE
87 : Status.valueOf(status),
88 distributed,
89 null,
90 gatewayPortId == null ? router.gatewayPortid()
91 : VirtualPortId.portId(gatewayPortId),
92 tenantId == null ? router.tenantId()
93 : TenantId.tenantId(tenantId),
94 routes);
95 Set<Router> routerSet = Sets.newHashSet(routerObj);
96 service.createRouters(routerSet);
97 } catch (Exception e) {
98 print(null, e.getMessage());
99 }
100 }
101}