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