Ejemplo n.º 1
0
def _description_from_vm_name(vm_name: str) -> str:
    """
    Given the name of a VirtualBox VM, return its description.
    """
    virtualbox_vm = vertigo_py.VM(name=vm_name)  # type: ignore
    info = virtualbox_vm.parse_info()  # type: Dict[str, str]
    escaped_description = info.get('description', '')
    description = escaped_description.encode().decode('unicode_escape')
    return str(description)
Ejemplo n.º 2
0
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']
Ejemplo n.º 3
0
def clean(destroy_running_clusters: bool) -> None:
    """
    Remove VMs created by this tool.

    This is useful in removing paused and aborted VMs.
    VMs are aborted when the host is shut down.
    """
    running_clusters = vm_names_by_cluster(running_only=True)
    all_clusters = vm_names_by_cluster(running_only=False)
    not_running_cluster_names = set(
        all_clusters.keys() - running_clusters.keys(),
    )

    if destroy_running_clusters:
        for cluster_id in running_clusters.keys():
            destroy_cluster(cluster_id=cluster_id)

    for cluster_id in not_running_cluster_names:
        for vm_name in all_clusters[cluster_id]:
            virtualbox_vm = vertigo_py.VM(name=vm_name)  # type: ignore
            virtualbox_vm.unregistervm(delete=True)
            print('not running ', vm_name)