Skip to content

Commit

Permalink
CASMCMS-8723: Update CFS cli for v3/paging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Bak authored and rustydb committed Sep 6, 2023
1 parent 0d5f32c commit 7cab083
Show file tree
Hide file tree
Showing 3 changed files with 19,574 additions and 8,247 deletions.
45 changes: 29 additions & 16 deletions cray/modules/cfs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,31 @@
from cray.generator import generate

CURRENT_VERSION = 'v2'
PRESERVE_VERSIONS = True
SWAGGER_OPTS = {
'vocabulary': {
'deleteall': 'deleteall'
}
}

cli = generate(__file__, condense=False, swagger_opts=SWAGGER_OPTS)
cli.commands = cli.commands[CURRENT_VERSION].commands

if PRESERVE_VERSIONS:
cli.commands.update(cli.commands[CURRENT_VERSION].commands)
else:
cli.commands = cli.commands[CURRENT_VERSION].commands


def setup(cfs_cli):
""" Sets up all cfs overrides """
setup_configurations_update(cfs_cli)
setup_sessions_create(cfs_cli)
setup_components_update(cfs_cli)
setup_configurations_update(cfs_cli, "v2")
setup_sessions_create(cfs_cli, "v2")
remove_sessions_update(cfs_cli, "v2")
setup_components_update(cfs_cli, "v2")
setup_configurations_update(cfs_cli, "v3")
setup_sessions_create(cfs_cli, "v3")
remove_sessions_update(cfs_cli, "v3")
setup_components_update(cfs_cli, "v3")


# CONFIGURATIONS #
Expand All @@ -85,18 +95,17 @@ def _decorator(configuration_id, file, update_branches, **kwargs):
return _decorator


def setup_configurations_update(cfs_cli):
def setup_configurations_update(cfs_cli, version):
""" Adds the --file and --update-branches parameters for configuration updates """
tmp_swagger_opts = {
'vocabulary': {
'patch': 'patch'
}
}
tmp_cli = generate(__file__, condense=False, swagger_opts=tmp_swagger_opts)
tmp_cli.commands = tmp_cli.commands[CURRENT_VERSION].commands

update_command = tmp_cli.commands['configurations'].commands['update']
patch_command = tmp_cli.commands['configurations'].commands['patch']
update_command = tmp_cli.commands[version].commands['configurations'].commands['update']
patch_command = tmp_cli.commands[version].commands['configurations'].commands['patch']

option(
'--file', callback=_opt_callback, type=str, metavar='TEXT',
Expand All @@ -117,14 +126,18 @@ def setup_configurations_update(cfs_cli):
patch_command.callback
)

cfs_cli.commands['configurations'].commands['update'] = update_command
cfs_cli.commands[version].commands['configurations'].commands['update'] = update_command


# SESSIONS #

# Update session should only be in the api as it is not user friendly and
# is only used by CFS to update session status.
del cli.commands['sessions'].commands['update']
def remove_sessions_update(cfs_cli, version):
"""
Update session should only be in the api as it is not user friendly and
is only used by CFS to update session status.
"""
del cfs_cli.commands[version].commands['sessions'].commands['update']



def _target_groups_callback(cb):
Expand Down Expand Up @@ -201,9 +214,9 @@ def _decorator(
IMAGE_MAP_PAYLOAD = 'target-image-map'


def setup_sessions_create(cfs_cli):
def setup_sessions_create(cfs_cli, version):
""" Adds the --tags and --target-group parameters for session creates """
command = cfs_cli.commands['sessions'].commands['create']
command = cfs_cli.commands[version].commands['sessions'].commands['create']

# Create a new option which can handle multiple groups with individual names
# and member lists. `option` acts as a decorator here.
Expand Down Expand Up @@ -274,9 +287,9 @@ def _decorator(component_id, state, tags, **kwargs):
return _decorator


def setup_components_update(cfs_cli):
def setup_components_update(cfs_cli, version):
""" Adds the --state and --tags parameters for component updates """
command = cfs_cli.commands['components'].commands['update']
command = cfs_cli.commands[version].commands['components'].commands['update']
option(
'--state',
callback=_opt_callback,
Expand Down
Loading

0 comments on commit 7cab083

Please sign in to comment.