Skip to content

Commit e260817

Browse files
SakshamsMice Xia
authored andcommitted
CLOUDSTACK-2130: UpdateDefaultNicForVirtualMachine api should also create usage events for updating new default network
Signed-off-by: Mice Xia <mice_xia@tcloudcomputing.com>
1 parent a37fa39 commit e260817

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,13 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
10241024
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");
10251025
}
10261026

1027+
Network oldDefaultNetwork = null;
1028+
oldDefaultNetwork = _networkModel.getDefaultNetworkForVm(vmId);
1029+
long oldNetworkOfferingId = -1L;
1030+
1031+
if(oldDefaultNetwork!=null) {
1032+
oldNetworkOfferingId = oldDefaultNetwork.getNetworkOfferingId();
1033+
}
10271034
NicVO existingVO = _nicDao.findById(existing.id);
10281035
Integer chosenID = nic.getDeviceId();
10291036
Integer existingID = existing.getDeviceId();
@@ -1055,6 +1062,16 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th
10551062
throw new CloudRuntimeException("Failed to change default nic to " + nic + " and now we have no default");
10561063
} else if (newdefault.getId() == nic.getNetworkId()) {
10571064
s_logger.debug("successfully set default network to " + network + " for " + vmInstance);
1065+
String nicIdString = Long.toString(nic.getId());
1066+
long newNetworkOfferingId = network.getNetworkOfferingId();
1067+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
1068+
vmInstance.getId(), nicIdString, oldNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid());
1069+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
1070+
vmInstance.getId(), nicIdString, newNetworkOfferingId, null, 1L, VirtualMachine.class.getName(), vmInstance.getUuid());
1071+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
1072+
vmInstance.getId(), nicIdString, newNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid());
1073+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vmInstance.getAccountId(), vmInstance.getDataCenterId(),
1074+
vmInstance.getId(), nicIdString, oldNetworkOfferingId, null, 0L, VirtualMachine.class.getName(), vmInstance.getUuid());
10581075
return _vmDao.findById(vmInstance.getId());
10591076
}
10601077

0 commit comments

Comments
 (0)