@@ -1235,21 +1235,9 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
1235
1235
1236
1236
long destHostId = dest .getHost ().getId ();
1237
1237
vm .setPodIdToDeployIn (dest .getPod ().getId ());
1238
- final Long cluster_id = dest .getCluster ().getId ();
1239
- final ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao .findDetail (cluster_id , VmDetailConstants .CPU_OVER_COMMIT_RATIO );
1240
- final ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao .findDetail (cluster_id , VmDetailConstants .MEMORY_OVER_COMMIT_RATIO );
1241
-
1242
- if (userVmDetailsDao .findDetail (vm .getId (), VmDetailConstants .CPU_OVER_COMMIT_RATIO ) == null &&
1243
- (Float .parseFloat (cluster_detail_cpu .getValue ()) > 1f || Float .parseFloat (cluster_detail_ram .getValue ()) > 1f )) {
1244
- userVmDetailsDao .addDetail (vm .getId (), VmDetailConstants .CPU_OVER_COMMIT_RATIO , cluster_detail_cpu .getValue (), true );
1245
- userVmDetailsDao .addDetail (vm .getId (), VmDetailConstants .MEMORY_OVER_COMMIT_RATIO , cluster_detail_ram .getValue (), true );
1246
- } else if (userVmDetailsDao .findDetail (vm .getId (), VmDetailConstants .CPU_OVER_COMMIT_RATIO ) != null ) {
1247
- userVmDetailsDao .addDetail (vm .getId (), VmDetailConstants .CPU_OVER_COMMIT_RATIO , cluster_detail_cpu .getValue (), true );
1248
- userVmDetailsDao .addDetail (vm .getId (), VmDetailConstants .MEMORY_OVER_COMMIT_RATIO , cluster_detail_ram .getValue (), true );
1249
- }
1238
+ final Long clusterId = dest .getCluster ().getId ();
1239
+ updateOverCommitRatioForVmProfile (vmProfile , clusterId );
1250
1240
1251
- vmProfile .setCpuOvercommitRatio (Float .parseFloat (cluster_detail_cpu .getValue ()));
1252
- vmProfile .setMemoryOvercommitRatio (Float .parseFloat (cluster_detail_ram .getValue ()));
1253
1241
StartAnswer startAnswer = null ;
1254
1242
1255
1243
try {
@@ -1264,7 +1252,7 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
1264
1252
resetVmNicsDeviceId (vm .getId ());
1265
1253
_networkMgr .prepare (vmProfile , dest , ctx );
1266
1254
if (vm .getHypervisorType () != HypervisorType .BareMetal ) {
1267
- checkAndAttemptMigrateVmAcrossCluster (vm , cluster_id , dest .getStorageForDisks ());
1255
+ checkAndAttemptMigrateVmAcrossCluster (vm , clusterId , dest .getStorageForDisks ());
1268
1256
volumeMgr .prepare (vmProfile , dest );
1269
1257
}
1270
1258
@@ -1462,6 +1450,27 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
1462
1450
}
1463
1451
}
1464
1452
1453
+ private void updateOverCommitRatioForVmProfile (VirtualMachineProfile vmProfile , long clusterId ) {
1454
+ final ClusterDetailsVO clusterDetailCpu = _clusterDetailsDao .findDetail (clusterId , VmDetailConstants .CPU_OVER_COMMIT_RATIO );
1455
+ final ClusterDetailsVO clusterDetailRam = _clusterDetailsDao .findDetail (clusterId , VmDetailConstants .MEMORY_OVER_COMMIT_RATIO );
1456
+ final float parsedClusterCpuDetailCpu = Float .parseFloat (clusterDetailCpu .getValue ());
1457
+ final float parsedClusterDetailRam = Float .parseFloat (clusterDetailRam .getValue ());
1458
+ UserVmDetailVO vmDetailCpu = userVmDetailsDao .findDetail (vmProfile .getId (), VmDetailConstants .CPU_OVER_COMMIT_RATIO );
1459
+ UserVmDetailVO vmDetailRam = userVmDetailsDao .findDetail (vmProfile .getId (), VmDetailConstants .MEMORY_OVER_COMMIT_RATIO );
1460
+
1461
+ if ((vmDetailCpu == null && parsedClusterCpuDetailCpu > 1f ) ||
1462
+ (vmDetailCpu != null && Float .parseFloat (vmDetailCpu .getValue ()) != parsedClusterCpuDetailCpu )) {
1463
+ userVmDetailsDao .addDetail (vmProfile .getId (), VmDetailConstants .CPU_OVER_COMMIT_RATIO , clusterDetailCpu .getValue (), true );
1464
+ }
1465
+ if ((vmDetailRam == null && parsedClusterDetailRam > 1f ) ||
1466
+ (vmDetailRam != null && Float .parseFloat (vmDetailRam .getValue ()) != parsedClusterDetailRam )) {
1467
+ userVmDetailsDao .addDetail (vmProfile .getId (), VmDetailConstants .MEMORY_OVER_COMMIT_RATIO , clusterDetailRam .getValue (), true );
1468
+ }
1469
+
1470
+ vmProfile .setCpuOvercommitRatio (Float .parseFloat (clusterDetailCpu .getValue ()));
1471
+ vmProfile .setMemoryOvercommitRatio (Float .parseFloat (clusterDetailRam .getValue ()));
1472
+ }
1473
+
1465
1474
/**
1466
1475
* Setting pod id to null can result in migration of Volumes across pods. This is not desirable for VMs which
1467
1476
* have a volume in Ready state (happens when a VM is shutdown and started again).
@@ -2736,6 +2745,7 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy
2736
2745
_networkMgr .prepareNicForMigration (profile , dest );
2737
2746
volumeMgr .prepareForMigration (profile , dest );
2738
2747
profile .setConfigDriveLabel (VmConfigDriveLabel .value ());
2748
+ updateOverCommitRatioForVmProfile (profile , dest .getHost ().getClusterId ());
2739
2749
2740
2750
final VirtualMachineTO to = toVmTO (profile );
2741
2751
final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand (to );
0 commit comments