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)
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)
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'])
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()
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('')
def version(): """Print the client version information""" _version = _get_version_from_pkg() or _get_version_from_file() or 'unknown' print_data({'version': _version}, 'yaml')
def execute(self): self._validate() output = self.spec.get('output', 'json') print_data(self.spec['data'], output) click.echo('')
def show(output): """Display API endpoints""" endpoints = list_endpoints() print_data(endpoints, output, headers=['Service', 'Endpoint'])
def show(output): """Display a spaceconfig""" data = get_config() print_data(data, output)