Skip to content

Commit

Permalink
Merge pull request #35 from whdalsrnt/master
Browse files Browse the repository at this point in the history
Add Analyze Command
  • Loading branch information
whdalsrnt authored Jun 11, 2023
2 parents a97d2e1 + 6454ec1 commit da41e84
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/spacectl/command/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,34 @@ def list(resource, parameter, json_parameter, file_path, minimal_columns, all_co
_execute_api(service, resource, 'list', params=params, api_version=api_version, output=output, parser=parser)


@cli.command()
@click.argument('resource')
@click.option('-p', '--parameter', multiple=True, help='Input Parameter (-p <key>=<value> -p ...)')
@click.option('-j', '--json-parameter', help='JSON type parameter')
@click.option('-f', '--file-parameter', 'file_path', type=click.Path(exists=True), help='YAML file only')
@click.option('-c', '--columns', help='Specific columns (-c id,name)')
@click.option('-l', '--limit', type=int, help='Number of rows')
@click.option('-v', '--api-version', default='v1', help='API Version', show_default=True)
@click.option('-o', '--output', default='table', help='Output format',
type=click.Choice(['table', 'json', 'yaml', 'csv', 'quiet']), show_default=True)
def analyze(resource, parameter, json_parameter, file_path, columns, limit, api_version, output):
"""Analyze resources"""
service, resource = _get_service_and_resource(resource)
parser = None

if columns:
columns = columns.split(',')
template = load_template(service, resource, columns)
parser = load_parser(service, resource, template)

params = _parse_parameter(file_path, json_parameter, parameter)

if limit:
params['query'] = params.get('query', {})
params['query']['page'] = {'limit': limit}

_execute_api(service, resource, 'analyze', params=params, api_version=api_version, output=output, parser=parser)

@cli.command()
@click.argument('resource')
@click.option('-p', '--parameter', multiple=True, help='Input Parameter (-p <key>=<value> -p ...)')
Expand Down
6 changes: 3 additions & 3 deletions src/spacectl/conf/global_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

# Inventory
'region': ['inventory', 'Region'],
'server': ['inventory', 'Server'],
'sv': ['inventory', 'Server'],
'cloud_service_type': ['inventory', 'CloudServiceType'],
'cloud_service': ['inventory', 'CloudService'],
'cloud_service_type': ['inventory', 'CloudServiceType'],
'cs': ['inventory', 'CloudService'],
'cloud_service_query_set': ['inventory', 'CloudServiceQuerySet'],
'cloud_service_stats': ['inventory', 'CloudServiceStats'],
'resource_group': ['inventory', 'ResourceGroup'],
'rg': ['inventory', 'ResourceGroup'],
'collector': ['inventory', 'Collector'],
Expand Down

0 comments on commit da41e84

Please sign in to comment.