CLOUDSTACK-2130: UpdateDefaultNicForVirtualMachine api should also create usage events for updating new default network

Signed-off-by: Mice Xia <mice_xia@tcloudcomputing.com>
This commit is contained in:
Saksham Srivastava 2013-05-14 10:39:20 +05:30 committed by Mice Xia
parent a37fa39fe7
commit e260817318
1 changed files with 17 additions and 0 deletions

View File

@ -1024,6 +1024,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
throw new CloudRuntimeException("Failed to find a nic profile for the existing default network. This is bad and probably means some sort of configuration corruption");
}
Network oldDefaultNetwork = null;
oldDefaultNetwork = _networkModel.getDefaultNetworkForVm(vmId);
long oldNetworkOfferingId = -1L;
if(oldDefaultNetwork!=null) {
oldNetworkOfferingId = oldDefaultNetwork.getNetworkOfferingId();
}
NicVO existingVO = _nicDao.findById(existing.id);
Integer chosenID = nic.getDeviceId();
Integer existingID = existing.getDeviceId();
@ -1055,6 +1062,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
throw new CloudRuntimeException("Failed to change default nic to " + nic + " and now we have no default");
} else if (newdefault.getId() == nic.getNetworkId()) {
s_logger.debug("successfully set default network to " + network + " for " + vmInstance);
String nicIdString = Long.toString(nic.getId());
long newNetworkOfferingId = network.getNetworkOfferingId();
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
vmInstance.getId(), nicIdString, oldNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
vmInstance.getId(), nicIdString, newNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
vmInstance.getId(), nicIdString, newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
vmInstance.getId(), nicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid());
return _vmDao.findById(vmInstance.getId());
}