How to use st2client - 10 common examples

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 / st2tests / integration / orquesta / base.py View on Github external
def setUpClass(cls):
        cls.st2client = st2.Client(base_url='http://127.0.0.1')
github StackStorm / st2 / st2tests / integration / orquesta / test_wiring_functions_st2kv.py View on Github external
def del_kvp(cls, name, scope='system'):
        kvp = models.KeyValuePair(id=name, name=name, scope=scope)

        cls.st2client.keys.delete(kvp)
github StackStorm / st2 / st2tests / integration / mistral / test_st2kv.py View on Github external
def set_kvp(cls, name, value, scope='system', secret=False):
        kvp = models.KeyValuePair(id=name, name=name, value=value, scope=scope, secret=secret)

        cls.st2client.keys.update(kvp)
github StackStorm / st2 / st2tests / integration / mistral / test_st2kv.py View on Github external
def del_kvp(cls, name, scope='system'):
        kvp = models.KeyValuePair(id=name, name=name, scope=scope)

        cls.st2client.keys.delete(kvp)
github StackStorm / st2 / st2tests / integration / orquesta / base.py View on Github external
def _execute_workflow(self, action, parameters=None, execute_async=True,
                          expected_status=None, expected_result=None):

        ex = models.LiveAction(action=action, parameters=(parameters or {}))
        ex = self.st2client.executions.create(ex)
        self.assertIsNotNone(ex.id)
        self.assertEqual(ex.action['ref'], action)
        self.assertIn(ex.status, LIVEACTION_LAUNCHED_STATUSES)

        if execute_async:
            return ex

        if expected_status is None:
            expected_status = action_constants.LIVEACTION_STATUS_SUCCEEDED

        self.assertIn(expected_status, action_constants.LIVEACTION_STATUSES)

        ex = self._wait_for_completion(ex)

        self.assertEqual(ex.status, expected_status)
github StackStorm / st2 / st2tests / integration / orquesta / base.py View on Github external
def _execute_workflow(
        self,
        action,
        parameters=None,
        execute_async=True,
        expected_status=None,
        expected_result=None,
    ):

        ex = models.LiveAction(action=action, parameters=(parameters or {}))
        ex = self.st2client.executions.create(ex)
        self.assertIsNotNone(ex.id)
        self.assertEqual(ex.action['ref'], action)
        self.assertIn(ex.status, LIVEACTION_LAUNCHED_STATUSES)

        if execute_async:
            return ex

        if expected_status is None:
            expected_status = action_constants.LIVEACTION_STATUS_SUCCEEDED

        self.assertIn(expected_status, action_constants.LIVEACTION_STATUSES)

        ex = self._wait_for_completion(ex)

        self.assertEqual(ex.status, expected_status)
github StackStorm / st2 / st2tests / integration / mistral / base.py View on Github external
def _execute_workflow(self, action, parameters=None):
        ex = models.LiveAction(action=action, parameters=(parameters or {}))
        ex = self.st2client.executions.create(ex)
        self.assertIsNotNone(ex.id)
        self.assertEqual(ex.action['ref'], action)
        self.assertIn(ex.status, LIVEACTION_LAUNCHED_STATUSES)

        return ex
github StackStorm / st2 / st2client / st2client / commands / pack.py View on Github external
if status == LIVEACTION_STATUS_SCHEDULED:
                        indicator.add_stage(status, name)
                    if status == LIVEACTION_STATUS_RUNNING:
                        indicator.update_stage(status, name)
                    if status in LIVEACTION_COMPLETED_STATES:
                        indicator.finish_stage(status, name)

        if execution and execution.status == LIVEACTION_STATUS_FAILED:
            args.depth = 1
            self._print_execution_details(execution=execution, args=args, **kwargs)
            sys.exit(1)

        return self.app.client.managers['Execution'].get_by_id(parent_id, **kwargs)


class PackListCommand(resource.ResourceListCommand):
    display_attributes = ['ref', 'name', 'description', 'version', 'author']
    attribute_display_order = ['ref', 'name', 'description', 'version', 'author']


class PackGetCommand(resource.ResourceGetCommand):
    pk_argument_name = 'ref'
    display_attributes = ['name', 'version', 'author', 'email', 'keywords', 'description']
    attribute_display_order = ['name', 'version', 'author', 'email', 'keywords', 'description']
    help_string = 'Get information about an installed pack.'


class PackShowCommand(PackResourceCommand):
    def __init__(self, resource, *args, **kwargs):
        help_string = (
            'Get information about an available %s from the index.'
            % resource.get_display_name().lower()
github StackStorm / st2 / st2client / st2client / commands / pack.py View on Github external
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))
github NL-ix / bird-stack / st2 / packs / bird / actions / update_drop_list_info.py View on Github external
r = requests.get(url)
            except requests.exceptions.RequestException as e:
                return (False, str(e))

            request_out = r.text

            # TODO Implement a generic parsing algorithm
            drop_list = [p.split(";")[0].strip()
                         for p in request_out.split("\n")[4:-1]]
            ret += drop_list

        api_base_url = self.config.get('st2_base_url')
        st_client = Client(base_url=api_base_url)
        drop_list_key = "drop_list_prefixes_{}".format(ip_version)
        drop_list_value = json.dumps(list(set(ret)))
        drop_list_pair = KeyValuePair(name=drop_list_key,
                                      value=drop_list_value)
        try:
            st_client.keys.update(drop_list_pair)
        except Exception as e:
            return (False, str(e))

        return (True, drop_list_key)