Skip to content

Commit

Permalink
Added workaround for setting hostname in hsm
Browse files Browse the repository at this point in the history
Changed redfishEndpoints update and redfishEndpoints create to not use
the hostname if it starts with http: or https:
  • Loading branch information
shunr-hpe committed Apr 18, 2024
1 parent b755ed4 commit 86936cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.bash*
.config
.python-version
.idea
dist
build
parts
Expand Down
35 changes: 35 additions & 0 deletions cray/modules/hsm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def setup(hsm_cli):
""" Sets up all HSM overrides """
setup_groups_partitions_create(hsm_cli, 'groups')
setup_groups_partitions_create(hsm_cli, 'partitions')
setup_redfish_endpoints_update(hsm_cli)
setup_redfish_endpoints_create(hsm_cli)


# Groups and Partitions #
Expand Down Expand Up @@ -93,6 +95,39 @@ def setup_groups_partitions_create(hsm_cli, command):
hsm_cli.commands[command].commands['create'] = create_command


# redfishEndpoints update #
def setup_redfish_endpoints_update(hsm_cli):
""" Added a fix for the hostname being set to the cray global hostname """
update_command = hsm_cli.commands["inventory"].commands["redfishEndpoints"].commands['update']
update_command.callback = create_re_create_and_update_shim(update_command.callback)


# redfishEndpoints create #
def setup_redfish_endpoints_create(hsm_cli):
""" Added a fix for the hostname being set to the cray global hostname """
create_command = hsm_cli.commands["inventory"].commands["redfishEndpoints"].commands['create']
create_command.callback = create_re_create_and_update_shim(create_command.callback)


def create_re_create_and_update_shim(func):
""" This causes the call to ignore any hostname value that starts with http: or https:
The top level cray command has a --hostname option which is stored in the config file
and its value gets passed through here when the user doesn't specify the hsm flavor
of the --hostname option """

def _decorator(**kwargs):
hostname = kwargs.get("hostname")
if hostname:
value = hostname.get("value")
if value and (value.lower().startswith("https:") or value.lower().startswith("http:")):
hostname["value"] = None
kwargs["hostname"] = hostname

return func(**kwargs)

return _decorator


# Keeping for future API versions
# if HSM_API_VERSION == 'v1':
# cli = generate(__file__, filename='swagger3_v1.json', swagger_opts=SWAGGER_OPTS)
Expand Down

0 comments on commit 86936cd

Please sign in to comment.