This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.19 by this push:
     new 674495b162b Fixup startVM on simulator (#9199)
674495b162b is described below

commit 674495b162b509e0c20017c69eae5348266252b1
Author: Vishesh <vishes...@gmail.com>
AuthorDate: Fri Jun 21 15:53:45 2024 +0530

    Fixup startVM on simulator (#9199)
---
 .../com/cloud/agent/manager/MockVmManagerImpl.java | 79 ++++++++--------------
 1 file changed, 29 insertions(+), 50 deletions(-)

diff --git 
a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java
 
b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java
index 67f3e95e872..2ae8e7e8688 100644
--- 
a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java
+++ 
b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java
@@ -137,57 +137,36 @@ public class MockVmManagerImpl extends ManagerBase 
implements MockVmManager {
         }
 
         if (vm == null) {
-            final int vncPort = 0;
-            if (vncPort < 0) {
-                return "Unable to allocate VNC port";
-            }
             vm = new MockVMVO();
-            vm.setCpu(cpuHz);
-            vm.setMemory(ramSize);
-            vm.setPowerState(PowerState.PowerOn);
-            vm.setName(vmName);
-            vm.setVncPort(vncPort);
-            vm.setHostId(host.getId());
-            vm.setBootargs(bootArgs);
-            if (vmName.startsWith("s-")) {
-                vm.setType("SecondaryStorageVm");
-            } else if (vmName.startsWith("v-")) {
-                vm.setType("ConsoleProxy");
-            } else if (vmName.startsWith("r-")) {
-                vm.setType("DomainRouter");
-            } else if (vmName.startsWith("i-")) {
-                vm.setType("User");
-            }
-            txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
-            try {
-                txn.start();
-                vm = _mockVmDao.persist((MockVMVO)vm);
-                txn.commit();
-            } catch (final Exception ex) {
-                txn.rollback();
-                throw new CloudRuntimeException("unable to save vm to db " + 
vm.getName(), ex);
-            } finally {
-                txn.close();
-                txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
-                txn.close();
-            }
-        } else {
-            if (vm.getPowerState() == PowerState.PowerOff) {
-                vm.setPowerState(PowerState.PowerOn);
-                txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
-                try {
-                    txn.start();
-                    _mockVmDao.update(vm.getId(), (MockVMVO)vm);
-                    txn.commit();
-                } catch (final Exception ex) {
-                    txn.rollback();
-                    throw new CloudRuntimeException("unable to update vm " + 
vm.getName(), ex);
-                } finally {
-                    txn.close();
-                    txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
-                    txn.close();
-                }
-            }
+        }
+        vm.setCpu(cpuHz);
+        vm.setMemory(ramSize);
+        vm.setPowerState(PowerState.PowerOn);
+        vm.setName(vmName);
+        vm.setVncPort(0);
+        vm.setHostId(host.getId());
+        vm.setBootargs(bootArgs);
+        if (vmName.startsWith("s-")) {
+            vm.setType("SecondaryStorageVm");
+        } else if (vmName.startsWith("v-")) {
+            vm.setType("ConsoleProxy");
+        } else if (vmName.startsWith("r-")) {
+            vm.setType("DomainRouter");
+        } else if (vmName.startsWith("i-")) {
+            vm.setType("User");
+        }
+        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
+        try {
+            txn.start();
+            vm = _mockVmDao.persist((MockVMVO)vm);
+            txn.commit();
+        } catch (final Exception ex) {
+            txn.rollback();
+            throw new CloudRuntimeException("unable to save vm to db " + 
vm.getName(), ex);
+        } finally {
+            txn.close();
+            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
+            txn.close();
         }
 
         if (vm.getPowerState() == PowerState.PowerOn && 
vmName.startsWith("s-")) {

Reply via email to