Skip to content

Commit

Permalink
FIxed the ibm tagging (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma authored Nov 5, 2024
1 parent 178f6fb commit 6b17598
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion cloud_governance/main/environment_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', '')
Expand Down
19 changes: 11 additions & 8 deletions jenkins/clouds/ibm/hourly/tagging/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

def run_cmd(cmd):
os.system(cmd)
os.system('echo "\n\n\n"')


def generate_env_vars(**kwargs):
Expand All @@ -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)


Expand All @@ -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)

0 comments on commit 6b17598

Please sign in to comment.