Exemple #1
0
    def __init__(self,
                 db_host,
                 db_user,
                 db_passwd,
                 db_name,
                 big_lock_timeout,
                 big_lock_wait,
                 thread_safe=True,
                 ssl=False,
                 ssl_ca=None,
                 ssl_cert=None,
                 ssl_key=None,
                 ssl_capath=None,
                 ssl_cipher=None,
                 db_debug=False,
                 db_debug_log=None):
        """Instantiates the db_access class.

    Inputs:
      db_host: string of the database host name
      db_user: string of the user name used to connect to mysql
      db_passwd: string of password used to connect to mysql
      db_name: string of name of database in mysql server to use
      big_lock_timeout: integer of how long the big lock should be valid for
      big_lock_wait: integer of how long to wait for proccesses to finish
                     before locking the database
      thread_safe: boolean of if db_acceess should be thread safe
    """
        # Do some better checking of these args
        self.db_host = db_host
        self.db_user = db_user
        self.db_passwd = db_passwd
        self.db_name = db_name
        self.big_lock_timeout = big_lock_timeout
        self.big_lock_wait = big_lock_wait
        self.ssl = ssl
        self.ssl_ca = ssl_ca
        self.ssl_settings = {}
        self.db_debug = db_debug
        self.db_debug_log = db_debug_log
        if (self.ssl):
            if (self.ssl_ca):
                self.ssl_settings['ca'] = ssl_ca
            else:
                raise errors.ConfigError(
                    'ssl_ca not specified in config file.')
        self.transaction_init = False
        self.connection = None
        self.cursor = None
        # This is generated only when ListRow is called and is then cached for
        # the life of the object.
        self.foreign_keys = []
        self.data_validation_instance = None
        self.locked_db = False
        self.thread_safe = thread_safe
        self.queue = Queue.Queue()
        self.now_serving = None
        self.queue_update_lock = threading.Lock()
 def _loadModule(self, pluginName, conf, types):
     # load plugin
     try:
         savePath = sys.path
         sys.path.insert(0, self.base.conf.pluginSearchPath)
         if conf.search is not None:
             sys.path.insert(0, conf.search)
         module = __import__(conf.module, globals(), locals(), [])
         sys.path = savePath
     except DisablePlugin:
         moduleLogVerbose.info(
             "\tPlugin raised DisablePlugin exception. skipping.")
         return
     except ImportError, e:
         sys.path = savePath
         raise errors.ConfigError('Plugin "%s" cannot be loaded: %s' %
                                  (conf.module, e))
Exemple #3
0
        configuration = load_config(tornado.options.options.config)
    except (errors.ConfigError, tornado.options.Error), e:
        logging.error(str(e))
        raise SystemExit(1)

    port = determine_port(configuration.get('options'))
    return configuration, port



def load_config(config_path):
    try:
        config = notch_config.get_config_from_file(config_path)
    except errors.ConfigMissingRequiredSectionError, e:
        logging.error('Config file %r did not parse a section named: %r',
                      tornado.options.options.config, str(e))
        raise
    if not config:
        raise errors.ConfigError('No configuration was loaded.')
    else:
        return config


def determine_port(options):
    if options:
        return (tornado.options.options.port or
                options.get('port') or
                DEFAULT_PORT)
    else:
        return tornado.options.options.port or DEFAULT_PORT
Exemple #4
0
    def __init__(self, file_name=constants.SERVER_CONFIG_FILE_LOCATION):
        """Sets self.server, self.database, self.login and self.password from 
    a config file or passed vriables.

    Inputs:
      file_name:	name of config file to parse
      db_server: name of database server
      db_database: name of database on server
      db_login: login name used to access the database
      db_passwd: password used to login to the database

    Raises:
      ConfigError: Could not read the file.
      ConfigError: Variable is not used
      ConfigError: Datatype is not supported
      ConfigError: Variable is missing in config file section
    """
        cp = ConfigParser.SafeConfigParser()
        a = cp.read(file_name)
        self.config_file = {}
        self.config_file_path = file_name
        if (a == []):
            raise errors.ConfigError('Could not read the file %s' % file_name)

        file_schema = constants.CONFIG_FILE_SCHEMA

        for section in file_schema:
            self.config_file[section] = {}
            if (cp.has_section(section)):
                variables = file_schema[section]
                file_variables = cp.options(section)
                for variable in file_variables:
                    if (variable not in variables):
                        raise errors.ConfigError(
                            'Variable "%s" in "%s" is not used' %
                            (variable, file_name))
                for variable in variables:
                    if (variable not in file_variables):
                        raise errors.ConfigError(
                            'Variable "%s" is missing in config file: '
                            '"%s", in the "%s" section.' %
                            (variable, file_name, section))
                    if (variables[variable] is 'str'):
                        self.config_file[section][variable] = (cp.get(
                            section, variable))
                    elif (variables[variable] is 'int'):
                        self.config_file[section][variable] = (cp.getint(
                            section, variable))
                    elif (variables[variable] is 'boolean'):
                        self.config_file[section][variable] = cp.getboolean(
                            section, variable)
                    elif (variables[variable] is 'float'):
                        self.config_file[section][variable] = cp.getfloat(
                            section, variable)
                    else:
                        raise errors.ConfigError(
                            'DataType "%s" is not supported' %
                            (variables[variable]))

        if ('authentication_method' in self.config_file['credentials']):
            authentication_method = self.config_file['credentials'][
                'authentication_method']
            self.config_file[authentication_method] = {}
            authentication_values = cp.items(authentication_method)
            for authentication_value in authentication_values:
                self.config_file[authentication_method][
                    authentication_value[0]] = (authentication_value[1])
class Plugins:
    '''
    Manager class for plugins.
    '''
    def __init__(self, base, optparser=None, types=None, disabled=None):
        '''Initialise the instance.
        '''
        self.base = base
        self.optparser = optparser
        self.cmdline = (None, None)

        self.verbose_logger = getLog(prefix="verbose.")

        self.disabledPlugins = disabled
        if types is None:
            types = ALL_TYPES
        if not isinstance(types, (list, tuple)):
            types = (types, )

        # TODO: load plugins here
        self._plugins = {}
        for i in self.base.listPluginsFromIni():
            conf = self.base.getPluginConfFromIni(i)
            moduleLogVerbose.info("Checking Plugin (%s)" % i)
            if conf.enabled:
                self._loadModule(i, conf, types)

        # Call close handlers when yum exit's
        #atexit.register(self.run, 'close')

        # Let plugins register custom config file options
        self.run('config')

    decorate(traceLog())

    def _loadModule(self, pluginName, conf, types):
        # load plugin
        try:
            savePath = sys.path
            sys.path.insert(0, self.base.conf.pluginSearchPath)
            if conf.search is not None:
                sys.path.insert(0, conf.search)
            module = __import__(conf.module, globals(), locals(), [])
            sys.path = savePath
        except DisablePlugin:
            moduleLogVerbose.info(
                "\tPlugin raised DisablePlugin exception. skipping.")
            return
        except ImportError, e:
            sys.path = savePath
            raise errors.ConfigError('Plugin "%s" cannot be loaded: %s' %
                                     (conf.module, e))

        for i in conf.module.split(".")[1:]:
            module = getattr(module, i)

        # Check API version required by the plugin
        if not hasattr(module, 'requires_api_version'):
            raise errors.ConfigError(
                'Plugin "%s" doesn\'t specify required API version' %
                conf.module)

        if not apiverok(API_VERSION, module.requires_api_version):
            raise errors.ConfigError(
                'Plugin "%s" requires API %s. Supported API is %s.' % (
                    conf.module,
                    module.requires_api_version,
                    API_VERSION,
                ))

        # Check plugin type against filter
        plugintypes = getattr(module, 'plugin_type', None)
        if plugintypes is None:
            raise errors.ConfigError(
                'Plugin "%s" doesn\'t specify plugin type' % pluginName)
        if not isinstance(plugintypes, (list, tuple)):
            plugintypes = (plugintypes, )
        for plugintype in plugintypes:
            if plugintype not in types:
                moduleLogVerbose.info(
                    "\tPlugin %s not loaded: doesnt match load type (%s)" %
                    (pluginName, plugintypes))
                return
        # Check if this plugin has been temporary disabled
        if self.disabledPlugins:
            if pluginName in self.disabledPlugins:
                moduleLogVerbose.info("\tPlugin %s not loaded: disabled" %
                                      pluginName)
                return

        moduleLogVerbose.info("\tLoaded %s plugin" % pluginName)
        self._plugins[pluginName] = {"conf": conf, "module": module}