-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CLOUDSTACK-9880: Expansion of Management IP Range. #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // 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.command.admin.network; | ||
|
|
||
| import org.apache.log4j.Logger; | ||
|
|
||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.ApiArgValidator; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseAsyncCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.PodResponse; | ||
|
|
||
| import com.cloud.dc.Pod; | ||
| import com.cloud.event.EventTypes; | ||
| import com.cloud.exception.ConcurrentOperationException; | ||
| import com.cloud.exception.InsufficientCapacityException; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.user.Account; | ||
|
|
||
| @APICommand(name = CreateManagementNetworkIpRangeCmd.APINAME, | ||
| description = "Creates a Management network IP range.", | ||
| responseObject = PodResponse.class, | ||
| since = "4.11.0.0", | ||
| requestHasSensitiveInfo = false, | ||
| responseHasSensitiveInfo = false, | ||
| authorized = {RoleType.Admin}) | ||
| public class CreateManagementNetworkIpRangeCmd extends BaseAsyncCmd { | ||
| public static final Logger s_logger = Logger.getLogger(CreateManagementNetworkIpRangeCmd.class); | ||
|
|
||
| public static final String APINAME = "createManagementNetworkIpRange"; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @Parameter(name = ApiConstants.POD_ID, | ||
| type = CommandType.UUID, | ||
| entityType = PodResponse.class, | ||
| required = true, | ||
| description = "UUID of POD, where the IP range belongs to.", | ||
| validations = {ApiArgValidator.PositiveNumber}) | ||
| private Long podId; | ||
|
|
||
| @Parameter(name = ApiConstants.GATEWAY, | ||
| type = CommandType.STRING, | ||
| required = true, | ||
| description = "The gateway for the management network.", | ||
| validations = {ApiArgValidator.NotNullOrEmpty}) | ||
| private String gateway; | ||
|
|
||
| @Parameter(name = ApiConstants.NETMASK, | ||
| type = CommandType.STRING, | ||
| required = true, | ||
| description = "The netmask for the management network.", | ||
| validations = {ApiArgValidator.NotNullOrEmpty}) | ||
| private String netmask; | ||
|
|
||
| @Parameter(name = ApiConstants.START_IP, | ||
| type = CommandType.STRING, | ||
| required = true, | ||
| description = "The starting IP address.", | ||
| validations = {ApiArgValidator.NotNullOrEmpty}) | ||
| private String startIp; | ||
|
|
||
| @Parameter(name = ApiConstants.END_IP, | ||
| type = CommandType.STRING, | ||
| description = "The ending IP address.") | ||
| private String endIp; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| public Long getPodId() { | ||
| return podId; | ||
| } | ||
|
|
||
| public String getGateWay() { | ||
| return gateway; | ||
| } | ||
|
|
||
| public String getNetmask() { | ||
| return netmask; | ||
| } | ||
|
|
||
| public String getStartIp() { | ||
| return startIp; | ||
| } | ||
|
|
||
| public String getEndIp() { | ||
| return endIp; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventType() { | ||
| return EventTypes.EVENT_MANAGEMENT_IP_RANGE_CREATE; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventDescription() { | ||
| return "Creating management ip range from " + getStartIp() + " to " + getEndIp() + " and gateway=" + getGateWay() + ", netmask=" + getNetmask() + " of pod=" + getPodId(); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, | ||
| ResourceAllocationException { | ||
| Pod result = _configService.createPodIpRange(this); | ||
| if (result != null) { | ||
| PodResponse response = _responseGenerator.createPodResponse(result, false); | ||
| response.setResponseName(getCommandName()); | ||
| this.setResponseObject(response); | ||
| } else { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Pod IP Range."); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getCommandName() { | ||
| return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // 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.command.admin.network; | ||
|
|
||
| import org.apache.log4j.Logger; | ||
|
|
||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.ApiArgValidator; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseAsyncCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.PodResponse; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.SuccessResponse; | ||
|
|
||
| import com.cloud.event.EventTypes; | ||
| import com.cloud.exception.ConcurrentOperationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import com.cloud.user.Account; | ||
|
|
||
| @APICommand(name = DeleteManagementNetworkIpRangeCmd.APINAME, | ||
| description = "Deletes a management network IP range. This action is only allowed when no IPs in this range are allocated.", | ||
| responseObject = SuccessResponse.class, | ||
| since = "4.11.0.0", | ||
| requestHasSensitiveInfo = false, | ||
| responseHasSensitiveInfo = false, | ||
| authorized = {RoleType.Admin}) | ||
| public class DeleteManagementNetworkIpRangeCmd extends BaseAsyncCmd { | ||
| public static final Logger s_logger = Logger.getLogger(DeleteManagementNetworkIpRangeCmd.class); | ||
|
|
||
| public static final String APINAME = "deleteManagementNetworkIpRange"; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @Parameter(name = ApiConstants.POD_ID, | ||
| type = CommandType.UUID, | ||
| entityType = PodResponse.class, | ||
| required = true, | ||
| description = "UUID of POD, where the IP range belongs to.", | ||
| validations = ApiArgValidator.PositiveNumber) | ||
| private Long podId; | ||
|
|
||
| @Parameter(name = ApiConstants.START_IP, | ||
| type = CommandType.STRING, | ||
| required = true, | ||
| description = "The starting IP address.", | ||
| validations = ApiArgValidator.NotNullOrEmpty) | ||
| private String startIp; | ||
|
|
||
| @Parameter(name = ApiConstants.END_IP, | ||
| type = CommandType.STRING, | ||
| required = true, | ||
| description = "The ending IP address.", | ||
| validations = ApiArgValidator.NotNullOrEmpty) | ||
| private String endIp; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| public Long getPodId() { | ||
| return podId; | ||
| } | ||
|
|
||
| public String getStartIp() { | ||
| return startIp; | ||
| } | ||
|
|
||
| public String getEndIp() { | ||
| return endIp; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventType() { | ||
| return EventTypes.EVENT_MANAGEMENT_IP_RANGE_DELETE; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventDescription() { | ||
| return "Deleting management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| try { | ||
| _configService.deletePodIpRange(this); | ||
| SuccessResponse response = new SuccessResponse(getCommandName()); | ||
| this.setResponseObject(response); | ||
| } catch (ResourceUnavailableException ex) { | ||
| s_logger.warn("Exception: ", ex); | ||
| throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); | ||
| } catch (ConcurrentOperationException ex) { | ||
| s_logger.warn("Exception: ", ex); | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); | ||
| } catch (Exception e) { | ||
| s_logger.warn("Failed to delete management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(), e); | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getCommandName() { | ||
| return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,11 +55,11 @@ public class PodResponse extends BaseResponse { | |
|
|
||
| @SerializedName("startip") | ||
| @Param(description = "the starting IP for the Pod") | ||
| private String startIp; | ||
| private List<String> startIp; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think this breaks API response?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we are adding multiple ranges in a pod, so there will be a list of startIps and endIps. It is not breaking because if you look at the createPodResponse method of ApiResonseHelper, where the startIp and endIp variable are converted to list. And the Start IP and End IP field are removed from pod detail page. Hope this clarifies. |
||
|
|
||
| @SerializedName("endip") | ||
| @Param(description = "the ending IP for the Pod") | ||
| private String endIp; | ||
| private List<String> endIp; | ||
|
|
||
| @SerializedName("allocationstate") | ||
| @Param(description = "the allocation state of the Pod") | ||
|
|
@@ -117,19 +117,19 @@ public void setNetmask(String netmask) { | |
| this.netmask = netmask; | ||
| } | ||
|
|
||
| public String getStartIp() { | ||
| public List<String> getStartIp() { | ||
| return startIp; | ||
| } | ||
|
|
||
| public void setStartIp(String startIp) { | ||
| public void setStartIp(List<String> startIp) { | ||
| this.startIp = startIp; | ||
| } | ||
|
|
||
| public String getEndIp() { | ||
| public List<String> getEndIp() { | ||
| return endIp; | ||
| } | ||
|
|
||
| public void setEndIp(String endIp) { | ||
| public void setEndIp(List<String> endIp) { | ||
| this.endIp = endIp; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nitin-maharana I saw the related mail so went ahead and looked at it. You don't need my review but I am never merging blindly (unless as RM;)
Is there a reason you changed this file? I don't see any significance in the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @DaanHoogland, Firstly thanks for reviewing it.
I agree this change has no significance to the feature. But exactly I don't remember why I changed the order because I implemented it long back. I guess, one reason must be to maintain all UUIDs on one side, gateway & netmask another side, startIp and endIp together in the middle.