Committed by
Gerrit Code Review
[ONOS-2253] The CLIs of subnet resource.
Change-Id: I4e499ecfef33681bc78c6f865e3d0e85f7a85ee9
Showing
4 changed files
with
343 additions
and
0 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 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 creating a subnet. | ||
| 41 | + */ | ||
| 42 | +@Command(scope = "onos", name = "subnet-create", description = "Supports for creating a subnet") | ||
| 43 | +public class SubnetCreateCommand 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", | ||
| 66 | + required = false, 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", | ||
| 78 | + required = false, multiValued = false) | ||
| 79 | + boolean shared = false; | ||
| 80 | + | ||
| 81 | + @Option(name = "-m", aliases = "--ipV6AddressMode", | ||
| 82 | + description = "Subnet Mode ipV6AddressMode", 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) | ||
| 91 | + Iterable<HostRoute> hostRoutes = null; | ||
| 92 | + | ||
| 93 | + @Option(name = "-a", aliases = "--allocationPools", | ||
| 94 | + description = "Subnet jsonnode allocationPools", required = false, multiValued = false) | ||
| 95 | + Iterable<AllocationPool> allocationPools = Sets.newHashSet(); | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + protected void execute() { | ||
| 99 | + SubnetService service = get(SubnetService.class); | ||
| 100 | + if (id == null || networkId == null || tenantId == null) { | ||
| 101 | + print(null, "id,networkId,tenantId can not be null"); | ||
| 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 | + | ||
| 114 | + Set<Subnet> subnetsSet = Sets.newHashSet(subnet); | ||
| 115 | + service.createSubnets(subnetsSet); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 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 org.apache.karaf.shell.commands.Command; | ||
| 19 | +import org.apache.karaf.shell.commands.Option; | ||
| 20 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | +import org.onosproject.vtnrsc.Subnet; | ||
| 22 | +import org.onosproject.vtnrsc.SubnetId; | ||
| 23 | +import org.onosproject.vtnrsc.subnet.SubnetService; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Supports for querying a subnet. | ||
| 27 | + */ | ||
| 28 | +@Command(scope = "onos", name = "subnets", description = "Supports for querying a subnet") | ||
| 29 | +public class SubnetQueryCommand extends AbstractShellCommand { | ||
| 30 | + | ||
| 31 | + @Option(name = "-i", aliases = "--id", description = "Subnet id", required = false, | ||
| 32 | + multiValued = false) | ||
| 33 | + String id = null; | ||
| 34 | + | ||
| 35 | + private static final String FMT = "subnetId=%s, networkId=%s, subnetName=%s," | ||
| 36 | + + "tenantId=%s, cidr=%s, dhcpEnabled=%s, gatewayIp=%s," + "ipVersion=%s"; | ||
| 37 | + | ||
| 38 | + @Override | ||
| 39 | + protected void execute() { | ||
| 40 | + SubnetService service = get(SubnetService.class); | ||
| 41 | + if (id != null) { | ||
| 42 | + Subnet subnet = service.getSubnet(SubnetId.subnetId(id)); | ||
| 43 | + printSubnet(subnet); | ||
| 44 | + } else { | ||
| 45 | + Iterable<Subnet> subnets = service.getSubnets(); | ||
| 46 | + if (subnets == null) { | ||
| 47 | + return; | ||
| 48 | + } | ||
| 49 | + for (Subnet subnet : subnets) { | ||
| 50 | + printSubnet(subnet); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + private void printSubnet(Subnet subnet) { | ||
| 56 | + print(FMT, subnet.id(), subnet.networkId(), subnet.subnetName(), | ||
| 57 | + subnet.tenantId(), subnet.cidr(), subnet.dhcpEnabled(), subnet | ||
| 58 | + .gatewayIp(), subnet.ipVersion()); | ||
| 59 | + | ||
| 60 | + } | ||
| 61 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 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.onosproject.cli.AbstractShellCommand; | ||
| 23 | +import org.onosproject.vtnrsc.SubnetId; | ||
| 24 | +import org.onosproject.vtnrsc.subnet.SubnetService; | ||
| 25 | + | ||
| 26 | +import com.google.common.collect.Sets; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Supports for removing a subnet. | ||
| 30 | + */ | ||
| 31 | +@Command(scope = "onos", name = "subnet-remove", description = "Supports for removing a subnet") | ||
| 32 | +public class SubnetRemoveCommand extends AbstractShellCommand { | ||
| 33 | + | ||
| 34 | + @Argument(index = 0, name = "id", description = "Subnet SubnetId Id", required = true, | ||
| 35 | + multiValued = false) | ||
| 36 | + String id = null; | ||
| 37 | + | ||
| 38 | + @Override | ||
| 39 | + protected void execute() { | ||
| 40 | + SubnetService service = get(SubnetService.class); | ||
| 41 | + Set<SubnetId> subnetsSet = Sets.newHashSet(); | ||
| 42 | + subnetsSet.add(SubnetId.subnetId(id)); | ||
| 43 | + service.removeSubnets(subnetsSet); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 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) | ||
| 91 | + Iterable<HostRoute> hostRoutes = null; | ||
| 92 | + | ||
| 93 | + @Option(name = "-a", aliases = "--allocationPools", | ||
| 94 | + description = "Subnet jsonnode allocationPools", required = false, multiValued = false) | ||
| 95 | + Iterable<AllocationPool> allocationPools = Sets.newHashSet();; | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + protected void execute() { | ||
| 99 | + SubnetService service = get(SubnetService.class); | ||
| 100 | + if (id == null || networkId == null || tenantId == null) { | ||
| 101 | + print(null, "id,networkId,tenantId can not be null"); | ||
| 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 | +} |
-
Please register or login to post a comment