Skip to content

Commit

Permalink
Merge pull request #1644 from dcos/state-progress
Browse files Browse the repository at this point in the history
 Ignore paused VMs
  • Loading branch information
adamtheturtle authored Apr 8, 2019
2 parents 6ea898f + 00423d8 commit ccfbd27
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/dcos_e2e_cli/dcos_vagrant/commands/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ def _description_from_vm_name(vm_name: str) -> str:
return str(description)


def _state_from_vm_name(vm_name: str) -> str:
"""
Given the name of a VirtualBox VM, return its VM state, such as
"running".
See
https://www.virtualbox.org/sdkref/_virtual_box_8idl.html#a80b08f71210afe16038e904a656ed9eb
for possible states.
"""
virtualbox_vm = vertigo_py.VM(name=vm_name) # type: ignore
info = virtualbox_vm.parse_info() # type: Dict[str, str]
return info['VMState']


@functools.lru_cache()
def _running_vm_names() -> Set[str]:
"""
Expand All @@ -53,7 +67,13 @@ def _running_vm_names() -> Set[str]:
for line in lines:
vm_name_in_quotes, _ = line.split(' ')
vm_name = vm_name_in_quotes[1:-1]
vm_names.add(vm_name)
state = _state_from_vm_name(vm_name=vm_name)
if state == 'running':
# A VM can be manually paused. This can be problematic if someone
# pauses a VM, then creates a new one with the same cluster ID.
# However, we work on the assumption that a user will not manually
# interfere with VirtualBox.
vm_names.add(vm_name)
return vm_names


Expand Down

0 comments on commit ccfbd27

Please sign in to comment.