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; |
jiangrui | 800e26f | 2015-11-28 13:59:51 +0800 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onosproject.cli.AbstractShellCommand; |
| 25 | import org.onosproject.vtnrsc.DefaultFloatingIp; |
| 26 | import org.onosproject.vtnrsc.FloatingIpId; |
| 27 | import org.onosproject.vtnrsc.FloatingIp; |
| 28 | import org.onosproject.vtnrsc.FloatingIp.Status; |
| 29 | import org.onosproject.vtnrsc.RouterId; |
| 30 | import org.onosproject.vtnrsc.TenantId; |
| 31 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 32 | import org.onosproject.vtnrsc.VirtualPortId; |
| 33 | import org.onosproject.vtnrsc.floatingip.FloatingIpService; |
| 34 | |
| 35 | import com.google.common.collect.Sets; |
| 36 | |
| 37 | /** |
| 38 | * Supports for create a floating IP. |
| 39 | */ |
| 40 | @Command(scope = "onos", name = "floatingip-create", |
| 41 | description = "Supports for creating a floating IP") |
| 42 | public class FloatingIpCreateCommand extends AbstractShellCommand { |
| 43 | @Argument(index = 0, name = "id", description = "The floating IP identifier", |
| 44 | required = true, multiValued = false) |
| 45 | String id = null; |
| 46 | |
| 47 | @Argument(index = 1, name = "networkId", description = "The network identifier of floating IP", |
| 48 | required = true, multiValued = false) |
| 49 | String networkId = null; |
| 50 | |
| 51 | @Argument(index = 2, name = "tenantId", description = "The tenant identifier of floating IP", |
| 52 | required = true, multiValued = false) |
| 53 | String tenantId = null; |
| 54 | |
| 55 | @Argument(index = 3, name = "routerId", description = "The router identifier of floating IP", |
| 56 | required = true, multiValued = false) |
| 57 | String routerId = null; |
| 58 | |
| 59 | @Argument(index = 4, name = "fixedIp", description = "The fixed IP of floating IP", |
| 60 | required = true, multiValued = false) |
| 61 | String fixedIp = null; |
| 62 | |
| 63 | @Argument(index = 5, name = "floatingIp", description = "The floating IP of floating IP", |
| 64 | required = true, multiValued = false) |
| 65 | String floatingIp = null; |
| 66 | |
| 67 | @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP", |
| 68 | required = false, multiValued = false) |
| 69 | String portId = null; |
| 70 | |
| 71 | @Option(name = "-s", aliases = "--status", description = "The status of floating IP", |
| 72 | required = false, multiValued = false) |
| 73 | String status = null; |
| 74 | |
| 75 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame^] | 76 | protected void doExecute() { |
jiangrui | 800e26f | 2015-11-28 13:59:51 +0800 | [diff] [blame] | 77 | FloatingIpService service = get(FloatingIpService.class); |
| 78 | try { |
| 79 | FloatingIp floatingIpObj = new DefaultFloatingIp( |
| 80 | FloatingIpId.of(id), |
| 81 | TenantId.tenantId(tenantId), |
| 82 | TenantNetworkId.networkId(networkId), |
| 83 | VirtualPortId.portId(portId), |
| 84 | RouterId.valueOf(routerId), |
| 85 | floatingIp == null ? null : IpAddress.valueOf(floatingIp), |
| 86 | fixedIp == null ? null : IpAddress.valueOf(fixedIp), |
| 87 | status == null ? Status.ACTIVE |
| 88 | : Status.valueOf(status)); |
| 89 | Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj); |
| 90 | service.createFloatingIps(floatingIpSet); |
| 91 | } catch (Exception e) { |
| 92 | print(null, e.getMessage()); |
| 93 | } |
| 94 | } |
| 95 | } |