ScaleComputing / HyperCoreAnsibleCollection

Official Ansible collection for Scale Computing SC//HyperCore (HC3) v1 API
GNU General Public License v3.0
12 stars 8 forks source link

Change `machine_type` using `vm` or `vm_params` module #287

Closed justinc1 closed 7 months ago

justinc1 commented 9 months ago

The PR will make machine_type changable using vm_params or vm module.

Implementation detail how to change BIOS VM to UEFI:

Sorry you are reading this. Touching the shotdown/reboot part exploded. Many functions were returning reboot to signal VM needs to be rebooted (but caller need to know if VM was running before). Before touching implementation I added extra check to (some) integration tests to check value of vm_rebooted. This showed some bugs - (if I remember correctly) modules were returning vm_rebooted as True when VM was not even running initially. Or we tested module only on stopped VM. I think (didn't try to check) we might be also rebooting VM more than once during module invocation. PR extends some of integration tests - not all.

The VM.reboot field was removed from code. Sometimes it was meaning VM needs to be rebooted (but only if it was running), sometimes it was meaning VM was rebooted. It is replaced by flags _was_nice_shutdown_tried, _was_force_shutdown_tried,_was_start_tried`. Makes usage easier, we just need to make sure the same VM object is used all the time.

Some bugs or potential bugs remain - there are about 5 TODOs in PR. I will create a separate issue(s) for them, this PR is already to big. Beside vm and vm_params module also vm_nic module should now work correctly (regarding vm_reboot). The vm_disk and vm_boot_devices were left on TODO list.

Some changes are cosmetic. We had FROM_HYPERCORE_TO_ANSIBLE_POWER_STATE and FROM_ANSIBLE_TO_HYPERCORE_POWER_STATE mappings. But FROM_ANSIBLE_TO_HYPERCORE_POWER_STATE was not about states, it was about state changes - so I renamed it to _ACTIONS.

The module checks VM has all required disks before changing machine_type (UEFI VM is bootable only if NVRAM disk is present). But likely we want also to prevent removing NVRAM disk from UEFI VM - this is not implemented yet.

Fixes #284