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

Signed-off-by: Mice Xia <mice_...@tcloudcomputing.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e2608173
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e2608173
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e2608173

Branch: refs/heads/rbd-snap-clone
Commit: e26081731898e2b3de53fdfb9f58d6fdb017f09f
Parents: a37fa39
Author: Saksham Srivastava <saksham.srivast...@citrix.com>
Authored: Tue May 14 10:39:20 2013 +0530
Committer: Mice Xia <mice_...@tcloudcomputing.com>
Committed: Thu May 16 14:22:36 2013 +0800

----------------------------------------------------------------------
 server/src/com/cloud/vm/UserVmManagerImpl.java |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e2608173/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 8b1a9af..f2c44a4 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -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());
         }
 

Reply via email to