Skip to content

Commit

Permalink
CASMCMS-8650: Update BOS API spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mharding-hpe committed Sep 17, 2024
1 parent 5091ad5 commit c036cb3
Show file tree
Hide file tree
Showing 4 changed files with 14,284 additions and 15,915 deletions.
31 changes: 24 additions & 7 deletions cray/modules/bos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@

cli = generate(__file__, swagger_opts=SWAGGER_OPTS)

# Update v2 sessions should only be in the API -- not intended for CLI use
del cli.commands['v2'].commands['sessions'].commands['update']

# Remove all v1 endpoints
del cli.commands['v1']

# Place the v2 commands at the 'cray bos' level of the cli
CURRENT_VERSION = 'v2'
PRESERVE_VERSIONS = True
Expand All @@ -50,6 +44,18 @@
cli.commands = cli.commands[CURRENT_VERSION].commands


def strip_tenant_header_params(cmd=cli):
"""
Remove tenant header parameters from CLI commands, because those are
handled differently by the CLI
"""
if hasattr(cmd, 'params'):
cmd.params = [ p for p in cmd.params if p.payload_name != 'Cray-Tenant-Name' ]
if hasattr(cmd, 'commands'):
for c in cmd.commands.values():
strip_tenant_header_params(c)


# Add --file parameter for specifying session template data
def create_templates_shim(func):
""" Callback function to custom create our own payload """
Expand Down Expand Up @@ -93,7 +99,7 @@ def updatemany_data_handler(args):
def create_patch_shim(func):
""" Callback function to custom create our own payload """

def _decorator(filter_ids, filter_session, patch, enabled, **kwargs):
def _decorator(filter_ids, filter_session, patch, enabled, retry_policy, **kwargs):
filter_ids = filter_ids["value"]
filter_session = filter_session["value"]
if not (filter_ids or filter_session):
Expand All @@ -115,6 +121,8 @@ def _decorator(filter_ids, filter_session, patch, enabled, **kwargs):
payload["patch"] = {}
if enabled["value"] is not None:
payload["patch"]["enabled"] = enabled["value"]
if retry_policy["value"] is not None:
payload["patch"]["retry_policy"] = retry_policy["value"]
# Hack to tell the CLI we are passing our own payload; don't generate
kwargs[FROM_FILE_TAG] = {"value": payload, "name": FROM_FILE_TAG}
return func(data_handler=updatemany_data_handler, **kwargs)
Expand Down Expand Up @@ -166,6 +174,14 @@ def setup_components_patch():
metavar='BOOLEAN',
help="Shortcut for --patch '{\"enabled\":True/False}'"
)(new_command)
option(
'--retry-policy',
callback=_opt_callback,
type=int,
default=None,
metavar='INT',
help="Shortcut for --patch '{\"retry_policy\":<int>}'"
)(new_command)
new_command.params += default_params
new_command.callback = create_patch_shim(new_command.callback)

Expand All @@ -181,6 +197,7 @@ def setup_v2_template_create():
cli.commands['v2'].commands['sessiontemplates'].commands['create'] = \
temp_cli.commands['v2'].commands['sessiontemplates'].commands['create']

strip_tenant_header_params()

setup_v2_template_create()

Expand Down
Loading

0 comments on commit c036cb3

Please sign in to comment.