jiangrui | 9ba8cda | 2015-08-12 11:41:47 +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 | 9ba8cda | 2015-08-12 11:41:47 +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.subnet; |
| 17 | |
| 18 | import java.util.Set; |
| 19 | |
| 20 | import org.apache.karaf.shell.commands.Argument; |
| 21 | import org.apache.karaf.shell.commands.Command; |
| 22 | import org.apache.karaf.shell.commands.Option; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.IpAddress.Version; |
| 25 | import org.onlab.packet.IpPrefix; |
| 26 | import org.onosproject.cli.AbstractShellCommand; |
| 27 | import org.onosproject.vtnrsc.AllocationPool; |
| 28 | import org.onosproject.vtnrsc.DefaultSubnet; |
| 29 | import org.onosproject.vtnrsc.HostRoute; |
| 30 | import org.onosproject.vtnrsc.Subnet; |
| 31 | import org.onosproject.vtnrsc.Subnet.Mode; |
| 32 | import org.onosproject.vtnrsc.SubnetId; |
| 33 | import org.onosproject.vtnrsc.TenantId; |
| 34 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 35 | import org.onosproject.vtnrsc.subnet.SubnetService; |
| 36 | |
| 37 | import com.google.common.collect.Sets; |
| 38 | |
| 39 | /** |
| 40 | * Supports for updating a subnet. |
| 41 | */ |
| 42 | @Command(scope = "onos", name = "subnet-update", description = "Supports for updating a subnet") |
| 43 | public class SubnetUpdateCommand extends AbstractShellCommand { |
| 44 | |
| 45 | @Argument(index = 0, name = "id", description = "Subnet Id", required = true, |
| 46 | multiValued = false) |
| 47 | String id = null; |
| 48 | |
| 49 | @Argument(index = 1, name = "subnetName", description = "Subnet String name", required = true, |
| 50 | multiValued = false) |
| 51 | String subnetName = null; |
| 52 | |
| 53 | @Argument(index = 2, name = "networkId", description = "Subnet Network Id", required = true, |
| 54 | multiValued = false) |
| 55 | String networkId = null; |
| 56 | |
| 57 | @Argument(index = 3, name = "tenantId", description = "Subnet Tenant Id", required = true, |
| 58 | multiValued = false) |
| 59 | String tenantId = null; |
| 60 | |
| 61 | @Option(name = "-i", aliases = "--ipVersion", description = "Subnet Version ipVersion", |
| 62 | required = false, multiValued = false) |
| 63 | Version ipVersion = null; |
| 64 | |
| 65 | @Option(name = "-c", aliases = "--cidr", description = "Subnet IpPrefix cidr", required = false, |
| 66 | multiValued = false) |
| 67 | String cidr = "0.0.0.0/0"; |
| 68 | |
| 69 | @Option(name = "-g", aliases = "--gatewayIp", description = "Subnet IpAddress gatewayIp", |
| 70 | required = false, multiValued = false) |
| 71 | String gatewayIp = "0.0.0.0"; |
| 72 | |
| 73 | @Option(name = "-d", aliases = "--dhcpEnabled", description = "Subnet boolean dhcpEnabled", |
| 74 | required = false, multiValued = false) |
| 75 | boolean dhcpEnabled = false; |
| 76 | |
| 77 | @Option(name = "-s", aliases = "--shared", description = "Subnet boolean shared", required = false, |
| 78 | multiValued = false) |
| 79 | boolean shared = false; |
| 80 | |
| 81 | @Option(name = "-m", aliases = "--ipV6AddressMode", description = "Subnet Mode ipV6AddressMode", |
| 82 | required = false, multiValued = false) |
| 83 | String ipV6AddressMode = null; |
| 84 | |
| 85 | @Option(name = "-r", aliases = "--ipV6RaMode", description = "Subnet Mode ipV6RaMode", |
| 86 | required = false, multiValued = false) |
| 87 | String ipV6RaMode = null; |
| 88 | |
| 89 | @Option(name = "-h", aliases = "--hostRoutes", description = "Subnet jsonnode hostRoutes", |
| 90 | required = false, multiValued = false) |
jiangrui | ac0879a | 2015-09-08 16:58:49 +0800 | [diff] [blame] | 91 | Set<HostRoute> hostRoutes = Sets.newHashSet(); |
jiangrui | 9ba8cda | 2015-08-12 11:41:47 +0800 | [diff] [blame] | 92 | |
| 93 | @Option(name = "-a", aliases = "--allocationPools", |
| 94 | description = "Subnet jsonnode allocationPools", required = false, multiValued = false) |
Sho SHIMIZU | 9f614a4 | 2015-09-11 15:32:46 -0700 | [diff] [blame] | 95 | Set<AllocationPool> allocationPools = Sets.newHashSet(); |
jiangrui | 9ba8cda | 2015-08-12 11:41:47 +0800 | [diff] [blame] | 96 | |
| 97 | @Override |
| 98 | protected void execute() { |
| 99 | SubnetService service = get(SubnetService.class); |
| 100 | if (id == null || networkId == null || tenantId == null) { |
Satish K | 1b81f85 | 2015-11-29 15:32:23 +0530 | [diff] [blame] | 101 | print("id,networkId,tenantId can not be null"); |
jiangrui | 9ba8cda | 2015-08-12 11:41:47 +0800 | [diff] [blame] | 102 | return; |
| 103 | } |
| 104 | Subnet subnet = new DefaultSubnet(SubnetId.subnetId(id), subnetName, |
| 105 | TenantNetworkId.networkId(networkId), |
| 106 | TenantId.tenantId(tenantId), ipVersion, |
| 107 | cidr == null ? null : IpPrefix.valueOf(cidr), |
| 108 | gatewayIp == null ? null : IpAddress.valueOf(gatewayIp), |
| 109 | dhcpEnabled, shared, hostRoutes, |
| 110 | ipV6AddressMode == null ? null : Mode.valueOf(ipV6AddressMode), |
| 111 | ipV6RaMode == null ? null : Mode.valueOf(ipV6RaMode), |
| 112 | allocationPools); |
| 113 | Set<Subnet> subnetsSet = Sets.newHashSet(); |
| 114 | subnetsSet.add(subnet); |
| 115 | service.updateSubnets(subnetsSet); |
| 116 | } |
| 117 | |
| 118 | } |