How to use the st2client.exceptions.operations.OperationFailureException function in st2client

To help you get started, we’ve selected a few st2client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StackStorm / st2 / st2client / st2client / commands / pack.py View on Github external
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
github StackStorm / st2 / st2client / st2client / commands / auth.py View on Github external
def run_and_print(self, args, **kwargs):
        try:
            instance = self.run(args, **kwargs)
            if not instance:
                raise Exception('Server did not create instance.')
        except Exception as e:
            message = e.message or str(e)
            print('ERROR: %s' % (message))
            raise OperationFailureException(message)
        if args.only_key:
            print(instance.key)
        else:
            self.print_output(instance, table.PropertyValueTable,
                              attributes=['all'], json=args.json, yaml=args.yaml)
github StackStorm / st2 / st2client / st2client / utils / interactive.py View on Github external
from prompt_toolkit import token
from prompt_toolkit import validation

from st2client.exceptions.operations import OperationFailureException
from six.moves import range


POSITIVE_BOOLEAN = {'1', 'y', 'yes', 'true'}
NEGATIVE_BOOLEAN = {'0', 'n', 'no', 'nope', 'nah', 'false'}


class ReaderNotImplemented(OperationFailureException):
    pass


class DialogInterrupted(OperationFailureException):
    pass


class MuxValidator(validation.Validator):
    def __init__(self, validators, spec):
        super(MuxValidator, self).__init__()

        self.validators = validators
        self.spec = spec

    def validate(self, document):
        input = document.text

        for validator in self.validators:
            validator(input, self.spec)
github StackStorm / st2 / st2client / st2client / commands / resource.py View on Github external
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)
github StackStorm / st2 / st2client / st2client / commands / pack.py View on Github external
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 = six.text_type(e)
            print('ERROR: %s' % (message))
            raise OperationFailureException(message)
github StackStorm / st2 / st2client / st2client / utils / interactive.py View on Github external
import six
import jsonschema
from jsonschema import Draft3Validator
from prompt_toolkit import prompt
from prompt_toolkit import token
from prompt_toolkit import validation

from st2client.exceptions.operations import OperationFailureException
from six.moves import range


POSITIVE_BOOLEAN = {'1', 'y', 'yes', 'true'}
NEGATIVE_BOOLEAN = {'0', 'n', 'no', 'nope', 'nah', 'false'}


class ReaderNotImplemented(OperationFailureException):
    pass


class DialogInterrupted(OperationFailureException):
    pass


class MuxValidator(validation.Validator):
    def __init__(self, validators, spec):
        super(MuxValidator, self).__init__()

        self.validators = validators
        self.spec = spec

    def validate(self, document):
        input = document.text
github StackStorm / st2 / st2client / st2client / commands / resource.py View on Github external
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))
github StackStorm / st2 / st2client / st2client / commands / auth.py View on Github external
def run_and_print(self, args, **kwargs):
        try:
            instance = self.run(args, **kwargs)
            if not instance:
                raise Exception('Server did not create instance.')
        except Exception as e:
            message = six.text_type(e)
            print('ERROR: %s' % (message))
            raise OperationFailureException(message)
        if args.only_key:
            print(instance.key)
        else:
            self.print_output(
                instance,
                table.PropertyValueTable,
                attributes=['all'],
                json=args.json,
                yaml=args.yaml,
            )
github StackStorm / st2 / st2client / st2client / utils / interactive.py View on Github external
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.'
        )