Example #1
0
def config_get(section,
               option,
               raise_exception=True,
               default=None,
               clean_cached=False,
               check_config_table=True,
               session=None,
               use_cache=True,
               expiration_time=900):
    """
    Return the string value for a given option in a section

    First it looks at the configuration file and, if it is not found, check in the config table only if it is called
    from a server/daemon (and if check_config_table is set).

    :param section: the named section.
    :param option: the named option.
    :param raise_exception: Boolean to raise or not NoOptionError, NoSectionError or RuntimeError.
    :param default: the default value if not found.
    :param check_config_table: if not set, avoid looking at config table even if it is called from server/daemon
    :param session: The database session in use. Only used if not found in config file and if it is called from
                    server/daemon
    :param use_cache: Boolean if the cache should be used. Only used if not found in config file and if it is called
                      from server/daemon
    :param expiration_time: Time after that the cached value gets ignored. Only used if not found in config file and if
                            it is called from server/daemon

    :returns: the configuration value.

    :raises NoOptionError
    :raises NoSectionError
    :raises RuntimeError
    """
    global __CONFIG
    from rucio.common.utils import is_client
    client_mode = is_client()
    try:
        return get_config().get(section, option)
    except (ConfigParser.NoOptionError, ConfigParser.NoSectionError,
            RuntimeError) as err:
        if not client_mode and check_config_table:
            try:
                return __config_get_table(section=section,
                                          option=option,
                                          raise_exception=raise_exception,
                                          default=default,
                                          clean_cached=clean_cached,
                                          session=session,
                                          use_cache=use_cache,
                                          expiration_time=expiration_time)
            except (ConfigNotFound, DatabaseException, ImportError):
                raise err
        else:
            if raise_exception and default is None:
                raise err
            if clean_cached:
                __CONFIG = None
            return default
Example #2
0
def config_get_bool(section,
                    option,
                    raise_exception=True,
                    default=None,
                    check_config_table=True,
                    session=None,
                    use_cache=True,
                    expiration_time=900):
    """
    Return the boolean value for a given option in a section

    :param section: the named section.
    :param option: the named option.
    :param raise_exception: Boolean to raise or not NoOptionError, NoSectionError or RuntimeError.
    :param default: the default value if not found.
    :param check_config_table: if not set, avoid looking at config table even if it is called from server/daemon
    :param session: The database session in use. Only used if not found in config file and if it is called from
                    server/daemon
    :param use_cache: Boolean if the cache should be used. Only used if not found in config file and if it is called
                      from server/daemon
    :param expiration_time: Time after that the cached value gets ignored. Only used if not found in config file and if
                            it is called from server/daemon
.
    :returns: the configuration value.

    :raises NoOptionError
    :raises NoSectionError
    :raises RuntimeError
    :raises ValueError
    """
    from rucio.common.utils import is_client
    client_mode = is_client()
    try:
        return get_config().getboolean(section, option)
    except (ConfigParser.NoOptionError, ConfigParser.NoSectionError,
            RuntimeError) as err:
        if not client_mode and check_config_table:
            try:
                return bool(
                    __config_get_table(section=section,
                                       option=option,
                                       raise_exception=raise_exception,
                                       default=default,
                                       session=session,
                                       use_cache=use_cache,
                                       expiration_time=expiration_time))
            except (ConfigNotFound, DatabaseException, ImportError):
                raise err
            except ValueError as err_:
                raise err_
        else:
            if raise_exception and default is None:
                raise err
            try:
                return bool(default)
            except ValueError as err_:
                raise err_
Example #3
0
# - Cedric Serfon <*****@*****.**>, 2017-2019
# - James Perry <*****@*****.**>, 2019
# - Andrew Lister <*****@*****.**>, 2019
# - Brandon White <*****@*****.**>, 2019
# - Eli Chadwick <*****@*****.**>, 2020
# - Simon Fayer <*****@*****.**>, 2021
# - Gabriele Fronzé <*****@*****.**>, 2021
# - David Población Criado <*****@*****.**>, 2021

from dogpile.cache import make_region

from rucio.common.utils import is_client
from rucio.rse import rsemanager
from rucio.common import config

if is_client():
    setattr(rsemanager, 'CLIENT_MODE', True)
    setattr(rsemanager, 'SERVER_MODE', False)
else:
    setattr(rsemanager, 'CLIENT_MODE', False)
    setattr(rsemanager, 'SERVER_MODE', True)


def get_rse_client(rse, vo='def', **kwarg):
    '''
    get_rse_client
    '''
    from rucio.client.rseclient import RSEClient
    client = RSEClient(vo=vo)
    return client.get_rse(rse)