Skip to content

Commit 482e7eb

Browse files
raveningDaanHoogland
authored andcommitted
New feature: Acquire specific public IP for network (#3775)
Currently in cloudstack, when we click on "Acquire New Ip", it will randomly acquire IP from the pool. With this enhancement, it is possible to select the IP from the drop down IP list of that network. Same thing applies for a VPC as well.
1 parent 06e1212 commit 482e7eb

10 files changed

Lines changed: 562 additions & 13 deletions

File tree

api/src/main/java/com/cloud/network/NetworkService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface NetworkService {
5656

5757
List<? extends Network> getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner);
5858

59-
IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displayIp) throws ResourceAllocationException, InsufficientAddressCapacityException,
59+
IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displayIp, String ipaddress) throws ResourceAllocationException, InsufficientAddressCapacityException,
6060
ConcurrentOperationException;
6161

6262
boolean releaseIpAddress(long ipAddressId) throws InsufficientAddressCapacityException;

api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd implements UserCmd {
125125
authorized = {RoleType.Admin})
126126
private Boolean display;
127127

128+
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="IP Address to be associated")
129+
private String ipAddress;
130+
128131
/////////////////////////////////////////////////////
129132
/////////////////// Accessors ///////////////////////
130133
/////////////////////////////////////////////////////
@@ -178,6 +181,10 @@ public Integer getRegionId() {
178181
return regionId;
179182
}
180183

184+
public String getIpAddress() {
185+
return ipAddress;
186+
}
187+
181188
public Long getNetworkId() {
182189
if (vpcId != null) {
183190
return null;
@@ -306,7 +313,7 @@ public void create() throws ResourceAllocationException {
306313
IpAddress ip = null;
307314

308315
if (!isPortable()) {
309-
ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNetworkId(), getDisplayIp());
316+
ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNetworkId(), getDisplayIp(), ipAddress);
310317
} else {
311318
ip = _networkService.allocatePortableIP(_accountService.getAccount(getEntityOwnerId()), 1, getZoneId(), getNetworkId(), getVpcId());
312319
}

engine/components-api/src/main/java/com/cloud/network/IpAddressManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void transferPortableIP(long ipAddrId, long currentNetworkId, long newNetworkId)
169169
PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat)
170170
throws ConcurrentOperationException, InsufficientAddressCapacityException;
171171

172-
IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerId, DataCenter zone, Boolean displayIp)
172+
IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerId, DataCenter zone, Boolean displayIp, String ipaddress)
173173
throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException;
174174

175175
PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List<Long> vlanDbIds, Long networkId, String requestedIp, boolean isSystem)

plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/element/CiscoVnmcElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public boolean implement(final Network network, final NetworkOffering offering,
353353
try {
354354
Account caller = CallContext.current().getCallingAccount();
355355
long callerUserId = CallContext.current().getCallingUserId();
356-
outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone, true);
356+
outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone, true, null);
357357
} catch (ResourceAllocationException e) {
358358
s_logger.error("Unable to allocate additional public Ip address. Exception details " + e);
359359
throw new CloudRuntimeException("Unable to allocate additional public Ip address. Exception details " + e);

server/src/main/java/com/cloud/network/IpAddressManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ private IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId) thr
444444

445445
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
446446

447-
return allocateIp(ipOwner, isSystem, caller, callerUserId, zone, null);
447+
return allocateIp(ipOwner, isSystem, caller, callerUserId, zone, null, null);
448448
}
449449

450450
// An IP association is required in below cases
@@ -1132,7 +1132,7 @@ public void releasePodIp(Long id) throws CloudRuntimeException {
11321132

11331133
@DB
11341134
@Override
1135-
public IpAddress allocateIp(final Account ipOwner, final boolean isSystem, Account caller, long callerUserId, final DataCenter zone, final Boolean displayIp)
1135+
public IpAddress allocateIp(final Account ipOwner, final boolean isSystem, Account caller, long callerUserId, final DataCenter zone, final Boolean displayIp, final String ipaddress)
11361136
throws ConcurrentOperationException,
11371137
ResourceAllocationException, InsufficientAddressCapacityException {
11381138

@@ -1166,7 +1166,7 @@ public IpAddress allocateIp(final Account ipOwner, final boolean isSystem, Accou
11661166
ip = Transaction.execute(new TransactionCallbackWithException<PublicIp, InsufficientAddressCapacityException>() {
11671167
@Override
11681168
public PublicIp doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException {
1169-
PublicIp ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, null, isSystem, null, displayIp, false);
1169+
PublicIp ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, ipaddress, isSystem, null, displayIp, false);
11701170

11711171
if (ip == null) {
11721172
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public List<? extends Network> getIsolatedNetworksWithSourceNATOwnedByAccountInZ
520520

521521
@Override
522522
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true)
523-
public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displayIp)
523+
public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displayIp, String ipaddress)
524524
throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
525525

526526
Account caller = CallContext.current().getCallingAccount();
@@ -544,7 +544,7 @@ public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolea
544544
if (s_logger.isDebugEnabled()) {
545545
s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId());
546546
}
547-
return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp);
547+
return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp, ipaddress);
548548
} else {
549549
throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone"
550550
+ " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
@@ -555,7 +555,7 @@ public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolea
555555
_accountMgr.checkAccess(caller, null, false, ipOwner);
556556
}
557557

558-
return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp);
558+
return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp, ipaddress);
559559
}
560560

561561
@Override

server/src/test/java/com/cloud/vpc/MockNetworkManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public List<? extends Network> getIsolatedNetworksOwnedByAccountInZone(long zone
160160
* @see com.cloud.network.NetworkService#allocateIP(com.cloud.user.Account, long, java.lang.Long)
161161
*/
162162
@Override
163-
public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displayIp) throws ResourceAllocationException, InsufficientAddressCapacityException,
163+
public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displayIp, String ipaddress) throws ResourceAllocationException, InsufficientAddressCapacityException,
164164
ConcurrentOperationException {
165165
// TODO Auto-generated method stub
166166
return null;

0 commit comments

Comments
 (0)