Conversation
This commit supports: * enumerating existing VirtualBox VMs * checking the powered state of a VirtualBox VM * powering a VirtualBox VM up or down
setup.py
Outdated
|
|
||
| setup(name='vm_automation', | ||
| version='0.1.2', | ||
| version='0.1.3', |
There was a problem hiding this comment.
No bump here 0.1.2 is the currently in development version.
There was a problem hiding this comment.
OK, wasn't sure since I was adding a dependency and keyword. Will un-bump.
| self.vmSession.console.power_down() | ||
| self.vmSession.unlock_machine() | ||
| self.vmSession = None | ||
| return |
There was a problem hiding this comment.
Can you expand this out to have all methods implemented from workstationVm for Server and VM classes?
Throwing some sort of not implemented or returning false for not yet supported items seems a good start to make these classes interchangeable.
NOTE: I went with the NotImplmentedError exception, which appears to be acceptable for this use case based on random googling and the [Python3 docs](https://docs.python.org/3/library/exceptions.html#NotImplementedError). Happy to change if a different one would be preferable.
|
Updated...! |
This requires the [VirtualBox Guest Additions](https://www.virtualbox.org/manual/ch04.html) to be properly installed+running in the guest VM to work.
jmartin-tech
left a comment
There was a problem hiding this comment.
Issues in testing, I can address if need be.
| return None | ||
|
|
||
| def enumerateVms(self, negFilter = None): | ||
| for vm in self.vm.machines: |
There was a problem hiding this comment.
This looks to fail when no vms already exist...
>>> myserver.enumerateVms()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "vm_automation/virtualboxVm.py", line 20, in enumerateVms
self.vmList.append(virtualboxVm(self, vm))
File "vm_automation/virtualboxVm.py", line 56, in __init__
self.vmName = str(self.vmObject.name)
File "/home/msfadmin/.pyenv/versions/2.7.13/lib/python2.7/site-packages/virtualbox/library.py", line 9619, in name
ret = self._get_attr("name")
File "/home/msfadmin/.pyenv/versions/2.7.13/lib/python2.7/site-packages/virtualbox/library_base.py", line 165, in _get_attr
attr = self._search_attr(name, prefix='get')
File "/home/msfadmin/.pyenv/versions/2.7.13/lib/python2.7/site-packages/virtualbox/library_base.py", line 152, in _search_attr
attr = getattr(self._i, attr_name, self)
File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/client/__init__.py", line 381, in __getattr__
return getattr(interface, attr)
File "/usr/lib/virtualbox/sdk/bindings/xpcom/python/xpcom/client/__init__.py", line 467, in __getattr__
return XPTC_InvokeByIndex(self._comobj_, method_index, args)
xpcom.Exception: 0x80070005 (The object functionality is limited)
There was a problem hiding this comment.
Hah, welp. Good catch! I can fix...
| return None | ||
|
|
||
| def enumerateVms(self, negFilter = None): | ||
| for vm in self.vm.machines: |
There was a problem hiding this comment.
Enumerating the Vms available does not clear the list on each pass, when a vm is renamed by another task the list "expands" instead of changes.
>>> myserver.enumerateVms()
True
>>> myserver.vmList
[]
>>> myserver.enumerateVms()
True
>>> myserver.vmList
[<vm_automation.virtualboxVm.virtualboxVm instance at 0x7fecc9505680>]
>>> for vm in myserver.vmList:
... print(vm.vmName)
...
vm
>>> myserver.enumerateVms()
True
>>> for vm in myserver.vmList:
... print(vm.vmName)
...
vm
Nexpose
>>> myserver.vmList
[<vm_automation.virtualboxVm.virtualboxVm instance at 0x7fecc9505680>, <vm_automation.virtualboxVm.virtualboxVm instance at 0x7fecc95057e8>]
|
PR updated to clear the list of VMs prior to enumeration. Upon closer inspection, the stacktrace (above) when no VMs are present is interesting, as that loop should only be entered when there is at least one VirtualBox VM present (i.e. self.vm.machines is not an empty list). Each "machine" object should have a name attribute. I'm wondering if maybe the machines list contains an entry for a VM that was removed (allowing the loop body to execute but fail to get the name) or if the machines list is corrupted in some way. I have a LOT of VirtualBox VMs on my system (it's my primary VM host), so I'd prefer to not remove them for replicating this issue. :) FWIW, here's what a machine object should "look" like, I'd be curious if you might check this on your setup, @jmartin-r7, to maybe see what's up with the machines list. Thx! |
|
The fail is not really due to an empty return more likely due to accessing a value that is not there when the virtualbox env had a vm removed directly from disk without using virtualbox commands. Will send details separately for a machine you can test on. |
Using the pyvbox library, we can enumerate all VMs on an install of VirtualBox, check their powered state, and change their powered state (up or down). Offering this PR now to see if this looks like a reasonable direction (and I can go back and add more functionality if this to 'too minimum' for an MVP of a PR).
Also includes some minor verbiage tweaks to the README.md file (e.g. consistent company/product names, removal of trailing spaces, minor stuff...).