From acb2bd873b9a60cf23ad5874911dffa10ef63794 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 10 May 2022 18:22:04 +0200 Subject: [PATCH 1/2] feat(Jupyter):added base_url --- VirtualMachineService/ancon/Playbook.py | 48 ++++++++++++++----------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/VirtualMachineService/ancon/Playbook.py b/VirtualMachineService/ancon/Playbook.py index c1e82c9f..168467e7 100644 --- a/VirtualMachineService/ancon/Playbook.py +++ b/VirtualMachineService/ancon/Playbook.py @@ -31,20 +31,20 @@ class Playbook(object): - ACTIVE = "ACTIVE" PLAYBOOK_FAILED = "PLAYBOOK_FAILED" def __init__( - self, - ip, - port, - playbooks_information, - osi_private_key, - public_key, - pool, - loaded_metadata_keys, - cloud_site, + self, + ip, + port, + playbooks_information, + osi_private_key, + public_key, + pool, + loaded_metadata_keys, + cloud_site, + ): self.loaded_metadata_keys = loaded_metadata_keys self.cloud_site = cloud_site @@ -57,6 +57,9 @@ def __init__( None # init process, returncode, standard output, standard error output ) self.returncode = -1 + self.playbooks_information = playbooks_information + LOG.exception(self.playbooks_information) + self.stdout = "" self.stderr = "" # init temporary directories and mandatory generic files @@ -86,10 +89,10 @@ def __init__( ) inventory_string = ( - "[vm]\n" + ip + ":" + port + " ansible_user=ubuntu " - "ansible_ssh_private_key_file=" - + self.private_key.name - + " ansible_python_interpreter=/usr/bin/python3" + "[vm]\n" + ip + ":" + port + " ansible_user=ubuntu " + "ansible_ssh_private_key_file=" + + self.private_key.name + + " ansible_python_interpreter=/usr/bin/python3" ) self.inventory.write(inventory_string) self.inventory.close() @@ -105,12 +108,12 @@ def copy_playbooks_and_init(self, playbooks_information, public_key): self.playbooks_dir + "/change_key_vars_file.yml", self.directory.name ) with open( - self.directory.name + "/change_key_vars_file.yml", mode="r" + self.directory.name + "/change_key_vars_file.yml", mode="r" ) as key_file: data_ck = self.yaml_exec.load(key_file) data_ck["change_key_vars"]["key"] = public_key.strip('"') with open( - self.directory.name + "/change_key_vars_file.yml", mode="w" + self.directory.name + "/change_key_vars_file.yml", mode="w" ) as key_file: self.yaml_exec.dump(data_ck, key_file) self.add_to_playbook_always_lists("change_key") @@ -120,14 +123,14 @@ def copy_playbooks_and_init(self, playbooks_information, public_key): self.playbooks_dir + "/" + self.playbook_exec_name, self.directory.name ) with open( - self.directory.name + "/" + self.playbook_exec_name, mode="r" + self.directory.name + "/" + self.playbook_exec_name, mode="r" ) as generic_playbook: data_gp = self.yaml_exec.load(generic_playbook) data_gp[0]["vars_files"] = self.vars_files data_gp[0]["tasks"][0]["block"] = self.tasks data_gp[0]["tasks"][0]["always"] = self.always_tasks with open( - self.directory.name + "/" + self.playbook_exec_name, mode="w" + self.directory.name + "/" + self.playbook_exec_name, mode="w" ) as generic_playbook: self.yaml_exec.dump(data_gp, generic_playbook) @@ -145,10 +148,15 @@ def load_vars(): data[playbook_name + "_tools"][k] = p_dict if playbook_name in self.loaded_metadata_keys: for k, v in playbook_vars.items(): + LOG.info(playbook_vars) if k == "template_version": data[playbook_name + "_vars"][k] = v if k == "create_only_backend": data[playbook_name + "_vars"][k] = v + if k == "base_url": + data[playbook_name + "_vars"][k] = v + + if playbook_name == OPTIONAL: for k, v in playbook_vars.items(): if k == MOSH: @@ -165,12 +173,12 @@ def load_vars(): try: shutil.copy(self.playbooks_dir + playbook_var_yml, self.directory.name) with open( - self.directory.name + playbook_var_yml, mode="r" + self.directory.name + playbook_var_yml, mode="r" ) as variables: data = self.yaml_exec.load(variables) load_vars() with open( - self.directory.name + playbook_var_yml, mode="w" + self.directory.name + playbook_var_yml, mode="w" ) as variables: self.yaml_exec.dump(data, variables) self.add_to_playbook_lists(playbook_name_local, playbook_name) From 28a413202075eef147b5ea61abd695b835097b1d Mon Sep 17 00:00:00 2001 From: dweinholz Date: Tue, 10 May 2022 16:22:47 +0000 Subject: [PATCH 2/2] fix(Linting):blacked code --- VirtualMachineService/ancon/Playbook.py | 40 ++++++++++++------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/VirtualMachineService/ancon/Playbook.py b/VirtualMachineService/ancon/Playbook.py index 168467e7..f99c8eec 100644 --- a/VirtualMachineService/ancon/Playbook.py +++ b/VirtualMachineService/ancon/Playbook.py @@ -35,16 +35,15 @@ class Playbook(object): PLAYBOOK_FAILED = "PLAYBOOK_FAILED" def __init__( - self, - ip, - port, - playbooks_information, - osi_private_key, - public_key, - pool, - loaded_metadata_keys, - cloud_site, - + self, + ip, + port, + playbooks_information, + osi_private_key, + public_key, + pool, + loaded_metadata_keys, + cloud_site, ): self.loaded_metadata_keys = loaded_metadata_keys self.cloud_site = cloud_site @@ -89,10 +88,10 @@ def __init__( ) inventory_string = ( - "[vm]\n" + ip + ":" + port + " ansible_user=ubuntu " - "ansible_ssh_private_key_file=" - + self.private_key.name - + " ansible_python_interpreter=/usr/bin/python3" + "[vm]\n" + ip + ":" + port + " ansible_user=ubuntu " + "ansible_ssh_private_key_file=" + + self.private_key.name + + " ansible_python_interpreter=/usr/bin/python3" ) self.inventory.write(inventory_string) self.inventory.close() @@ -108,12 +107,12 @@ def copy_playbooks_and_init(self, playbooks_information, public_key): self.playbooks_dir + "/change_key_vars_file.yml", self.directory.name ) with open( - self.directory.name + "/change_key_vars_file.yml", mode="r" + self.directory.name + "/change_key_vars_file.yml", mode="r" ) as key_file: data_ck = self.yaml_exec.load(key_file) data_ck["change_key_vars"]["key"] = public_key.strip('"') with open( - self.directory.name + "/change_key_vars_file.yml", mode="w" + self.directory.name + "/change_key_vars_file.yml", mode="w" ) as key_file: self.yaml_exec.dump(data_ck, key_file) self.add_to_playbook_always_lists("change_key") @@ -123,14 +122,14 @@ def copy_playbooks_and_init(self, playbooks_information, public_key): self.playbooks_dir + "/" + self.playbook_exec_name, self.directory.name ) with open( - self.directory.name + "/" + self.playbook_exec_name, mode="r" + self.directory.name + "/" + self.playbook_exec_name, mode="r" ) as generic_playbook: data_gp = self.yaml_exec.load(generic_playbook) data_gp[0]["vars_files"] = self.vars_files data_gp[0]["tasks"][0]["block"] = self.tasks data_gp[0]["tasks"][0]["always"] = self.always_tasks with open( - self.directory.name + "/" + self.playbook_exec_name, mode="w" + self.directory.name + "/" + self.playbook_exec_name, mode="w" ) as generic_playbook: self.yaml_exec.dump(data_gp, generic_playbook) @@ -156,7 +155,6 @@ def load_vars(): if k == "base_url": data[playbook_name + "_vars"][k] = v - if playbook_name == OPTIONAL: for k, v in playbook_vars.items(): if k == MOSH: @@ -173,12 +171,12 @@ def load_vars(): try: shutil.copy(self.playbooks_dir + playbook_var_yml, self.directory.name) with open( - self.directory.name + playbook_var_yml, mode="r" + self.directory.name + playbook_var_yml, mode="r" ) as variables: data = self.yaml_exec.load(variables) load_vars() with open( - self.directory.name + playbook_var_yml, mode="w" + self.directory.name + playbook_var_yml, mode="w" ) as variables: self.yaml_exec.dump(data, variables) self.add_to_playbook_lists(playbook_name_local, playbook_name)