def run_and_print(self, args, **kwargs): all_pack_instances = self.app.client.managers['Pack'].get_all(**kwargs) super(PackRemoveCommand, self).run_and_print(args, **kwargs) packs = args.packs if len(packs) == 1: pack_instance = self.app.client.managers['Pack'].get_by_ref_or_id(packs[0], **kwargs) if pack_instance: raise OperationFailureException('Pack %s has not been removed properly' % packs[0]) removed_pack_instance = next((pack for pack in all_pack_instances if pack.name == packs[0]), None) self.print_output(removed_pack_instance, table.PropertyValueTable, attributes=args.attr, json=args.json, yaml=args.yaml, attribute_display_order=self.attribute_display_order) else: remaining_pack_instances = self.app.client.managers['Pack'].get_all(**kwargs) pack_instances = [] for pack in all_pack_instances: if pack.name in packs or pack.ref in packs: pack_instances.append(pack) if pack in remaining_pack_instances: raise OperationFailureException('Pack %s has not been removed properly' % pack.name) self.print_output(pack_instances, table.MultiColumnTable, attributes=args.attr, widths=args.width, json=args.json, yaml=args.yaml)
def run(self, args, **kwargs): schema = self.app.client.managers['ConfigSchema'].get_by_ref_or_id(args.name, **kwargs) if not schema: raise resource.ResourceNotFoundError("%s doesn't have config schema defined" % self.resource.get_display_name()) config = interactive.InteractiveForm(schema.attributes).initiate_dialog() message = '---\nDo you want to preview the config in an editor before saving?' description = 'Secrets would be shown in plain text.' preview_dialog = interactive.Question(message, {'default': 'y', 'description': description}) if preview_dialog.read() == 'y': contents = yaml.safe_dump(config, indent=4, default_flow_style=False) modified = editor.edit(contents=contents) config = yaml.safe_load(modified) message = '---\nDo you want me to save it?' save_dialog = interactive.Question(message, {'default': 'y'}) if save_dialog.read() == 'n': raise OperationFailureException('Interrupted') result = self.app.client.managers['Config'].update(Config(pack=args.name, values=config)) return result
def run(self, args, **kwargs): schema = self.app.client.managers["ConfigSchema"].get_by_ref_or_id( args.name, **kwargs ) if not schema: msg = "%s \"%s\" doesn't exist or doesn't have a config schema defined." raise resource.ResourceNotFoundError( msg % (self.resource.get_display_name(), args.name) ) config = interactive.InteractiveForm(schema.attributes).initiate_dialog() message = "---\nDo you want to preview the config in an editor before saving?" description = "Secrets will be shown in plain text." preview_dialog = interactive.Question( message, {"default": "y", "description": description} ) if preview_dialog.read() == "y": try: contents = yaml.safe_dump(config, indent=4, default_flow_style=False) modified = editor.edit(contents=contents) config = yaml.safe_load(modified) except editor.EditorError as e: print(six.text_type(e)) message = "---\nDo you want me to save it?" save_dialog = interactive.Question(message, {"default": "y"}) if save_dialog.read() == "n": raise OperationFailureException("Interrupted") config_item = Config(pack=args.name, values=config) result = self.app.client.managers["Config"].update(config_item, **kwargs) return result
def run_and_print(self, args, **kwargs): try: instance = self.run(args, **kwargs) if not instance: raise Exception("Configuration failed") self.print_output(instance, table.PropertyValueTable, attributes=['all'], json=args.json, yaml=args.yaml) except (KeyboardInterrupt, SystemExit): raise OperationFailureException('Interrupted') except Exception as e: if self.app.client.debug: raise message = e.message or str(e) print('ERROR: %s' % (message)) raise OperationFailureException(message)
def run_and_print(self, args, **kwargs): try: self.run(args, **kwargs) except ResourceNotFoundError: resource_id = getattr(args, self.pk_argument_name, None) self.print_not_found(resource_id) raise OperationFailureException('Resource %s not found.' % resource_id)
def run_and_print(self, args, **kwargs): instance = self.run(args, **kwargs) try: self.print_output(instance, table.PropertyValueTable, attributes=['all'], json=args.json, yaml=args.yaml) except Exception as e: print('ERROR: %s' % e.message) raise OperationFailureException(e.message)
def run_and_print(self, args, **kwargs): trace = None try: trace = self.run(args, **kwargs) except resource.ResourceNotFoundError: self.print_not_found(args.id) raise OperationFailureException('Trace %s not found.' % (args.id)) return self.print_trace_details(trace=trace, args=args)
def run_and_print(self, args, **kwargs): try: execution = self.run(args, **kwargs) except resource.ResourceNotFoundError: self.print_not_found(args.id) raise OperationFailureException('Execution %s not found.' % (args.id)) return self._print_execution_details(execution=execution, args=args, **kwargs)
def run_and_print(self, args, **kwargs): resource_id = getattr(args, self.pk_argument_name, None) try: self.run(args, **kwargs) print('Resource with id "%s" has been successfully deleted.' % (resource_id)) except ResourceNotFoundError: self.print_not_found(resource_id) raise OperationFailureException('Resource %s not found.' % resource_id)
def _transform_response(self, response): if response.lower() in POSITIVE_BOOLEAN: return True if response.lower() in NEGATIVE_BOOLEAN: return False # Hopefully, it will never happen raise OperationFailureException('Response neither positive no negative. ' 'Value have not been properly validated.')
def run_and_print(self, args, **kwargs): try: instance = self.run(args, **kwargs) self.print_output(instance, table.PropertyValueTable, attributes=args.attr, json=args.json, yaml=args.yaml, attribute_display_order=self.attribute_display_order) except ResourceNotFoundError: resource_id = getattr(args, self.pk_argument_name, None) self.print_not_found(resource_id) raise OperationFailureException('Resource %s not found.' % resource_id)
def run_and_print(self, args, **kwargs): try: instance = self.run(args, **kwargs) if not instance: raise Exception('Server did not create instance.') self.print_output(instance, table.PropertyValueTable, attributes=['all'], json=args.json, yaml=args.yaml) except Exception as e: message = e.message or str(e) print('ERROR: %s' % (message)) raise OperationFailureException(message)
def run_and_print(self, args, **kwargs): try: execution = self.run(args, **kwargs) if not args.json: # Include elapsed time for running executions execution = format_execution_status(execution) except resource.ResourceNotFoundError: self.print_not_found(args.id) raise OperationFailureException('Execution %s not found.' % (args.id)) return self._print_execution_details(execution=execution, args=args, **kwargs)
def run_and_print(self, args, **kwargs): trace = None try: trace = self.run(args, **kwargs) except resource.ResourceNotFoundError: self.print_not_found(args.id) raise OperationFailureException('Trace %s not found.' % (args.id)) # First filter for causation chains trace = self._filter_trace_components(trace=trace, args=args) # next filter for display purposes trace = self._apply_display_filters(trace=trace, args=args) return self.print_trace_details(trace=trace, args=args)
def run_and_print(self, args, **kwargs): try: instance = self.run(args, **kwargs) if not instance: raise resource.ResourceNotFoundError("No matching items found") self.print_output(instance, table.PropertyValueTable, attributes=['all'], json=args.json, yaml=args.yaml) except resource.ResourceNotFoundError: print("No matching items found") except Exception as e: message = e.message or str(e) print('ERROR: %s' % (message)) raise OperationFailureException(message)
def run_and_print(self, args, **kwargs): instance = self.run(args, **kwargs) try: self.print_output( instance, table.PropertyValueTable, attributes=["all"], json=args.json, yaml=args.yaml, ) except Exception as e: print("ERROR: %s" % (six.text_type(e))) raise OperationFailureException(six.text_type(e))
def run_and_print(self, args, **kwargs): try: instance = self.run(args, **kwargs) if not instance: raise Exception("Server did not create instance.") self.print_output( instance, table.PropertyValueTable, attributes=["all"], json=args.json, yaml=args.yaml, ) except Exception as e: message = six.text_type(e) print("ERROR: %s" % (message)) raise OperationFailureException(message)
def run_and_print(self, args, **kwargs): if args.tasks: self.run_and_print_child_task_list(args, **kwargs) return try: instance = self.run(args, **kwargs) formatter = table.PropertyValueTable if args.detail else execution.ExecutionResult if args.detail: options = {'attributes': args.attr} elif args.key: options = { 'attributes': ['result.%s' % args.key], 'key': args.key } else: options = {'attributes': ['status', 'result']} options['json'] = args.json options[ 'attribute_transform_functions'] = self.attribute_transform_functions self.print_output(instance, formatter, **options) except resource.ResourceNotFoundError: self.print_not_found(args.id) raise OperationFailureException('Execution %s not found.' % args.id)