Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIxed the ibm tagging #866

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)