DaanHoogland commented on a change in pull request #3522: New API endpoint:
UpdateVlanIpRange
URL: https://github.com/apache/cloudstack/pull/3522#discussion_r310584112
##########
File path:
server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
##########
@@ -3958,6 +3961,116 @@ public VlanVO doInTransaction(final TransactionStatus
status) {
}
+ @Override
+ public Vlan updateVlanAndPublicIpRange(UpdateVlanIpRangeCmd cmd) throws
ConcurrentOperationException,
+ ResourceUnavailableException, ResourceAllocationException{
+
+ return updateVlanAndPublicIpRange(cmd.getId(),
cmd.getStartIp(),cmd.getEndIp(),
+ cmd.getGateway(),cmd.getNetmask());
+ }
+
+ @DB
+ @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_UPDATE,
eventDescription = "update vlan ip Range", async
+ = false)
+ public Vlan updateVlanAndPublicIpRange(final long id, String startIp,
+ String endIp,
+ String gateway,
+ String netmask) throws
ConcurrentOperationException{
+
+ // verify parameters
+ VlanVO vlanRange = _vlanDao.findById(id);
+ if (vlanRange == null) {
+ throw new InvalidParameterValueException("Please specify a valid
IP range id.");
+ }
+
+ if (gateway == null) {
+ gateway = vlanRange.getVlanGateway();
+ }
+
+ if (netmask == null) {
+ netmask = vlanRange.getVlanNetmask();
+ }
+
+ final String[] existingVlanIPRangeArray =
vlanRange.getIpRange().split("-");
+ final String currentStartIP= existingVlanIPRangeArray[0];
+ final String currentEndIP = existingVlanIPRangeArray [1];
+
+ if(startIp == null){
+ startIp= currentStartIP;
+ }
+
+ if(endIp == null){
+ endIp= currentEndIP;
+ }
+
+ // Check if the VLAN has any allocated public IPs
+ final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(id);
+ for (final IPAddressVO ip : ips) {
+ if (ip.getState()== IpAddress.State.Allocated){
+ if (!Strings.isNullOrEmpty(startIp) &&
NetUtils.ip2Long(startIp) > NetUtils.ip2Long(ip.getAddress().addr())) {
+ throw new InvalidParameterValueException("The start IP
address must have a lower IP address value" +
+ " " +
+ "than" +
+ " "+ ip.getAddress() +
+ " which is already in use.");
+ }
+ if (!Strings.isNullOrEmpty(endIp) && NetUtils.ip2Long(endIp) <
NetUtils.ip2Long(ip.getAddress().addr())) {
Review comment:
👍
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services