jiangrui | 264dede | 2015-11-28 14:02:34 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
jiangrui | 264dede | 2015-11-28 14:02:34 +0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.vtnrsc.cli.router; |
| 17 | |
| 18 | import java.util.ArrayList; |
| 19 | import java.util.List; |
| 20 | import java.util.Set; |
| 21 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 22 | import org.apache.karaf.shell.api.action.Argument; |
| 23 | import org.apache.karaf.shell.api.action.Command; |
| 24 | import org.apache.karaf.shell.api.action.Option; |
jiangrui | 264dede | 2015-11-28 14:02:34 +0800 | [diff] [blame] | 25 | import org.onosproject.cli.AbstractShellCommand; |
| 26 | import org.onosproject.vtnrsc.DefaultRouter; |
| 27 | import org.onosproject.vtnrsc.Router; |
| 28 | import org.onosproject.vtnrsc.Router.Status; |
| 29 | import org.onosproject.vtnrsc.RouterId; |
| 30 | import org.onosproject.vtnrsc.TenantId; |
| 31 | import org.onosproject.vtnrsc.VirtualPortId; |
| 32 | import org.onosproject.vtnrsc.router.RouterService; |
| 33 | |
| 34 | import 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") |
| 40 | public 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 |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 74 | protected void doExecute() { |
jiangrui | 264dede | 2015-11-28 14:02:34 +0800 | [diff] [blame] | 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 | } |