Removed the `relative_key_path` parameter from GCPHandler class because it's unused and has a misleading name.
This commit is contained in:
parent
c45de9dae7
commit
7a03a9504d
|
@ -12,18 +12,17 @@ class GCPHandler(object):
|
||||||
MACHINE_STOPPING_COMMAND = "gcloud compute instances stop %s --zone=%s"
|
MACHINE_STOPPING_COMMAND = "gcloud compute instances stop %s --zone=%s"
|
||||||
|
|
||||||
# Key path location relative to this file
|
# Key path location relative to this file
|
||||||
DEFAULT_RELATIVE_KEY_PATH = "../../gcp_keys/gcp_key.json"
|
RELATIVE_KEY_PATH = "../../gcp_keys/gcp_key.json"
|
||||||
DEFAULT_ZONE = "europe-west3-a"
|
DEFAULT_ZONE = "europe-west3-a"
|
||||||
DEFAULT_PROJECT = "guardicore-22050661"
|
DEFAULT_PROJECT = "guardicore-22050661"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
relative_key_path=DEFAULT_RELATIVE_KEY_PATH,
|
|
||||||
zone=DEFAULT_ZONE,
|
zone=DEFAULT_ZONE,
|
||||||
project_id=DEFAULT_PROJECT,
|
project_id=DEFAULT_PROJECT,
|
||||||
):
|
):
|
||||||
self.zone = zone
|
self.zone = zone
|
||||||
abs_key_path = GCPHandler.get_absolute_key_path(relative_key_path)
|
abs_key_path = GCPHandler.get_absolute_key_path()
|
||||||
|
|
||||||
subprocess.call(GCPHandler.get_auth_command(abs_key_path), shell=True) # noqa: DUO116
|
subprocess.call(GCPHandler.get_auth_command(abs_key_path), shell=True) # noqa: DUO116
|
||||||
LOGGER.info("GCP Handler passed key")
|
LOGGER.info("GCP Handler passed key")
|
||||||
|
@ -33,15 +32,15 @@ class GCPHandler(object):
|
||||||
LOGGER.info("GCP Handler initialized successfully")
|
LOGGER.info("GCP Handler initialized successfully")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_absolute_key_path(relative_key_path: str) -> str:
|
def get_absolute_key_path() -> str:
|
||||||
file_dir = os.path.dirname(os.path.realpath(__file__))
|
absolute_key_path = os.path.join(__file__, GCPHandler.RELATIVE_KEY_PATH)
|
||||||
absolute_key_path = os.path.join(file_dir, relative_key_path)
|
absolute_key_path = os.path.realpath(absolute_key_path)
|
||||||
|
|
||||||
if not os.path.isfile(absolute_key_path):
|
if not os.path.isfile(absolute_key_path):
|
||||||
raise FileNotFoundError(
|
raise FileNotFoundError(
|
||||||
"GCP key not found. " "Add a service key to envs/monkey_zoo/gcp_keys/gcp_key.json"
|
"GCP key not found. " "Add a service key to envs/monkey_zoo/gcp_keys/gcp_key.json"
|
||||||
)
|
)
|
||||||
return os.path.normpath(absolute_key_path)
|
return absolute_key_path
|
||||||
|
|
||||||
def start_machines(self, machine_list):
|
def start_machines(self, machine_list):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue