forked from p15670423/monkey
Zoo: Parallelize start and stop of gcp machines
This commit is contained in:
parent
5cee9443ff
commit
e6ca0fd3b6
|
@ -7,7 +7,6 @@ GCP_TEST_MACHINE_LIST = {
|
||||||
"hadoop-2",
|
"hadoop-2",
|
||||||
"hadoop-3",
|
"hadoop-3",
|
||||||
"mssql-16",
|
"mssql-16",
|
||||||
"powershell-3-45",
|
|
||||||
"mimikatz-14",
|
"mimikatz-14",
|
||||||
"mimikatz-15",
|
"mimikatz-15",
|
||||||
"struts2-23",
|
"struts2-23",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from multiprocessing.dummy import Pool
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -44,24 +45,24 @@ def start_machines(machine_list):
|
||||||
"""
|
"""
|
||||||
LOGGER.info("Setting up all GCP machines...")
|
LOGGER.info("Setting up all GCP machines...")
|
||||||
try:
|
try:
|
||||||
|
arglist = []
|
||||||
for zone in machine_list:
|
for zone in machine_list:
|
||||||
subprocess.call( # noqa: DUO116
|
arglist.append((MACHINE_STARTING_COMMAND, machine_list, zone))
|
||||||
(MACHINE_STARTING_COMMAND % (" ".join(machine_list[zone]), zone)),
|
with Pool(2) as pool:
|
||||||
shell=True,
|
pool.map(run_gcp_command, arglist)
|
||||||
)
|
LOGGER.info("GCP machines successfully started.")
|
||||||
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 = []
|
||||||
for zone in machine_list:
|
for zone in machine_list:
|
||||||
subprocess.call( # noqa: DUO116
|
arglist.append((MACHINE_STOPPING_COMMAND, machine_list, zone))
|
||||||
(MACHINE_STOPPING_COMMAND % (" ".join(machine_list[zone]), zone)),
|
with Pool(2) as pool:
|
||||||
shell=True,
|
pool.map(run_gcp_command, arglist)
|
||||||
)
|
LOGGER.info("GCP machines stopped successfully.")
|
||||||
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)
|
||||||
|
|
||||||
|
@ -72,3 +73,11 @@ def get_auth_command(key_path):
|
||||||
|
|
||||||
def get_set_project_command(project):
|
def get_set_project_command(project):
|
||||||
return SET_PROPERTY_PROJECT % project
|
return SET_PROPERTY_PROJECT % project
|
||||||
|
|
||||||
|
|
||||||
|
def run_gcp_command(arglist):
|
||||||
|
gcp_cmd, machine_list, zone = arglist
|
||||||
|
subprocess.call( # noqa DUO116
|
||||||
|
(gcp_cmd % (" ".join(machine_list[zone]), zone)),
|
||||||
|
shell=True,
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue