jiangrui | 800e26f | 2015-11-28 13:59:51 +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 | 800e26f | 2015-11-28 13:59:51 +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.floatingip; |
| 17 | |
| 18 | import java.util.Set; |
| 19 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Argument; |
| 21 | import org.apache.karaf.shell.api.action.Command; |
| 22 | import org.apache.karaf.shell.api.action.Option; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
jiangrui | 800e26f | 2015-11-28 13:59:51 +0800 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onosproject.cli.AbstractShellCommand; |
| 26 | import org.onosproject.vtnrsc.DefaultFloatingIp; |
| 27 | import org.onosproject.vtnrsc.FloatingIpId; |
| 28 | import org.onosproject.vtnrsc.FloatingIp; |
| 29 | import org.onosproject.vtnrsc.FloatingIp.Status; |
| 30 | import org.onosproject.vtnrsc.RouterId; |
| 31 | import org.onosproject.vtnrsc.TenantId; |
| 32 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 33 | import org.onosproject.vtnrsc.VirtualPortId; |
| 34 | import org.onosproject.vtnrsc.floatingip.FloatingIpService; |
| 35 | |
| 36 | import com.google.common.collect.Sets; |
| 37 | |
| 38 | /** |
| 39 | * Supports for update a floating IP. |
| 40 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 41 | @Service |
jiangrui | 800e26f | 2015-11-28 13:59:51 +0800 | [diff] [blame] | 42 | @Command(scope = "onos", name = "floatingip-update", |
| 43 | description = "Supports for updating a floating IP") |
| 44 | public class FloatingIpUpdateCommand extends AbstractShellCommand { |
| 45 | @Argument(index = 0, name = "id", description = "The floating IP identifier", |
| 46 | required = true, multiValued = false) |
| 47 | String id = null; |
| 48 | |
| 49 | @Option(name = "-n", aliases = "--networkId", description = "The network identifier of floating IP", |
| 50 | required = false, multiValued = false) |
| 51 | String networkId = null; |
| 52 | |
| 53 | @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of floating IP", |
| 54 | required = false, multiValued = false) |
| 55 | String tenantId = null; |
| 56 | |
| 57 | @Option(name = "-r", aliases = "--routerId", description = "The router identifier of floating IP", |
| 58 | required = false, multiValued = false) |
| 59 | String routerId = null; |
| 60 | |
| 61 | @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP", |
| 62 | required = false, multiValued = false) |
| 63 | String portId = null; |
| 64 | |
| 65 | @Option(name = "-s", aliases = "--status", description = "The status of floating IP", |
| 66 | required = false, multiValued = false) |
| 67 | String status = null; |
| 68 | |
| 69 | @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP", |
| 70 | required = false, multiValued = false) |
| 71 | String fixedIp = null; |
| 72 | |
| 73 | @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP", |
| 74 | required = false, multiValued = false) |
| 75 | String floatingIp = null; |
| 76 | |
| 77 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 78 | protected void doExecute() { |
jiangrui | 800e26f | 2015-11-28 13:59:51 +0800 | [diff] [blame] | 79 | FloatingIpService service = get(FloatingIpService.class); |
| 80 | FloatingIpId floatingIpId = FloatingIpId.of(id); |
| 81 | FloatingIp floatingIpStore = get(FloatingIpService.class).getFloatingIp(floatingIpId); |
| 82 | try { |
| 83 | FloatingIp floatingIpObj = new DefaultFloatingIp( |
| 84 | floatingIpId, |
| 85 | tenantId == null ? floatingIpStore.tenantId() |
| 86 | : TenantId.tenantId(tenantId), |
| 87 | networkId == null ? floatingIpStore.networkId() |
| 88 | : TenantNetworkId.networkId(networkId), |
| 89 | portId == null ? floatingIpStore.portId() |
| 90 | : VirtualPortId.portId(portId), |
| 91 | routerId == null ? floatingIpStore.routerId() |
| 92 | : RouterId.valueOf(routerId), |
| 93 | floatingIp == null ? floatingIpStore.floatingIp() |
| 94 | : IpAddress.valueOf(floatingIp), |
| 95 | fixedIp == null ? floatingIpStore.fixedIp() |
| 96 | : IpAddress.valueOf(fixedIp), |
| 97 | status == null ? floatingIpStore.status() |
| 98 | : Status.valueOf(status)); |
| 99 | Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj); |
| 100 | service.updateFloatingIps(floatingIpSet); |
| 101 | } catch (Exception e) { |
| 102 | print(null, e.getMessage()); |
| 103 | } |
| 104 | } |
| 105 | } |