+@click.option('--literal', is_flag=True,
+ help='print literally, no pretty table')
+@click.pass_context
+def k8scluster_show(ctx, name, literal):
+ """shows the details of a K8s cluster
+
+ NAME: name or ID of the K8s cluster
+ """
+ try:
+ resp = ctx.obj.k8scluster.get(name)
+ if literal:
+ print(yaml.safe_dump(resp))
+ return
+ table = PrettyTable(['key', 'attribute'])
+ for k, v in list(resp.items()):
+ table.add_row([k, wrap_text(text=json.dumps(v, indent=2),width=100)])
+ table.align = 'l'
+ print(table)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+
+###########################
+# Repo operations
+###########################
+
+@cli.command(name='repo-add')
+@click.argument('name')
+@click.argument('uri')
+@click.option('--type',
+ type=click.Choice(['helm-chart', 'juju-bundle']),
+ prompt=True,
+ help='type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles)')
+@click.option('--description',
+ default='',
+ help='human readable description')
+#@click.option('--wait',
+# is_flag=True,
+# help='do not return the control immediately, but keep it \
+# until the operation is completed, or timeout')
+@click.pass_context
+def repo_add(ctx,
+ name,
+ uri,
+ type,
+ description):
+ """adds a repo to OSM
+
+ NAME: name of the repo
+ URI: URI of the repo
+ """
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ repo = {}
+ repo['name'] = name
+ repo['url'] = uri
+ repo['type'] = type
+ repo['description'] = description
+ ctx.obj.repo.create(name, repo)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+@cli.command(name='repo-update')
+@click.argument('name')
+@click.option('--newname', help='New name for the repo')
+@click.option('--uri', help='URI of the repo')
+@click.option('--type', type=click.Choice(['helm-chart', 'juju-bundle']),
+ help='type of repo (helm-chart for Helm Charts, juju-bundle for Juju Bundles)')
+@click.option('--description', help='human readable description')
+#@click.option('--wait',
+# is_flag=True,
+# help='do not return the control immediately, but keep it \
+# until the operation is completed, or timeout')
+@click.pass_context
+def repo_update(ctx,
+ name,
+ newname,
+ uri,
+ type,
+ description):
+ """updates a repo in OSM
+
+ NAME: name of the repo
+ """
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ repo = {}
+ if newname: repo['name'] = newname
+ if uri: repo['uri'] = uri
+ if type: repo['type'] = type
+ if description: repo['description'] = description
+ ctx.obj.repo.update(name, repo)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+@cli.command(name='repo-delete')
+@click.argument('name')
+@click.option('--force', is_flag=True, help='forces the deletion from the DB (not recommended)')
+#@click.option('--wait',
+# is_flag=True,
+# help='do not return the control immediately, but keep it \
+# until the operation is completed, or timeout')
+@click.pass_context
+def repo_delete(ctx, name, force):
+ """deletes a repo
+
+ NAME: name or ID of the repo to be deleted
+ """
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.repo.delete(name, force=force)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+@cli.command(name='repo-list')
+@click.option('--filter', default=None,
+ help='restricts the list to the repos matching the filter')
+@click.option('--literal', is_flag=True,
+ help='print literally, no pretty table')
+@click.pass_context
+def repo_list(ctx, filter, literal):
+ """list all repos"""
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ resp = ctx.obj.repo.list(filter)
+ if literal:
+ print(yaml.safe_dump(resp))
+ return
+ table = PrettyTable(['Name', 'Id', 'Type', 'URI', 'Description'])
+ for repo in resp:
+ #cluster['k8s-nets'] = json.dumps(yaml.safe_load(cluster['k8s-nets']))
+ table.add_row([repo['name'], repo['_id'], repo['type'], repo['url'], trunc_text(repo.get('description',''),40)])
+ table.align = 'l'
+ print(table)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+@cli.command(name='repo-show')
+@click.argument('name')
+@click.option('--literal', is_flag=True,
+ help='print literally, no pretty table')
+@click.pass_context
+def repo_show(ctx, name, literal):
+ """shows the details of a repo
+
+ NAME: name or ID of the repo
+ """
+ try:
+ resp = ctx.obj.repo.get(name)
+ if literal:
+ print(yaml.safe_dump(resp))
+ return
+ table = PrettyTable(['key', 'attribute'])
+ for k, v in list(resp.items()):
+ table.add_row([k, json.dumps(v, indent=2)])
+ table.align = 'l'
+ print(table)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+
+####################
+# Project mgmt operations
+####################
+
+@cli.command(name='project-create', short_help='creates a new project')
+@click.argument('name')
+#@click.option('--description',
+# default='no description',
+# help='human readable description')
+@click.pass_context
+def project_create(ctx, name):
+ """Creates a new project
+
+ NAME: name of the project
+ """
+ project = {}
+ project['name'] = name
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.project.create(name, project)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+@cli.command(name='project-delete', short_help='deletes a project')
+@click.argument('name')
+#@click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
+@click.pass_context
+def project_delete(ctx, name):
+ """deletes a project
+
+ NAME: name or ID of the project to be deleted
+ """
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ ctx.obj.project.delete(name)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+
+
+@cli.command(name='project-list', short_help='list all projects')
+@click.option('--filter', default=None,
+ help='restricts the list to the projects matching the filter')
+@click.pass_context
+def project_list(ctx, filter):
+ """list all projects"""
+ try:
+ check_client_version(ctx.obj, ctx.command.name)
+ resp = ctx.obj.project.list(filter)
+ except ClientException as e:
+ print(str(e))
+ exit(1)
+ table = PrettyTable(['name', 'id'])
+ for proj in resp:
+ table.add_row([proj['name'], proj['_id']])
+ table.align = 'l'
+ print(table)
+
+
+@cli.command(name='project-show', short_help='shows the details of a project')
+@click.argument('name')
+@click.pass_context