From c1a878049dbfb5fcb596a0da273c2257edf189f2 Mon Sep 17 00:00:00 2001 From: Thirumalesh Aaraveti Date: Tue, 5 Nov 2024 11:30:49 +0530 Subject: [PATCH] FIxed the ibm tagging --- .../main/environment_variables.py | 5 ++++- jenkins/clouds/ibm/hourly/tagging/tagging.py | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cloud_governance/main/environment_variables.py b/cloud_governance/main/environment_variables.py index e1188dbf..29187570 100644 --- a/cloud_governance/main/environment_variables.py +++ b/cloud_governance/main/environment_variables.py @@ -28,6 +28,7 @@ def load_from_env(self): with open(file_path) as f: for line in f.readlines(): key, found, value = line.strip().partition("=") + setattr(self, key, value) if not found: logger.error(f"ERROR: invalid line in {env}: {line.strip()}") continue @@ -167,7 +168,9 @@ def __init__(self): '') self._environment_variables_dict['IBM_CLOUD_API_KEY'] = EnvironmentVariables.get_env('IBM_CLOUD_API_KEY', '') - if self._environment_variables_dict['USAGE_REPORTS_APIKEY'] or hasattr(self, "IBM_CLOUD_API_KEY"): + if (self._environment_variables_dict['USAGE_REPORTS_APIKEY'] or + self._environment_variables_dict['IBM_CLOUD_API_KEY'] or + hasattr(self, "IBM_CLOUD_API_KEY")): self._environment_variables_dict['PUBLIC_CLOUD_NAME'] = 'IBM' self._environment_variables_dict['month'] = EnvironmentVariables.get_env('month', '') self._environment_variables_dict['year'] = EnvironmentVariables.get_env('year', '') diff --git a/jenkins/clouds/ibm/hourly/tagging/tagging.py b/jenkins/clouds/ibm/hourly/tagging/tagging.py index 855ae61e..69ed6adc 100644 --- a/jenkins/clouds/ibm/hourly/tagging/tagging.py +++ b/jenkins/clouds/ibm/hourly/tagging/tagging.py @@ -15,6 +15,7 @@ def run_cmd(cmd): os.system(cmd) + os.system('echo "\n\n\n"') def generate_env_vars(**kwargs): @@ -27,7 +28,7 @@ def generate_env_vars(**kwargs): def generate_volume_mounts(volume_mounts): items = [] for mount in volume_mounts: - items.append(f'-v {mount}="{mount}"') + items.append(f'-v {mount}:"{mount}"') return ' '.join(items) @@ -37,31 +38,33 @@ def get_podman_run_cmd(volume_mounts: list = None, **kwargs): volume_mounts = [] if "/etc/localtime" not in volume_mounts: volume_mounts.append("/etc/localtime") - cmd = f"podman run --rm {container_name} {generate_env_vars(**kwargs)} {generate_volume_mounts(volume_mounts)} {QUAY_CLOUD_GOVERNANCE_REPOSITORY}" + cmd = f"podman run --rm {container_name} {generate_env_vars(**kwargs)} {generate_volume_mounts(volume_mounts)} \ + {QUAY_CLOUD_GOVERNANCE_REPOSITORY}" return cmd -run_cmd('Run IBM tagging on baremetal, vm') +run_cmd("echo Run IBM tagging on baremetal, vm") -run_cmd("Run IBM tag baremetal") +run_cmd("echo Run IBM tag baremetal") volume_mounts_targets = [GOOGLE_APPLICATION_CREDENTIALS] input_env_keys = {'account': account, 'LDAP_HOST_NAME': LDAP_HOST_NAME, 'GOOGLE_APPLICATION_CREDENTIALS': GOOGLE_APPLICATION_CREDENTIALS, 'SPREADSHEET_ID': SPREADSHEET_ID, 'IBM_API_USERNAME': IBM_API_USERNAME, 'IBM_API_KEY': IBM_API_KEY, 'tag_operation': "update", - 'log_level': "INFO", 'policy': 'tag_baremetal'} + 'log_level': "INFO", 'policy': 'tag_baremetal', "PUBLIC_CLOUD_NAME": "IBM"} baremetal_cmd = get_podman_run_cmd(volume_mounts=volume_mounts_targets, **input_env_keys) run_cmd(baremetal_cmd) -run_cmd("Run IBM tag Virtual Machines") +run_cmd("echo Run IBM tag Virtual Machines") input_env_keys['policy'] = 'tag_vm' virtual_machine_cmd = get_podman_run_cmd(volume_mounts=volume_mounts_targets, **input_env_keys) run_cmd(virtual_machine_cmd) # Run tag resources -run_cmd("Run tag resources command") +run_cmd("echo Run tag resources command") podman_run_cmd = get_podman_run_cmd(policy="tag_resources", account=account, IBM_CLOUD_API_KEY=IBM_CLOUD_API_KEY, - IBM_CUSTOM_TAGS_LIST=IBM_CUSTOM_TAGS_LIST) + IBM_CUSTOM_TAGS_LIST=IBM_CUSTOM_TAGS_LIST, + PUBLIC_CLOUD_NAME="IBM") run_cmd(podman_run_cmd)