Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I want to share my thinking into a refactor.
We currently keep a lot of state and operations code related to VMs in the Daemon object. For instance state, i.e. preparing a VM, VM being deleted, VM shutdown delay, we track that state by moving the instance name between different sets/maps. Operations code are mostly platform-independent VM-control methods (start/shutdown/reboot/install_sshfs/mounts).
I'm in a situation where I want to add another per-VM operation (a maintenance operation which will fire on a timer while VM running). It is a platform independent op, so doesn't belong in the VirtualMachine implementations themselves. Right now, platform independent VM ops are private methods in Daemon itself. So adding this new op means I'll have to add another list to Daemon, and carefully add/remove from the list in sync with the VM state - clunky.
My thinking is to introduce a "VMInstance" class, which will hold per-VM state and platform independent operations (i.e. start/shutdown/reboot/install_sshfs/mounts).
I hope to replace the state sets/maps in Daemon with VMInstance::state() which for example would return Prepared/Exists/Deleted/ - I've to decide if the actual VM state should be included too.
And I also want to move the ops like start/shutdown/reboot/install_sshfs/mounts our of Daemon and create as members of this.
This PR is the first step on this journey, and make it easier to add my per-VM operation.
What do you folks think? Right direction or no?