mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Green-test: VirtualboxProviderHeavyTests::test_stop_action
We can now tell instances to stop Related to saltstack/salt#27089 Saltcloud virtualbox provider
This commit is contained in:
parent
8111dcb092
commit
8604be624b
@ -22,7 +22,7 @@ from salt.exceptions import SaltCloudSystemExit
|
|||||||
import salt.config as config
|
import salt.config as config
|
||||||
import salt.utils.cloud as cloud
|
import salt.utils.cloud as cloud
|
||||||
from utils.virtualbox import vb_list_machines, vb_clone_vm, HAS_LIBS, vb_machine_exists, vb_destroy_machine, \
|
from utils.virtualbox import vb_list_machines, vb_clone_vm, HAS_LIBS, vb_machine_exists, vb_destroy_machine, \
|
||||||
vb_machinestate_to_str, vb_get_machine
|
vb_get_machine, vb_stop_vm, treat_machine_dict
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -313,6 +313,22 @@ def destroy(name, call=None):
|
|||||||
|
|
||||||
# TODO implement actions e.g start, stop, restart, etc.
|
# TODO implement actions e.g start, stop, restart, etc.
|
||||||
|
|
||||||
|
def stop(name, call=None):
|
||||||
|
"""
|
||||||
|
Stop a running machine.
|
||||||
|
"""
|
||||||
|
if call != 'action':
|
||||||
|
raise SaltCloudSystemExit(
|
||||||
|
'The instance action must be called with -a or --action.'
|
||||||
|
)
|
||||||
|
|
||||||
|
log.info("Stopping machine: %s" % name)
|
||||||
|
vb_stop_vm(name)
|
||||||
|
machine = vb_get_machine(name)
|
||||||
|
del machine["name"]
|
||||||
|
return treat_machine_dict(machine)
|
||||||
|
|
||||||
|
|
||||||
# TODO implement functions
|
# TODO implement functions
|
||||||
|
|
||||||
def show_image(kwargs, call=None):
|
def show_image(kwargs, call=None):
|
||||||
|
@ -382,6 +382,31 @@ def vb_xpcom_to_attribute_dict(xpcom
|
|||||||
return dict(attribute_tuples)
|
return dict(attribute_tuples)
|
||||||
|
|
||||||
|
|
||||||
|
def treat_machine_dict(machine):
|
||||||
|
"""
|
||||||
|
Make machine presentable for outside world.
|
||||||
|
|
||||||
|
!!!Modifies the input machine!!!
|
||||||
|
|
||||||
|
@param machine:
|
||||||
|
@type machine: dict
|
||||||
|
@return: the modified input machine
|
||||||
|
@rtype: dict
|
||||||
|
"""
|
||||||
|
machine.update({
|
||||||
|
"id": machine.get("id", ""),
|
||||||
|
"image": machine.get("image", ""),
|
||||||
|
"size": "%s MB" % machine.get("memorySize", 0),
|
||||||
|
"state": vb_machinestate_to_str(machine.get("state", -1))[0],
|
||||||
|
"private_ips": [],
|
||||||
|
"public_ips": [],
|
||||||
|
})
|
||||||
|
|
||||||
|
# Replaced keys
|
||||||
|
if "memorySize" in machine:
|
||||||
|
del machine["memorySize"]
|
||||||
|
return machine
|
||||||
|
|
||||||
def vb_machinestate_to_str(machinestate):
|
def vb_machinestate_to_str(machinestate):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user