Skip to content

Commit 697aa45

Browse files
author
Alena Prokharchyk
committed
VPC: unplugNic - release the nic in the DB only after the command is executed succesfully on the backend
Conflicts: api/src/com/cloud/agent/api/routing/SetStaticRouteCommand.java server/src/com/cloud/network/NetworkManagerImpl.java server/test/com/cloud/network/MockNetworkManagerImpl.java
1 parent f59b935 commit 697aa45

4 files changed

Lines changed: 31 additions & 69 deletions

File tree

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package com.cloud.network;
1818

19-
import java.net.URI;
2019
import java.util.ArrayList;
2120
import java.util.List;
2221
import java.util.Map;
@@ -387,17 +386,6 @@ NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, D
387386
InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
388387

389388

390-
/**
391-
* @param vmProfile
392-
* @param network
393-
* @return TODO
394-
* @throws ConcurrentOperationException
395-
* @throws ResourceUnavailableException
396-
*/
397-
NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network)
398-
throws ConcurrentOperationException, ResourceUnavailableException;
399-
400-
401389
/**
402390
* @param vm
403391
* @param network
@@ -446,13 +434,11 @@ IPAddressVO associateIPToGuestNetwork(long ipAddrId, long networkId) throws Reso
446434

447435
/**
448436
* @param vmProfile
449-
* @param network
450-
* @param broadcastUri
451-
* @return
437+
* @param nic TODO
452438
* @throws ConcurrentOperationException
453439
* @throws ResourceUnavailableException
454440
*/
455-
NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri)
441+
void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic)
456442
throws ConcurrentOperationException, ResourceUnavailableException;
457443

458444

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,37 +2264,20 @@ public void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boo
22642264
ConcurrentOperationException, ResourceUnavailableException {
22652265
List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
22662266
for (NicVO nic : nics) {
2267-
NetworkVO network = _networksDao.findById(nic.getNetworkId());
2268-
releaseNic(vmProfile, nic, network);
2267+
releaseNic(vmProfile, nic);
22692268
}
22702269
}
2271-
2272-
@Override
2273-
public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network)
2274-
throws ConcurrentOperationException, ResourceUnavailableException {
2275-
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vmProfile.getId());
2276-
releaseNic(vmProfile, nic, network);
2277-
2278-
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
2279-
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
2280-
return profile;
2281-
}
2282-
2283-
22842270
@Override
2285-
public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri)
2271+
public void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic)
22862272
throws ConcurrentOperationException, ResourceUnavailableException {
2287-
NicVO nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vmProfile.getId(), broadcastUri.toString());
2288-
releaseNic(vmProfile, nic, network);
2289-
2290-
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
2291-
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
2292-
return profile;
2273+
NicVO nicVO = _nicDao.findById(nic.getId());
2274+
releaseNic(vmProfile, nicVO);
22932275
}
22942276

22952277

2296-
protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic, NetworkVO network)
2278+
protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic)
22972279
throws ConcurrentOperationException, ResourceUnavailableException {
2280+
NetworkVO network = _networksDao.findById(nic.getNetworkId());
22982281
if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
22992282
Nic.State originalState = nic.getState();
23002283
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,6 @@ public NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType) {
24932493
@Override
24942494
public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
24952495
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
2496-
NetworkVO networkVO = _networkDao.findById(network.getId());
24972496
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
24982497
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
24992498

@@ -2503,28 +2502,32 @@ public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broad
25032502
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
25042503
Host host = _hostDao.findById(vm.getHostId());
25052504
DeployDestination dest = new DeployDestination(dc, null, null, host);
2506-
2507-
//1) Release the nic
2508-
NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO, broadcastUri);
2509-
2510-
//2) Convert vmProfile to vmTO
25112505
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
25122506
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
25132507
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
25142508

2515-
NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
2509+
Nic nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
2510+
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
2511+
_networkMgr.getNetworkRate(network.getId(), vm.getId()),
2512+
_networkMgr.isSecurityGroupSupportedInNetwork(network),
2513+
_networkMgr.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
25162514

2515+
//1) Unplug the nic
2516+
NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
25172517
s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network);
25182518
boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest);
2519-
//4) Unplug the nic
25202519
if (result) {
25212520
s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network );
25222521
} else {
25232522
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
25242523
return false;
25252524
}
25262525

2527-
//6) Remove the nic
2526+
//2) Release the nic
2527+
_networkMgr.releaseNic(vmProfile, nic);
2528+
s_logger.debug("Successfully released nic " + nic + "for vm " + vm);
2529+
2530+
//3) Remove the nic
25282531
_networkMgr.removeNic(vmProfile, network);
25292532
return result;
25302533
}

‎server/test/com/cloud/network/MockNetworkManagerImpl.java‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package com.cloud.network;
1818

19-
import java.net.URI;
2019
import java.util.ArrayList;
2120
import java.util.List;
2221
import java.util.Map;
@@ -804,15 +803,6 @@ public NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmPro
804803
return null;
805804
}
806805

807-
/* (non-Javadoc)
808-
* @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.NetworkVO)
809-
*/
810-
@Override
811-
public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException {
812-
// TODO Auto-generated method stub
813-
return null;
814-
}
815-
816806
/* (non-Javadoc)
817807
* @see com.cloud.network.NetworkManager#removeNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network)
818808
*/
@@ -962,8 +952,7 @@ public void checkNetworkPermissions(Account owner, Network network) {
962952
* @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String)
963953
*/
964954
@Override
965-
public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
966-
InsufficientAddressCapacityException {
955+
public void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
967956
// TODO Auto-generated method stub
968957

969958
}
@@ -1066,15 +1055,6 @@ public boolean setupDns(Network network, Provider provider) {
10661055
return false;
10671056
}
10681057

1069-
/* (non-Javadoc)
1070-
* @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.network.NetworkVO, java.net.URI)
1071-
*/
1072-
@Override
1073-
public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
1074-
// TODO Auto-generated method stub
1075-
return null;
1076-
}
1077-
10781058
/* (non-Javadoc)
10791059
* @see com.cloud.network.NetworkManager#getPhysicalNtwksSupportingTrafficType(long, com.cloud.network.Networks.TrafficType)
10801060
*/
@@ -1139,4 +1119,14 @@ public NicProfile allocateAndPrepareNic(Network network, NicProfile requested, R
11391119
// TODO Auto-generated method stub
11401120
return null;
11411121
}
1122+
1123+
/* (non-Javadoc)
1124+
* @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String)
1125+
*/
1126+
@Override
1127+
public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network, String requestedIp) throws InsufficientVirtualNetworkCapcityException,
1128+
InsufficientAddressCapacityException {
1129+
// TODO Auto-generated method stub
1130+
1131+
}
11421132
}

0 commit comments

Comments
 (0)