Example #1
0
def top(**kwargs):
    # If reclass is installed, __virtual__ put it onto the search path, so we
    # don't need to protect against ImportError:
    from reclass.adapters.salt import top as reclass_top
    from reclass.errors import ReclassException

    try:
        # Salt's top interface is inconsistent with ext_pillar (see #5786) and
        # one is expected to extract the arguments to the master_tops plugin
        # by parsing the configuration file data. I therefore use this adapter
        # to hide this internality.
        reclass_opts = __opts__['master_tops']['reclass']

        # the source path we used above isn't something reclass needs to care
        # about, so filter it:
        filter_out_source_path_option(reclass_opts)

        # if no inventory_base_uri was specified, initialise it to the first
        # file_roots of class 'base' (if that exists):
        set_inventory_base_uri_default(__opts__, kwargs)

        # I purposely do not pass any of __opts__ or __salt__ or __grains__
        # to reclass, as I consider those to be Salt-internal and reclass
        # should not make any assumptions about it. Reclass only needs to know
        # how it's configured, so:
        return reclass_top(**reclass_opts)

    except ImportError as e:
        if 'reclass' in e.message:
            raise SaltInvocationError('master_tops.reclass: cannot find reclass '\
                                      'module in ' + sys.path)
        else:
            raise

    except TypeError as e:
        if 'unexpected keyword argument' in e.message:
            arg = e.message.split()[-1]
            raise SaltInvocationError('master_tops.reclass: unexpected option: ' + arg)
        else:
            raise

    except KeyError as e:
        if 'reclass' in e.message:
            raise SaltInvocationError('master_tops.reclass: no configuration '\
                                      'found in master config')
        else:
            raise

    except ReclassException as e:
        raise SaltInvocationError('master_tops.reclass: ' + e.message)
Example #2
0
def ext_pillar(minion_id, pillar, **kwargs):
    """
    Obtain the Pillar data from **reclass** for the given ``minion_id``.
    """

    # If reclass is installed, __virtual__ put it onto the search path, so we
    # don't need to protect against ImportError:
    # pylint: disable=3rd-party-module-not-gated,no-name-in-module
    from reclass.adapters.salt import ext_pillar as reclass_ext_pillar
    from reclass.errors import ReclassException

    # pylint: enable=3rd-party-module-not-gated,no-name-in-module

    try:
        # the source path we used above isn't something reclass needs to care
        # about, so filter it:
        filter_out_source_path_option(kwargs)

        # if no inventory_base_uri was specified, initialize it to the first
        # file_roots of class 'base' (if that exists):
        set_inventory_base_uri_default(__opts__, kwargs)

        # I purposely do not pass any of __opts__ or __salt__ or __grains__
        # to reclass, as I consider those to be Salt-internal and reclass
        # should not make any assumptions about it.
        return reclass_ext_pillar(minion_id, pillar, **kwargs)

    except TypeError as e:
        if "unexpected keyword argument" in str(e):
            arg = str(e).split()[-1]
            raise SaltInvocationError("ext_pillar.reclass: unexpected option: " + arg)
        else:
            raise

    except KeyError as e:
        if "id" in str(e):
            raise SaltInvocationError(
                "ext_pillar.reclass: __opts__ does not " "define minion ID"
            )
        else:
            raise

    except ReclassException as e:
        raise SaltInvocationError("ext_pillar.reclass: {}".format(e))
Example #3
0
def ext_pillar(minion_id, pillar, **kwargs):
    '''
    Obtain the Pillar data from **reclass** for the given ``minion_id``.
    '''

    # If reclass is installed, __virtual__ put it onto the search path, so we
    # don't need to protect against ImportError:
    from reclass.adapters.salt import ext_pillar as reclass_ext_pillar
    from reclass.errors import ReclassException

    try:
        # the source path we used above isn't something reclass needs to care
        # about, so filter it:
        filter_out_source_path_option(kwargs)

        # if no inventory_base_uri was specified, initialize it to the first
        # file_roots of class 'base' (if that exists):
        set_inventory_base_uri_default(__opts__, kwargs)

        # I purposely do not pass any of __opts__ or __salt__ or __grains__
        # to reclass, as I consider those to be Salt-internal and reclass
        # should not make any assumptions about it.
        return reclass_ext_pillar(minion_id, pillar, **kwargs)

    except TypeError as e:
        if 'unexpected keyword argument' in e.message:
            arg = e.message.split()[-1]
            raise SaltInvocationError(
                'ext_pillar.reclass: unexpected option: ' + arg)
        else:
            raise

    except KeyError as e:
        if 'id' in e.message:
            raise SaltInvocationError('ext_pillar.reclass: __opts__ does not '
                                      'define minion ID')
        else:
            raise

    except ReclassException as e:
        raise SaltInvocationError('ext_pillar.reclass: {0}'.format(e.message))
def ext_pillar(minion_id, pillar, **kwargs):
    '''
    Obtain the Pillar data from **reclass** for the given ``minion_id``.
    '''

    # If reclass is installed, __virtual__ put it onto the search path, so we
    # don't need to protect against ImportError:
    from reclass.adapters.salt import ext_pillar as reclass_ext_pillar
    from reclass.errors import ReclassException

    try:
        # the source path we used above isn't something reclass needs to care
        # about, so filter it:
        filter_out_source_path_option(kwargs)

        # if no inventory_base_uri was specified, initialize it to the first
        # file_roots of class 'base' (if that exists):
        set_inventory_base_uri_default(__opts__, kwargs)

        # I purposely do not pass any of __opts__ or __salt__ or __grains__
        # to reclass, as I consider those to be Salt-internal and reclass
        # should not make any assumptions about it.
        return reclass_ext_pillar(minion_id, pillar, **kwargs)

    except TypeError as e:
        if 'unexpected keyword argument' in str(e):
            arg = str(e).split()[-1]
            raise SaltInvocationError('ext_pillar.reclass: unexpected option: '
                                      + arg)
        else:
            raise

    except KeyError as e:
        if 'id' in str(e):
            raise SaltInvocationError('ext_pillar.reclass: __opts__ does not '
                                      'define minion ID')
        else:
            raise

    except ReclassException as e:
        raise SaltInvocationError('ext_pillar.reclass: {0}'.format(str(e)))
Example #5
0
def top(**kwargs):
    '''
    Query |reclass| for the top data (states of the minions).
    '''

    # If reclass is installed, __virtual__ put it onto the search path, so we
    # don't need to protect against ImportError:
    # pylint: disable=3rd-party-module-not-gated
    from reclass.adapters.salt import top as reclass_top
    from reclass.errors import ReclassException
    # pylint: enable=3rd-party-module-not-gated

    try:
        # Salt's top interface is inconsistent with ext_pillar (see #5786) and
        # one is expected to extract the arguments to the master_tops plugin
        # by parsing the configuration file data. I therefore use this adapter
        # to hide this internality.
        reclass_opts = __opts__['master_tops']['reclass']

        # the source path we used above isn't something reclass needs to care
        # about, so filter it:
        filter_out_source_path_option(reclass_opts)

        # if no inventory_base_uri was specified, initialise it to the first
        # file_roots of class 'base' (if that exists):
        set_inventory_base_uri_default(__opts__, kwargs)

        # Salt expects the top data to be filtered by minion_id, so we better
        # let it know which minion it is dealing with. Unfortunately, we must
        # extract these data (see #6930):
        minion_id = kwargs['opts']['id']

        # I purposely do not pass any of __opts__ or __salt__ or __grains__
        # to reclass, as I consider those to be Salt-internal and reclass
        # should not make any assumptions about it. Reclass only needs to know
        # how it's configured, so:
        return reclass_top(minion_id, **reclass_opts)

    except ImportError as e:
        if 'reclass' in six.text_type(e):
            raise SaltInvocationError(
                'master_tops.reclass: cannot find reclass module '
                'in {0}'.format(sys.path))
        else:
            raise

    except TypeError as e:
        if 'unexpected keyword argument' in six.text_type(e):
            arg = six.text_type(e).split()[-1]
            raise SaltInvocationError(
                'master_tops.reclass: unexpected option: {0}'.format(arg))
        else:
            raise

    except KeyError as e:
        if 'reclass' in six.text_type(e):
            raise SaltInvocationError('master_tops.reclass: no configuration '
                                      'found in master config')
        else:
            raise

    except ReclassException as e:
        raise SaltInvocationError('master_tops.reclass: {0}'.format(
            six.text_type(e)))
Example #6
0
def top(**kwargs):
    '''
    Query |reclass| for the top data (states of the minions).
    '''

    # If reclass is installed, __virtual__ put it onto the search path, so we
    # don't need to protect against ImportError:
    from reclass.adapters.salt import top as reclass_top
    from reclass.errors import ReclassException

    try:
        # Salt's top interface is inconsistent with ext_pillar (see #5786) and
        # one is expected to extract the arguments to the master_tops plugin
        # by parsing the configuration file data. I therefore use this adapter
        # to hide this internality.
        reclass_opts = __opts__['master_tops']['reclass']

        # the source path we used above isn't something reclass needs to care
        # about, so filter it:
        filter_out_source_path_option(reclass_opts)

        # if no inventory_base_uri was specified, initialise it to the first
        # file_roots of class 'base' (if that exists):
        set_inventory_base_uri_default(__opts__, kwargs)

        # Salt expects the top data to be filtered by minion_id, so we better
        # let it know which minion it is dealing with. Unfortunately, we must
        # extract these data (see #6930):
        minion_id = kwargs['opts']['id']

        # I purposely do not pass any of __opts__ or __salt__ or __grains__
        # to reclass, as I consider those to be Salt-internal and reclass
        # should not make any assumptions about it. Reclass only needs to know
        # how it's configured, so:
        return reclass_top(minion_id, **reclass_opts)

    except ImportError as e:
        if 'reclass' in str(e):
            raise SaltInvocationError(
                'master_tops.reclass: cannot find reclass module '
                'in {0}'.format(sys.path)
            )
        else:
            raise

    except TypeError as e:
        if 'unexpected keyword argument' in str(e):
            arg = str(e).split()[-1]
            raise SaltInvocationError(
                'master_tops.reclass: unexpected option: {0}'.format(arg)
            )
        else:
            raise

    except KeyError as e:
        if 'reclass' in str(e):
            raise SaltInvocationError('master_tops.reclass: no configuration '
                                      'found in master config')
        else:
            raise

    except ReclassException as e:
        raise SaltInvocationError('master_tops.reclass: {0}'.format(str(e)))