Skip to content

Commit 34bd922

Browse files
sureshanapartikioiekioie
authored
New API endpoint to update pod management network IP range (#5458)
* Add UpdatePodManagementNetwork api endpoint * Checkstyle changes and added a few methods * Minor Checkstyle change * Refactor UpdatePodManagementNetworkIpRangeCmd.java * Added missing parameters * Cleanup * Addressed the review comments Co-authored-by: kioie <kioieddy@google.com> Co-authored-by: kioie <kioi@outlook.com>
1 parent 121a72c commit 34bd922

File tree

9 files changed

+365
-1
lines changed

9 files changed

+365
-1
lines changed

api/src/main/java/com/cloud/configuration/ConfigurationService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.cloudstack.api.command.admin.network.DeleteManagementNetworkIpRangeCmd;
2525
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
2626
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
27+
import org.apache.cloudstack.api.command.admin.network.UpdatePodManagementNetworkIpRangeCmd;
2728
import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
2829
import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd;
2930
import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd;
@@ -204,6 +205,14 @@ public interface ConfigurationService {
204205
*/
205206
void deletePodIpRange(DeleteManagementNetworkIpRangeCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException;
206207

208+
/**
209+
* Updates a mutually exclusive IP range in the pod.
210+
* @param cmd - The command specifying pod ID, current Start IP, current End IP, new Start IP, new End IP.
211+
* @throws com.cloud.exception.ConcurrentOperationException
212+
* @return Success
213+
*/
214+
void updatePodIpRange(UpdatePodManagementNetworkIpRangeCmd cmd) throws ConcurrentOperationException;
215+
207216
/**
208217
* Edits a pod in the database. Will not allow you to edit pods that are being used anywhere in the system.
209218
*

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public class EventTypes {
328328

329329
public static final String EVENT_MANAGEMENT_IP_RANGE_CREATE = "MANAGEMENT.IP.RANGE.CREATE";
330330
public static final String EVENT_MANAGEMENT_IP_RANGE_DELETE = "MANAGEMENT.IP.RANGE.DELETE";
331+
public static final String EVENT_MANAGEMENT_IP_RANGE_UPDATE = "MANAGEMENT.IP.RANGE.UPDATE";
331332

332333
public static final String EVENT_STORAGE_IP_RANGE_CREATE = "STORAGE.IP.RANGE.CREATE";
333334
public static final String EVENT_STORAGE_IP_RANGE_DELETE = "STORAGE.IP.RANGE.DELETE";

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public class ApiConstants {
9898
public static final String CUSTOMIZED_IOPS = "customizediops";
9999
public static final String CUSTOM_ID = "customid";
100100
public static final String CUSTOM_JOB_ID = "customjobid";
101+
public static final String CURRENT_START_IP = "currentstartip";
102+
public static final String CURRENT_END_IP = "currentendip";
101103
public static final String MIN_IOPS = "miniops";
102104
public static final String MAX_IOPS = "maxiops";
103105
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";
@@ -252,6 +254,8 @@ public class ApiConstants {
252254
public static final String NIC = "nic";
253255
public static final String NIC_NETWORK_LIST = "nicnetworklist";
254256
public static final String NIC_IP_ADDRESS_LIST = "nicipaddresslist";
257+
public static final String NEW_START_IP = "newstartip";
258+
public static final String NEW_END_IP = "newendip";
255259
public static final String NUM_RETRIES = "numretries";
256260
public static final String OFFER_HA = "offerha";
257261
public static final String IS_SYSTEM_OFFERING = "issystem";
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.network;
18+
19+
import org.apache.cloudstack.acl.RoleType;
20+
import org.apache.cloudstack.api.APICommand;
21+
import org.apache.cloudstack.api.ApiArgValidator;
22+
import org.apache.cloudstack.api.ApiConstants;
23+
import org.apache.cloudstack.api.ApiErrorCode;
24+
import org.apache.cloudstack.api.BaseAsyncCmd;
25+
import org.apache.cloudstack.api.Parameter;
26+
import org.apache.cloudstack.api.ServerApiException;
27+
import org.apache.cloudstack.api.response.PodResponse;
28+
import org.apache.cloudstack.api.response.SuccessResponse;
29+
import org.apache.log4j.Logger;
30+
31+
import com.cloud.event.EventTypes;
32+
import com.cloud.exception.ConcurrentOperationException;
33+
import com.cloud.exception.InvalidParameterValueException;
34+
import com.cloud.user.Account;
35+
36+
@APICommand(name = UpdatePodManagementNetworkIpRangeCmd.APINAME,
37+
description = "Updates a management network IP range. Only allowed when no IPs are allocated.",
38+
responseObject = SuccessResponse.class,
39+
since = "4.16.0.0",
40+
requestHasSensitiveInfo = false,
41+
responseHasSensitiveInfo = false,
42+
authorized = {RoleType.Admin})
43+
public class UpdatePodManagementNetworkIpRangeCmd extends BaseAsyncCmd {
44+
45+
public static final Logger s_logger = Logger.getLogger(UpdatePodManagementNetworkIpRangeCmd.class);
46+
47+
public static final String APINAME = "updatePodManagementNetworkIpRange";
48+
49+
/////////////////////////////////////////////////////
50+
//////////////// API parameters /////////////////////
51+
/////////////////////////////////////////////////////
52+
@Parameter(name = ApiConstants.POD_ID,
53+
type = CommandType.UUID,
54+
entityType = PodResponse.class,
55+
required = true,
56+
description = "UUID of POD, where the IP range belongs to.",
57+
validations = {ApiArgValidator.PositiveNumber})
58+
private Long podId;
59+
60+
@Parameter(name = ApiConstants.CURRENT_START_IP,
61+
type = CommandType.STRING,
62+
entityType = PodResponse.class,
63+
required = true,
64+
description = "The current starting IP address.",
65+
validations = {ApiArgValidator.NotNullOrEmpty})
66+
private String currentStartIp;
67+
68+
@Parameter(name = ApiConstants.CURRENT_END_IP,
69+
type = CommandType.STRING,
70+
entityType = PodResponse.class,
71+
required = true,
72+
description = "The current ending IP address.",
73+
validations = {ApiArgValidator.NotNullOrEmpty})
74+
private String currentEndIp;
75+
76+
@Parameter(name = ApiConstants.NEW_START_IP,
77+
type = CommandType.STRING,
78+
description = "The new starting IP address.",
79+
validations = {ApiArgValidator.NotNullOrEmpty})
80+
private String newStartIp;
81+
82+
@Parameter(name = ApiConstants.NEW_END_IP,
83+
type = CommandType.STRING,
84+
description = "The new ending IP address.",
85+
validations = {ApiArgValidator.NotNullOrEmpty})
86+
private String newEndIp;
87+
88+
/////////////////////////////////////////////////////
89+
/////////////////// Accessors ///////////////////////
90+
/////////////////////////////////////////////////////
91+
92+
public Long getPodId() {
93+
return podId;
94+
}
95+
96+
public String getCurrentStartIP() {
97+
return currentStartIp;
98+
}
99+
100+
public String getCurrentEndIP() {
101+
return currentEndIp;
102+
}
103+
104+
public String getNewStartIP() {
105+
return newStartIp;
106+
}
107+
108+
public String getNewEndIP() {
109+
return newEndIp;
110+
}
111+
112+
@Override
113+
public String getEventType() {
114+
return EventTypes.EVENT_MANAGEMENT_IP_RANGE_UPDATE;
115+
}
116+
117+
@Override
118+
public String getEventDescription() {
119+
return "Updating pod management IP range " + getNewStartIP() + "-" + getNewEndIP() + " of Pod: " + getPodId();
120+
}
121+
122+
@Override
123+
public String getCommandName() {
124+
return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX;
125+
}
126+
127+
@Override
128+
public long getEntityOwnerId() {
129+
return Account.ACCOUNT_ID_SYSTEM;
130+
}
131+
132+
/////////////////////////////////////////////////////
133+
/////////////// API Implementation///////////////////
134+
/////////////////////////////////////////////////////
135+
136+
@Override
137+
public void execute() {
138+
if (getNewStartIP() == null && getNewEndIP() == null) {
139+
throw new InvalidParameterValueException("Either new starting IP address or new ending IP address must be specified");
140+
}
141+
142+
try {
143+
_configService.updatePodIpRange(this);
144+
SuccessResponse response = new SuccessResponse(getCommandName());
145+
this.setResponseObject(response);
146+
} catch (ConcurrentOperationException ex) {
147+
s_logger.warn("Exception: ", ex);
148+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
149+
} catch (Exception e) {
150+
s_logger.warn("Failed to update pod management IP range " + getNewStartIP() + "-" + getNewEndIP() + " of Pod: " + getPodId(), e);
151+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
152+
}
153+
}
154+
}

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public interface DataCenterIpAddressDao extends GenericDao<DataCenterIpAddressVO
4141

4242
List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId);
4343

44+
List<DataCenterIpAddressVO> listIpAddressUsage(final long podId, final long dcId, final boolean onlyListAllocated);
45+
4446
int countIPs(long podId, long dcId, boolean onlyCountAllocated);
4547

4648
int countIPs(long dcId, boolean onlyCountAllocated);

engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Date;
2222
import java.util.List;
2323

24-
2524
import org.apache.cloudstack.framework.config.ConfigKey;
2625
import org.apache.cloudstack.framework.config.Configurable;
2726
import org.apache.log4j.Logger;
@@ -238,6 +237,17 @@ public List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId) {
238237
return listBy(sc);
239238
}
240239

240+
@Override
241+
public List<DataCenterIpAddressVO> listIpAddressUsage(final long podId, final long dcId, final boolean onlyListAllocated) {
242+
SearchCriteria<DataCenterIpAddressVO> sc = createSearchCriteria();
243+
if(onlyListAllocated) {
244+
sc.addAnd("takenAt", SearchCriteria.Op.NNULL);
245+
}
246+
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
247+
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
248+
return listBy(sc);
249+
}
250+
241251
@Override
242252
public List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress) {
243253
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();

0 commit comments

Comments
 (0)