Skip to content

Commit 59a3015

Browse files
sureshanapartivishesh92
authored andcommitted
Update power state after vm stop confirmation (as power state 'PowerOn' is kept after vm stop and not updated later)
1 parent 8209684 commit 59a3015

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@
213213
import com.cloud.service.dao.ServiceOfferingDao;
214214
import com.cloud.storage.DiskOfferingVO;
215215
import com.cloud.storage.ScopeType;
216-
import com.cloud.storage.Storage.ImageFormat;
217216
import com.cloud.storage.Storage;
217+
import com.cloud.storage.Storage.ImageFormat;
218218
import com.cloud.storage.StorageManager;
219219
import com.cloud.storage.StoragePool;
220220
import com.cloud.storage.VMTemplateVO;
@@ -2208,9 +2208,14 @@ private void advanceStop(final VMInstanceVO vm, final boolean cleanUpEvenIfUnabl
22082208

22092209
boolean result = stateTransitTo(vm, Event.OperationSucceeded, null);
22102210
if (result) {
2211-
if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) {
2212-
ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
2213-
resourceCountDecrement(vm.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize()));
2211+
if (VirtualMachine.Type.User.equals(vm.type)) {
2212+
vm.setPowerState(PowerState.PowerOff);
2213+
_vmDao.update(vm.getId(), vm);
2214+
2215+
if (ResourceCountRunningVMsonly.value()) {
2216+
ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
2217+
resourceCountDecrement(vm.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize()));
2218+
}
22142219
}
22152220
} else {
22162221
throw new CloudRuntimeException("unable to stop " + vm);

0 commit comments

Comments
 (0)