From 487e0add3acfe71a621bfd067e7583e1601c979d Mon Sep 17 00:00:00 2001 From: Suresh Kumar Anaparti Date: Thu, 9 Sep 2021 14:08:18 +0530 Subject: [PATCH] Updated pod response, moved the parameters: startip, endip, vlanid, forsystemvms to ipranges (new parameter to hold the list of IP range details). --- .../apache/cloudstack/api/ApiConstants.java | 1 + .../api/response/IpRangeResponse.java | 76 +++++++++++++++++++ .../cloudstack/api/response/PodResponse.java | 52 ++++++++----- .../java/com/cloud/api/ApiResponseHelper.java | 38 +++++++--- .../infra/network/IpRangesTabManagement.vue | 12 +-- 5 files changed, 143 insertions(+), 36 deletions(-) create mode 100644 api/src/main/java/org/apache/cloudstack/api/response/IpRangeResponse.java diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java index f930800b9f86..c6eedc150db7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -565,6 +565,7 @@ public class ApiConstants { public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor"; public static final String KEYWORD = "keyword"; public static final String LIST_ALL = "listall"; + public static final String IP_RANGES = "ipranges"; public static final String SPECIFY_IP_RANGES = "specifyipranges"; public static final String IS_SOURCE_NAT = "issourcenat"; public static final String IS_STATIC_NAT = "isstaticnat"; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/IpRangeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/IpRangeResponse.java new file mode 100644 index 000000000000..c1d3061bce38 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/IpRangeResponse.java @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import com.google.gson.annotations.SerializedName; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.serializer.Param; + +@SuppressWarnings("unused") +public class IpRangeResponse extends BaseResponse { + + @SerializedName(ApiConstants.START_IP) + @Param(description = "the starting IP for the range") + private String startIp; + + @SerializedName(ApiConstants.END_IP) + @Param(description = "the ending IP for the range") + private String endIp; + + @SerializedName(ApiConstants.FOR_SYSTEM_VMS) + @Param(description = "indicates if range is dedicated for CPVM and SSVM") + private String forSystemVms; + + @SerializedName(ApiConstants.VLAN_ID) + @Param(description = "indicates Vlan ID for the range") + private String vlanId; + + public String getStartIp() { + return startIp; + } + + public void setStartIp(String startIp) { + this.startIp = startIp; + } + + public String getEndIp() { + return endIp; + } + + public void setEndIp(String endIp) { + this.endIp = endIp; + } + + public void setForSystemVms(String forSystemVms) { + this.forSystemVms = forSystemVms; + } + + public String getForSystemVms() { + return forSystemVms; + } + + public String getVlanId() { + return vlanId; + } + + public void setVlanId(String vlanId) { + this.vlanId = vlanId; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/PodResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/PodResponse.java index 038e3a2f746c..587fabfae8db 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/PodResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/PodResponse.java @@ -29,15 +29,15 @@ @EntityReference(value = Pod.class) public class PodResponse extends BaseResponseWithAnnotations { - @SerializedName("id") + @SerializedName(ApiConstants.ID) @Param(description = "the ID of the Pod") private String id; - @SerializedName("name") + @SerializedName(ApiConstants.NAME) @Param(description = "the name of the Pod") private String name; - @SerializedName("zoneid") + @SerializedName(ApiConstants.ZONE_ID) @Param(description = "the Zone ID of the Pod") private String zoneId; @@ -45,37 +45,45 @@ public class PodResponse extends BaseResponseWithAnnotations { @Param(description = "the Zone name of the Pod") private String zoneName; - @SerializedName("gateway") + @SerializedName(ApiConstants.GATEWAY) @Param(description = "the gateway of the Pod") private String gateway; - @SerializedName("netmask") + @SerializedName(ApiConstants.NETMASK) @Param(description = "the netmask of the Pod") private String netmask; - @SerializedName("startip") - @Param(description = "the starting IP for the Pod") + @SerializedName(ApiConstants.IP_RANGES) + @Param(description = "the IP ranges for the Pod", responseObject = IpRangeResponse.class, since = "4.16.0") + private List ipRanges; + + @Deprecated(since = "4.16") + @SerializedName(ApiConstants.START_IP) + @Param(description = "the starting IP for the Pod. This parameter is deprecated, please use 'startip' from ipranges parameter.") private List startIp; - @SerializedName("endip") - @Param(description = "the ending IP for the Pod") + @Deprecated(since = "4.16") + @SerializedName(ApiConstants.END_IP) + @Param(description = "the ending IP for the Pod. This parameter is deprecated, please use 'endip' from ipranges parameter.") private List endIp; - @SerializedName("forsystemvms") - @Param(description = "indicates if range is dedicated for CPVM and SSVM") + @Deprecated(since = "4.16") + @SerializedName(ApiConstants.FOR_SYSTEM_VMS) + @Param(description = "indicates if range is dedicated for CPVM and SSVM. This parameter is deprecated, please use 'forsystemvms' from ipranges parameter.") private List forSystemVms; - @SerializedName("vlanid") - @Param(description = "indicates Vlan ID for the range") + @Deprecated(since = "4.16") + @SerializedName(ApiConstants.VLAN_ID) + @Param(description = "indicates Vlan ID for the range. This parameter is deprecated, please use 'vlanid' from ipranges parameter.") private List vlanId; - @SerializedName("allocationstate") + @SerializedName(ApiConstants.ALLOCATION_STATE) @Param(description = "the allocation state of the Pod") private String allocationState; - @SerializedName("capacity") + @SerializedName(ApiConstants.CAPACITY) @Param(description = "the capacity of the Pod", responseObject = CapacityResponse.class) - private List capacitites; + private List capacities; public String getId() { return id; @@ -125,6 +133,10 @@ public void setNetmask(String netmask) { this.netmask = netmask; } + public void setIpRanges(List ipRanges) { + this.ipRanges = ipRanges; + } + public List getStartIp() { return startIp; } @@ -165,11 +177,11 @@ public void setAllocationState(String allocationState) { this.allocationState = allocationState; } - public List getCapacitites() { - return capacitites; + public List getCapacities() { + return capacities; } - public void setCapacitites(List capacitites) { - this.capacitites = capacitites; + public void setCapacities(List capacities) { + this.capacities = capacities; } } diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index 09057e642770..497e3cdb674e 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -85,6 +85,7 @@ import org.apache.cloudstack.api.response.InstanceGroupResponse; import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse; import org.apache.cloudstack.api.response.IpForwardingRuleResponse; +import org.apache.cloudstack.api.response.IpRangeResponse; import org.apache.cloudstack.api.response.IsolationMethodResponse; import org.apache.cloudstack.api.response.LBHealthCheckPolicyResponse; import org.apache.cloudstack.api.response.LBHealthCheckResponse; @@ -1082,24 +1083,40 @@ public GlobalLoadBalancerResponse createGlobalLoadBalancerResponse(GlobalLoadBal @Override public PodResponse createPodResponse(Pod pod, Boolean showCapacities) { String[] ipRange = new String[2]; - List startIp = new ArrayList(); - List endIp = new ArrayList(); + List startIps = new ArrayList(); + List endIps = new ArrayList(); List forSystemVms = new ArrayList(); List vlanIds = new ArrayList(); + List ipRanges = new ArrayList<>(); + if (pod.getDescription() != null && pod.getDescription().length() > 0) { final String[] existingPodIpRanges = pod.getDescription().split(","); for(String podIpRange: existingPodIpRanges) { + IpRangeResponse ipRangeResponse = new IpRangeResponse(); final String[] existingPodIpRange = podIpRange.split("-"); - startIp.add(((existingPodIpRange.length > 0) && (existingPodIpRange[0] != null)) ? existingPodIpRange[0] : ""); - endIp.add(((existingPodIpRange.length > 1) && (existingPodIpRange[1] != null)) ? existingPodIpRange[1] : ""); - forSystemVms.add((existingPodIpRange.length > 2) && (existingPodIpRange[2] != null) ? existingPodIpRange[2] : "0"); - vlanIds.add((existingPodIpRange.length > 3) && + String startIp = ((existingPodIpRange.length > 0) && (existingPodIpRange[0] != null)) ? existingPodIpRange[0] : ""; + ipRangeResponse.setStartIp(startIp); + startIps.add(startIp); + + String endIp = ((existingPodIpRange.length > 1) && (existingPodIpRange[1] != null)) ? existingPodIpRange[1] : ""; + ipRangeResponse.setEndIp(endIp); + endIps.add(endIp); + + String forSystemVm = (existingPodIpRange.length > 2) && (existingPodIpRange[2] != null) ? existingPodIpRange[2] : "0"; + ipRangeResponse.setForSystemVms(forSystemVm); + forSystemVms.add(forSystemVm); + + String vlanId = (existingPodIpRange.length > 3) && (existingPodIpRange[3] != null && !existingPodIpRange[3].equals("untagged")) ? BroadcastDomainType.Vlan.toUri(existingPodIpRange[3]).toString() : - BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED).toString()); + BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED).toString(); + ipRangeResponse.setVlanId(vlanId); + vlanIds.add(vlanId); + + ipRanges.add(ipRangeResponse); } } @@ -1112,8 +1129,9 @@ public PodResponse createPodResponse(Pod pod, Boolean showCapacities) { podResponse.setZoneName(zone.getName()); } podResponse.setNetmask(NetUtils.getCidrNetmask(pod.getCidrSize())); - podResponse.setStartIp(startIp); - podResponse.setEndIp(endIp); + podResponse.setIpRanges(ipRanges); + podResponse.setStartIp(startIps); + podResponse.setEndIp(endIps); podResponse.setForSystemVms(forSystemVms); podResponse.setVlanId(vlanIds); podResponse.setGateway(pod.getGateway()); @@ -1142,7 +1160,7 @@ public PodResponse createPodResponse(Pod pod, Boolean showCapacities) { } // Do it for stats as well. capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId())); - podResponse.setCapacitites(new ArrayList(capacityResponses)); + podResponse.setCapacities(new ArrayList(capacityResponses)); } podResponse.setHasAnnotation(annotationDao.hasAnnotations(pod.getUuid(), AnnotationService.EntityType.POD.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId()))); diff --git a/ui/src/views/infra/network/IpRangesTabManagement.vue b/ui/src/views/infra/network/IpRangesTabManagement.vue index a9bc32a9dad2..22ef9ff4cbd4 100644 --- a/ui/src/views/infra/network/IpRangesTabManagement.vue +++ b/ui/src/views/infra/network/IpRangesTabManagement.vue @@ -229,17 +229,17 @@ export default { this.total = response.listpodsresponse.count || 0 this.pods = response.listpodsresponse.pod ? response.listpodsresponse.pod : [] for (const pod of this.pods) { - if (pod && pod.startip && pod.startip.length > 0) { - for (var idx = 0; idx < pod.startip.length; idx++) { + if (pod && pod.ipranges && pod.ipranges.length > 0) { + for (var idx = 0; idx < pod.ipranges.length; idx++) { this.items.push({ id: pod.id, name: pod.name, gateway: pod.gateway, netmask: pod.netmask, - vlanid: pod.vlanid[idx], - startip: pod.startip[idx], - endip: pod.endip[idx], - forsystemvms: pod.forsystemvms[idx] === '1' + vlanid: pod.ipranges[idx].vlanid, + startip: pod.ipranges[idx].startip, + endip: pod.ipranges[idx].endip, + forsystemvms: pod.ipranges[idx].forsystemvms === '1' }) } }