Пример #1
0
def register_runner(runner_type, experimental):
    # For backward compatibility reasons, we also register runners under the old names
    runner_names = [runner_type['name']] + runner_type.get('aliases', [])
    for runner_name in runner_names:
        runner_type['name'] = runner_name
        runner_experimental = runner_type.get('experimental', False)

        if runner_experimental and not experimental:
            LOG.debug('Skipping experimental runner "%s"' % (runner_name))
            continue

        # Remove additional, non db-model attributes
        non_db_attributes = ['experimental', 'aliases']
        for attribute in non_db_attributes:
            if attribute in runner_type:
                del runner_type[attribute]

        try:
            runner_type_db = get_runnertype_by_name(runner_name)
            update = True
        except StackStormDBObjectNotFoundError:
            runner_type_db = None
            update = False

        # Note: We don't want to overwrite "enabled" attribute which is already in the database
        # (aka we don't want to re-enable runner which has been disabled by the user)
        if runner_type_db and runner_type_db['enabled'] != runner_type[
                'enabled']:
            runner_type['enabled'] = runner_type_db['enabled']

        # If package is not provided, assume it's the same as module name for backward
        # compatibility reasons
        if not runner_type.get('runner_package', None):
            runner_type['runner_package'] = runner_type['runner_module']

        runner_type_api = RunnerTypeAPI(**runner_type)
        runner_type_api.validate()
        runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

        if runner_type_db:
            runner_type_model.id = runner_type_db.id

        try:

            runner_type_db = RunnerType.add_or_update(runner_type_model)

            extra = {'runner_type_db': runner_type_db}
            if update:
                LOG.audit('RunnerType updated. RunnerType %s',
                          runner_type_db,
                          extra=extra)
            else:
                LOG.audit('RunnerType created. RunnerType %s',
                          runner_type_db,
                          extra=extra)
        except Exception:
            LOG.exception('Unable to register runner type %s.',
                          runner_type['name'])
            return 0
    return 1
Пример #2
0
def register_runner_types():
    LOG.debug('Start : register default RunnerTypes.')

    for runnertype in RUNNER_TYPES:
        try:
            runnertype_db = get_runnertype_by_name(runnertype['name'])
            update = True
        except StackStormDBObjectNotFoundError:
            runnertype_db = None
            update = False

        runnertype_api = RunnerTypeAPI(**runnertype)
        runnertype_api.validate()
        runner_type_model = RunnerTypeAPI.to_model(runnertype_api)

        if runnertype_db:
            runner_type_model.id = runnertype_db.id

        try:
            runnertype_db = RunnerType.add_or_update(runner_type_model)

            extra = {'runnertype_db': runnertype_db}
            if update:
                LOG.audit('RunnerType updated. RunnerType %s', runnertype_db, extra=extra)
            else:
                LOG.audit('RunnerType created. RunnerType %s', runnertype_db, extra=extra)
        except Exception:
            LOG.exception('Unable to register runner type %s.', runnertype['name'])

    LOG.debug('End : register default RunnerTypes.')
Пример #3
0
def register_runner_types():
    LOG.debug('Start : register default RunnerTypes.')

    for runnertype in RUNNER_TYPES:
        try:
            runnertype_db = get_runnertype_by_name(runnertype['name'])
            update = True
        except StackStormDBObjectNotFoundError:
            runnertype_db = None
            update = False

        runnertype_api = RunnerTypeAPI(**runnertype)
        runnertype_api.validate()
        runner_type_model = RunnerTypeAPI.to_model(runnertype_api)

        if runnertype_db:
            runner_type_model.id = runnertype_db.id

        try:
            runnertype_db = RunnerType.add_or_update(runner_type_model)

            extra = {'runnertype_db': runnertype_db}
            if update:
                LOG.audit('RunnerType updated. RunnerType %s',
                          runnertype_db,
                          extra=extra)
            else:
                LOG.audit('RunnerType created. RunnerType %s',
                          runnertype_db,
                          extra=extra)
        except Exception:
            LOG.exception('Unable to register runner type %s.',
                          runnertype['name'])

    LOG.debug('End : register default RunnerTypes.')
Пример #4
0
def register_runner_types(experimental=False):
    """
    :param experimental: True to also register experimental runners.
    :type experimental: ``bool``
    """
    LOG.debug('Start : register default RunnerTypes.')

    for runner_type in RUNNER_TYPES:
        runner_type = copy.deepcopy(runner_type)

        # For backward compatibility reasons, we also register runners under the old names
        runner_names = [runner_type['name']] + runner_type.get('aliases', [])
        for runner_name in runner_names:
            runner_type['name'] = runner_name
            runner_experimental = runner_type.get('experimental', False)

            if runner_experimental and not experimental:
                LOG.debug('Skipping experimental runner "%s"' % (runner_name))
                continue

            # Remove additional, non db-model attributes
            non_db_attributes = ['experimental', 'aliases']
            for attribute in non_db_attributes:
                if attribute in runner_type:
                    del runner_type[attribute]

            try:
                runner_type_db = get_runnertype_by_name(runner_name)
                update = True
            except StackStormDBObjectNotFoundError:
                runner_type_db = None
                update = False

            runner_type_api = RunnerTypeAPI(**runner_type)
            runner_type_api.validate()
            runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

            if runner_type_db:
                runner_type_model.id = runner_type_db.id

            try:
                runner_type_db = RunnerType.add_or_update(runner_type_model)

                extra = {'runner_type_db': runner_type_db}
                if update:
                    LOG.audit('RunnerType updated. RunnerType %s',
                              runner_type_db,
                              extra=extra)
                else:
                    LOG.audit('RunnerType created. RunnerType %s',
                              runner_type_db,
                              extra=extra)
            except Exception:
                LOG.exception('Unable to register runner type %s.',
                              runner_type['name'])

    LOG.debug('End : register default RunnerTypes.')
Пример #5
0
def register_runner_types(experimental=False):
    """
    :param experimental: True to also register experimental runners.
    :type experimental: ``bool``
    """
    LOG.debug('Start : register default RunnerTypes.')

    for runner_type in RUNNER_TYPES:
        runner_type = copy.deepcopy(runner_type)

        # For backward compatibility reasons, we also register runners under the old names
        runner_names = [runner_type['name']] + runner_type.get('aliases', [])
        for runner_name in runner_names:
            runner_type['name'] = runner_name
            runner_experimental = runner_type.get('experimental', False)

            if runner_experimental and not experimental:
                LOG.debug('Skipping experimental runner "%s"' % (runner_name))
                continue

            # Remove additional, non db-model attributes
            non_db_attributes = ['experimental', 'aliases']
            for attribute in non_db_attributes:
                if attribute in runner_type:
                    del runner_type[attribute]

            try:
                runner_type_db = get_runnertype_by_name(runner_name)
                update = True
            except StackStormDBObjectNotFoundError:
                runner_type_db = None
                update = False

            # Note: We don't want to overwrite "enabled" attribute which is already in the database
            # (aka we don't want to re-enable runner which has been disabled by the user)
            if runner_type_db and runner_type_db['enabled'] != runner_type['enabled']:
                runner_type['enabled'] = runner_type_db['enabled']

            runner_type_api = RunnerTypeAPI(**runner_type)
            runner_type_api.validate()
            runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

            if runner_type_db:
                runner_type_model.id = runner_type_db.id

            try:
                runner_type_db = RunnerType.add_or_update(runner_type_model)

                extra = {'runner_type_db': runner_type_db}
                if update:
                    LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra)
                else:
                    LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra)
            except Exception:
                LOG.exception('Unable to register runner type %s.', runner_type['name'])

    LOG.debug('End : register default RunnerTypes.')
Пример #6
0
def register_runner(runner_type, experimental):
    # For backward compatibility reasons, we also register runners under the old names
    runner_names = [runner_type['name']] + runner_type.get('aliases', [])
    for runner_name in runner_names:
        runner_type['name'] = runner_name
        runner_experimental = runner_type.get('experimental', False)

        if runner_experimental and not experimental:
            LOG.debug('Skipping experimental runner "%s"' % (runner_name))
            continue

        # Remove additional, non db-model attributes
        non_db_attributes = ['experimental', 'aliases']
        for attribute in non_db_attributes:
            if attribute in runner_type:
                del runner_type[attribute]

        try:
            runner_type_db = get_runnertype_by_name(runner_name)
            update = True
        except StackStormDBObjectNotFoundError:
            runner_type_db = None
            update = False

        # Note: We don't want to overwrite "enabled" attribute which is already in the database
        # (aka we don't want to re-enable runner which has been disabled by the user)
        if runner_type_db and runner_type_db['enabled'] != runner_type['enabled']:
            runner_type['enabled'] = runner_type_db['enabled']

        # If package is not provided, assume it's the same as module name for backward
        # compatibility reasons
        if not runner_type.get('runner_package', None):
            runner_type['runner_package'] = runner_type['runner_module']

        runner_type_api = RunnerTypeAPI(**runner_type)
        runner_type_api.validate()
        runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

        if runner_type_db:
            runner_type_model.id = runner_type_db.id

        try:

            runner_type_db = RunnerType.add_or_update(runner_type_model)

            extra = {'runner_type_db': runner_type_db}
            if update:
                LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra)
            else:
                LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra)
        except Exception:
            LOG.exception('Unable to register runner type %s.', runner_type['name'])
            return 0
    return 1
Пример #7
0
def register_runner_types(experimental=False):
    """
    :param experimental: True to also register experimental runners.
    :type experimental: ``bool``
    """
    LOG.debug("Start : register default RunnerTypes.")

    for runner_type in RUNNER_TYPES:
        runner_type = copy.deepcopy(runner_type)

        # For backward compatibility reasons, we also register runners under the old names
        runner_names = [runner_type["name"]] + runner_type.get("aliases", [])
        for runner_name in runner_names:
            runner_type["name"] = runner_name
            runner_experimental = runner_type.get("experimental", False)

            if runner_experimental and not experimental:
                LOG.debug('Skipping experimental runner "%s"' % (runner_name))
                continue

            # Remove additional, non db-model attributes
            non_db_attributes = ["experimental", "aliases"]
            for attribute in non_db_attributes:
                if attribute in runner_type:
                    del runner_type[attribute]

            try:
                runner_type_db = get_runnertype_by_name(runner_name)
                update = True
            except StackStormDBObjectNotFoundError:
                runner_type_db = None
                update = False

            runner_type_api = RunnerTypeAPI(**runner_type)
            runner_type_api.validate()
            runner_type_model = RunnerTypeAPI.to_model(runner_type_api)

            if runner_type_db:
                runner_type_model.id = runner_type_db.id

            try:
                runner_type_db = RunnerType.add_or_update(runner_type_model)

                extra = {"runner_type_db": runner_type_db}
                if update:
                    LOG.audit("RunnerType updated. RunnerType %s", runner_type_db, extra=extra)
                else:
                    LOG.audit("RunnerType created. RunnerType %s", runner_type_db, extra=extra)
            except Exception:
                LOG.exception("Unable to register runner type %s.", runner_type["name"])

    LOG.debug("End : register default RunnerTypes.")