Skip to content

Commit 7cceaae

Browse files
author
Alena Prokharchyk
committed
VPC: moved vpc related code from NetworkManager to VpcManager
Conflicts: api/src/com/cloud/api/commands/AssociateIPAddrCmd.java server/src/com/cloud/network/NetworkManagerImpl.java server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java server/src/com/cloud/network/rules/RulesManagerImpl.java server/src/com/cloud/network/vpc/VpcManagerImpl.java server/test/com/cloud/network/MockNetworkManagerImpl.java
1 parent ebe53a9 commit 7cceaae

13 files changed

Lines changed: 425 additions & 355 deletions

‎api/src/com/cloud/api/commands/AssociateIPAddrCmd.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,13 @@ public void execute() throws ResourceUnavailableException, ResourceAllocationExc
238238
UserContext.current().setEventDetails("Ip Id: " + getEntityId());
239239

240240
IpAddress result = null;
241-
242-
result = _networkService.associateIP(getEntityId(), getNetworkId(), getVpcId());
243241

242+
if (getVpcId() != null) {
243+
result = _vpcService.associateIPToVpc(getEntityId(), getVpcId());
244+
} else if (getNetworkId() != null) {
245+
result = _networkService.associateIPToNetwork(getEntityId(), getNetworkId());
246+
}
247+
244248
if (result != null) {
245249
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
246250
ipResponse.setResponseName(getCommandName());

‎api/src/com/cloud/api/commands/UpdateNetworkCmd.java‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,26 @@ public long getEntityOwnerId() {
116116
@Override
117117
public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
118118
User callerUser = _accountService.getActiveUser(UserContext.current().getCallerUserId());
119-
Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
120-
Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
121-
callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr());
119+
Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
120+
Network network = _networkService.getNetwork(id);
121+
if (network == null) {
122+
throw new InvalidParameterValueException("Couldn't find network by id", null);
123+
}
124+
125+
Network result = null;
126+
if (network.getVpcId() != null) {
127+
result = _vpcService.updateVpcGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
128+
callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr());
129+
} else {
130+
result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
131+
callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr());
132+
}
133+
122134
if (result != null) {
123135
NetworkResponse response = _responseGenerator.createNetworkResponse(result);
124136
response.setResponseName(getCommandName());
125137
this.setResponseObject(response);
126-
}else {
138+
} else {
127139
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network");
128140
}
129141
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,15 @@ PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkI
138138
boolean isVmPartOfNetwork(long vmId, long ntwkId);
139139

140140
/**
141-
* @param entityId
142141
* @param networkId
143-
* @param vpcId
142+
* @param entityId
144143
* @return
145144
* @throws ConcurrentOperationException
146145
* @throws ResourceUnavailableException
147146
* @throws ResourceAllocationException
148147
* @throws InsufficientAddressCapacityException
149148
*/
150-
IpAddress associateIP(long ipId, Long networkId, Long vpcId) throws InsufficientAddressCapacityException,
149+
IpAddress associateIPToNetwork(long ipId, long networkId) throws InsufficientAddressCapacityException,
151150
ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException;
152151

153152
/**

‎api/src/com/cloud/network/vpc/VpcService.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
import com.cloud.api.commands.ListPrivateGatewaysCmd;
2424
import com.cloud.api.commands.ListStaticRoutesCmd;
2525
import com.cloud.exception.ConcurrentOperationException;
26+
import com.cloud.exception.InsufficientAddressCapacityException;
2627
import com.cloud.exception.InsufficientCapacityException;
2728
import com.cloud.exception.NetworkRuleConflictException;
2829
import com.cloud.exception.ResourceAllocationException;
2930
import com.cloud.exception.ResourceUnavailableException;
31+
import com.cloud.network.IpAddress;
3032
import com.cloud.network.Network;
3133
import com.cloud.network.Network.Provider;
3234
import com.cloud.network.Network.Service;
35+
import com.cloud.user.Account;
36+
import com.cloud.user.User;
3337

3438
public interface VpcService {
3539

@@ -221,4 +225,19 @@ public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId
221225
* @return
222226
*/
223227
VpcGateway getVpcGateway(long id);
228+
229+
/**
230+
* @param ipId
231+
* @param vpcId
232+
* @return
233+
* @throws ResourceAllocationException
234+
* @throws ResourceUnavailableException
235+
* @throws InsufficientAddressCapacityException
236+
* @throws ConcurrentOperationException
237+
*/
238+
IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException,
239+
InsufficientAddressCapacityException, ConcurrentOperationException;
240+
241+
public Network updateVpcGuestNetwork(long networkId, String name, String displayText, Account callerAccount,
242+
User callerUser, String domainSuffix, Long ntwkOffId, Boolean changeCidr);
224243
}

‎server/src/com/cloud/network/NetworkManager.java‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.cloud.network.guru.NetworkGuru;
4848
import com.cloud.network.rules.FirewallRule;
4949
import com.cloud.network.rules.StaticNat;
50-
import com.cloud.network.vpc.Vpc;
5150
import com.cloud.offering.NetworkOffering;
5251
import com.cloud.offerings.NetworkOfferingVO;
5352
import com.cloud.user.Account;
@@ -274,8 +273,6 @@ List<PhysicalNetworkSetupInfo> getPhysicalNetworkInfo(long dcId,
274273

275274
public boolean checkIpForService(IPAddressVO ip, Service service, Long networkId);
276275

277-
void checkVirtualNetworkCidrOverlap(Long zoneId, String cidr);
278-
279276
void checkCapabilityForProvider(Set<Provider> providers, Service service,
280277
Capability cap, String capValue);
281278

@@ -319,16 +316,6 @@ void allocateDirectIp(NicProfile nic, DataCenter dc,
319316
PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException;
320317

321318

322-
/**
323-
* @param owner
324-
* @param vpc
325-
* @return
326-
* @throws ConcurrentOperationException
327-
* @throws InsufficientAddressCapacityException
328-
*/
329-
PublicIp assignSourceNatIpAddressToVpc(Account owner, Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException;
330-
331-
332319
/**
333320
* @param accountId
334321
* @param zoneId
@@ -409,13 +396,6 @@ IPAddressVO associateIPToGuestNetwork(long ipAddrId, long networkId, boolean rel
409396
InsufficientAddressCapacityException, ConcurrentOperationException;
410397

411398

412-
/**
413-
* @param ipId
414-
* @param networkId TODO
415-
*/
416-
void unassignIPFromVpcNetwork(long ipId, long networkId);
417-
418-
419399
/**
420400
* @param vm
421401
* @param networkId
@@ -479,9 +459,21 @@ NicProfile createNicForVm(Network network, NicProfile requested, ReservationCont
479459

480460

481461
/**
482-
* @param ip
462+
* @param addr
463+
*/
464+
void markPublicIpAsAllocated(IPAddressVO addr);
465+
466+
467+
/**
468+
* @param owner
469+
* @param guestNtwkId
470+
* @param vpcId
471+
* @param dcId
472+
* @param isSourceNat
483473
* @return
474+
* @throws ConcurrentOperationException
475+
* @throws InsufficientAddressCapacityException
484476
*/
485-
boolean ipUsedInVpc(IpAddress ip);
477+
PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat) throws ConcurrentOperationException, InsufficientAddressCapacityException;
486478

487479
}

0 commit comments

Comments
 (0)