Beispiel #1
0
def _execute_api(service,
                 resource,
                 verb,
                 params={},
                 api_version='v1',
                 output='yaml',
                 parser=None):
    config = get_config()
    _check_api_permissions(service, resource, verb)
    client = _get_client(service, api_version)
    response = _call_api(client, resource, verb, params, config=config)

    if verb == 'list' and parser:
        results = []
        try:
            for result in response.get('results', []):
                results.append(parser.parse_data(result))
        except Exception:
            raise Exception(
                f'{service}.{resource} template format is invalid.')

        response['results'] = results

    if verb in ['list', 'stat']:
        options = {'root_key': 'results'}

        if 'total_count' in response:
            options['total_count'] = response['total_count']

        print_data(response, output, **options)
    else:
        print_data(response, output)
Beispiel #2
0
def apply(file_path, output, env, var, var_file, silent):
    store.set_env()

    task_manager = TaskManager(silent)
    task_manager.load(file_path)
    store.apply_input(env, var, var_file)
    task_manager.run()

    if not output == 'none':
        print_data(store.get_output(), output)
Beispiel #3
0
def _print_api_resources(resources):
    data = []
    for service, service_value in resources.items():
        for resource, resource_value in service_value.items():
            data.append((service, resource, ', '.join(resource_value['alias']),
                         ', '.join(resource_value['verb'])))

    print_data(data,
               'table',
               headers=['Service', 'Resource', 'Short Names', 'Verb'])
Beispiel #4
0
def show(resource):
    """Display resource template"""
    service, resource = _get_service_and_resource(resource)
    template = get_template(service, resource)

    if template:
        template['parser'] = template.get('parser', DEFAULT_PARSER)
        print_data(template, 'yaml')
    else:
        click.echo(f'{service}.{resource} template is undefined.')
        click.echo()
Beispiel #5
0
    def _finish_tasks(self):
        task_output = store.get_output()

        if not self.silent:
            click.echo(
                f'FINISHED [ ok={task_output["success"]}, skipped={task_output["skip"]} ] '
                f'{"*" * 1000}'[:self.terminal_width])

        if not self.output == 'none':
            print_data(task_output, self.output)

        click.echo('')
Beispiel #6
0
def version():
    """Print the client version information"""
    _version = _get_version_from_pkg() or _get_version_from_file() or 'unknown'
    print_data({'version': _version}, 'yaml')
Beispiel #7
0
    def execute(self):
        self._validate()

        output = self.spec.get('output', 'json')
        print_data(self.spec['data'], output)
        click.echo('')
Beispiel #8
0
def show(output):
    """Display API endpoints"""
    endpoints = list_endpoints()
    print_data(endpoints, output, headers=['Service', 'Endpoint'])
Beispiel #9
0
def show(output):
    """Display a spaceconfig"""
    data = get_config()
    print_data(data, output)