Skip to content

Commit 62f0d8e

Browse files
l8556Nikolai Lambrov
andauthored
Refactor VM registration process in VmUpdater (#314)
* Refactor VM registration process in VmUpdater - Enhanced the VM registration logic to first check if the VM is already registered, logging a message if it is. This change improves the clarity of the registration process. - Updated the handling of the VBox file to ensure it exists before proceeding with registration, enhancing error handling and robustness in the VM management workflow. * Refactor VM registration in VmUpdater - Streamlined the VM registration process by directly passing the VBox file path to the `_remove_useless_dvd_images` and `register` methods, enhancing code clarity and reducing redundancy. - This change improves the overall efficiency of the VM update workflow. --------- Co-authored-by: Nikolai Lambrov <[email protected]>
1 parent 4dc3a33 commit 62f0d8e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

frameworks/vm_manager/vm_updater.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,18 @@ def _register_vm(self) -> None:
306306
"""
307307
Register VM in VirtualBox.
308308
"""
309-
if not self.vm.is_registered():
310-
vbox_file = self._find_vbox_file()
311-
if vbox_file and vbox_file.is_file():
312-
self._remove_useless_dvd_images(config_path=str(vbox_file))
313-
self.vm.register(str(vbox_file))
314-
else:
315-
self._log(f"VBox file not found on path: [cyan]{self.vm_dir}[/cyan]", color='red')
309+
if self.vm.is_registered():
310+
self._log(f"VM [cyan]{self.vm.name}[/cyan] is already registered", color='green')
311+
self._remove_useless_dvd_images()
312+
return
313+
314+
vbox_file = self._find_vbox_file()
315+
if not (vbox_file and vbox_file.is_file()):
316+
self._log(f"VBox file not found on path: [cyan]{self.vm_dir}[/cyan]", color='red')
317+
return
318+
319+
self._remove_useless_dvd_images(config_path=str(vbox_file))
320+
self.vm.register(str(vbox_file))
316321

317322
def _move_to_group_dir(self) -> None:
318323
"""

0 commit comments

Comments
 (0)