forked from p15670423/monkey
Zoo: Refactor start and stop gcp machine functions
This commit is contained in:
parent
e6ca0fd3b6
commit
9a96e6ed39
|
@ -45,24 +45,16 @@ def start_machines(machine_list):
|
||||||
"""
|
"""
|
||||||
LOGGER.info("Setting up all GCP machines...")
|
LOGGER.info("Setting up all GCP machines...")
|
||||||
try:
|
try:
|
||||||
arglist = []
|
run_gcp_pool(MACHINE_STARTING_COMMAND, machine_list)
|
||||||
for zone in machine_list:
|
LOGGER.info("GCP machines successfully started.")
|
||||||
arglist.append((MACHINE_STARTING_COMMAND, machine_list, zone))
|
|
||||||
with Pool(2) as pool:
|
|
||||||
pool.map(run_gcp_command, arglist)
|
|
||||||
LOGGER.info("GCP machines successfully started.")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.error("GCP Handler failed to start GCP machines: %s" % e)
|
LOGGER.error("GCP Handler failed to start GCP machines: %s" % e)
|
||||||
|
|
||||||
|
|
||||||
def stop_machines(machine_list):
|
def stop_machines(machine_list):
|
||||||
try:
|
try:
|
||||||
arglist = []
|
run_gcp_pool(MACHINE_STOPPING_COMMAND, machine_list)
|
||||||
for zone in machine_list:
|
LOGGER.info("GCP machines stopped successfully.")
|
||||||
arglist.append((MACHINE_STOPPING_COMMAND, machine_list, zone))
|
|
||||||
with Pool(2) as pool:
|
|
||||||
pool.map(run_gcp_command, arglist)
|
|
||||||
LOGGER.info("GCP machines stopped successfully.")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.error("GCP Handler failed to stop network machines: %s" % e)
|
LOGGER.error("GCP Handler failed to stop network machines: %s" % e)
|
||||||
|
|
||||||
|
@ -78,6 +70,13 @@ def get_set_project_command(project):
|
||||||
def run_gcp_command(arglist):
|
def run_gcp_command(arglist):
|
||||||
gcp_cmd, machine_list, zone = arglist
|
gcp_cmd, machine_list, zone = arglist
|
||||||
subprocess.call( # noqa DUO116
|
subprocess.call( # noqa DUO116
|
||||||
(gcp_cmd % (" ".join(machine_list[zone]), zone)),
|
(gcp_cmd % (" ".join(machine_list), zone)),
|
||||||
shell=True,
|
shell=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def run_gcp_pool(gcp_command, machine_list):
|
||||||
|
arglist = [(gcp_command, machine_list[zone], zone) for zone in machine_list]
|
||||||
|
with Pool(2) as pool:
|
||||||
|
pool.map(run_gcp_command, arglist)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue