blob: 50cfaa28d954e4e8245954c7e36043bc62a2d7e5 [file] [log] [blame]
jiangrui9ba8cda2015-08-12 11:41:47 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui9ba8cda2015-08-12 11:41:47 +08003 *
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 */
16package org.onosproject.vtnrsc.cli.subnet;
17
18import java.util.Set;
19
Ray Milkey86ad7bb2018-09-27 12:32:28 -070020import org.apache.karaf.shell.api.action.Argument;
21import org.apache.karaf.shell.api.action.Command;
22import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
jiangrui9ba8cda2015-08-12 11:41:47 +080024import org.onlab.packet.IpAddress;
25import org.onlab.packet.IpAddress.Version;
26import org.onlab.packet.IpPrefix;
27import org.onosproject.cli.AbstractShellCommand;
28import org.onosproject.vtnrsc.AllocationPool;
29import org.onosproject.vtnrsc.DefaultSubnet;
30import org.onosproject.vtnrsc.HostRoute;
31import org.onosproject.vtnrsc.Subnet;
32import org.onosproject.vtnrsc.Subnet.Mode;
33import org.onosproject.vtnrsc.SubnetId;
34import org.onosproject.vtnrsc.TenantId;
35import org.onosproject.vtnrsc.TenantNetworkId;
36import org.onosproject.vtnrsc.subnet.SubnetService;
37
38import com.google.common.collect.Sets;
39
40/**
41 * Supports for updating a subnet.
42 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070043@Service
jiangrui9ba8cda2015-08-12 11:41:47 +080044@Command(scope = "onos", name = "subnet-update", description = "Supports for updating a subnet")
45public class SubnetUpdateCommand extends AbstractShellCommand {
46
47 @Argument(index = 0, name = "id", description = "Subnet Id", required = true,
48 multiValued = false)
49 String id = null;
50
51 @Argument(index = 1, name = "subnetName", description = "Subnet String name", required = true,
52 multiValued = false)
53 String subnetName = null;
54
55 @Argument(index = 2, name = "networkId", description = "Subnet Network Id", required = true,
56 multiValued = false)
57 String networkId = null;
58
59 @Argument(index = 3, name = "tenantId", description = "Subnet Tenant Id", required = true,
60 multiValued = false)
61 String tenantId = null;
62
63 @Option(name = "-i", aliases = "--ipVersion", description = "Subnet Version ipVersion",
64 required = false, multiValued = false)
65 Version ipVersion = null;
66
67 @Option(name = "-c", aliases = "--cidr", description = "Subnet IpPrefix cidr", required = false,
68 multiValued = false)
69 String cidr = "0.0.0.0/0";
70
71 @Option(name = "-g", aliases = "--gatewayIp", description = "Subnet IpAddress gatewayIp",
72 required = false, multiValued = false)
73 String gatewayIp = "0.0.0.0";
74
75 @Option(name = "-d", aliases = "--dhcpEnabled", description = "Subnet boolean dhcpEnabled",
76 required = false, multiValued = false)
77 boolean dhcpEnabled = false;
78
79 @Option(name = "-s", aliases = "--shared", description = "Subnet boolean shared", required = false,
80 multiValued = false)
81 boolean shared = false;
82
83 @Option(name = "-m", aliases = "--ipV6AddressMode", description = "Subnet Mode ipV6AddressMode",
84 required = false, multiValued = false)
85 String ipV6AddressMode = null;
86
87 @Option(name = "-r", aliases = "--ipV6RaMode", description = "Subnet Mode ipV6RaMode",
88 required = false, multiValued = false)
89 String ipV6RaMode = null;
90
91 @Option(name = "-h", aliases = "--hostRoutes", description = "Subnet jsonnode hostRoutes",
92 required = false, multiValued = false)
jiangruiac0879a2015-09-08 16:58:49 +080093 Set<HostRoute> hostRoutes = Sets.newHashSet();
jiangrui9ba8cda2015-08-12 11:41:47 +080094
95 @Option(name = "-a", aliases = "--allocationPools",
96 description = "Subnet jsonnode allocationPools", required = false, multiValued = false)
Sho SHIMIZU9f614a42015-09-11 15:32:46 -070097 Set<AllocationPool> allocationPools = Sets.newHashSet();
jiangrui9ba8cda2015-08-12 11:41:47 +080098
99 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -0700100 protected void doExecute() {
jiangrui9ba8cda2015-08-12 11:41:47 +0800101 SubnetService service = get(SubnetService.class);
102 if (id == null || networkId == null || tenantId == null) {
Satish K1b81f852015-11-29 15:32:23 +0530103 print("id,networkId,tenantId can not be null");
jiangrui9ba8cda2015-08-12 11:41:47 +0800104 return;
105 }
106 Subnet subnet = new DefaultSubnet(SubnetId.subnetId(id), subnetName,
107 TenantNetworkId.networkId(networkId),
108 TenantId.tenantId(tenantId), ipVersion,
109 cidr == null ? null : IpPrefix.valueOf(cidr),
110 gatewayIp == null ? null : IpAddress.valueOf(gatewayIp),
111 dhcpEnabled, shared, hostRoutes,
112 ipV6AddressMode == null ? null : Mode.valueOf(ipV6AddressMode),
113 ipV6RaMode == null ? null : Mode.valueOf(ipV6RaMode),
114 allocationPools);
115 Set<Subnet> subnetsSet = Sets.newHashSet();
116 subnetsSet.add(subnet);
117 service.updateSubnets(subnetsSet);
118 }
119
120}