self.host_provider = config_provider.getProviderByName(
            setting.HOST_CONFIG_PROVIDER)

    def getGlobalConfig(self):
        '''get global config.'''
        return self.global_provider.getGlobalConfig()

    def getClusterConfig(self, clusterid):
        '''get cluster config.'''
        return self.cluster_provider.getClusterConfig(clusterid)

    def getHostConfig(self, hostid):
        '''get host config.'''
        return self.host_provider.getHostConfig(hostid)

    def updateGlobalConfig(self, config):
        '''update global config.'''
        self.global_provider.updateGlobalConfig(config)

    def updateClusterConfig(self, clusterid, config):
        '''update cluster config.'''
        self.cluster_provider.updateClusterConfig(
            clusterid, config)

    def updateHostConfig(self, hostid, config):
        '''update host config.'''
        self.host_provider.updateHostConfig(hostid, config)


config_provider.registerProvider(MixProvider)
 def test_multi_registered_provider(self):
     config_provider.registerProvider(DummyProvider)
     self.assertRaises(KeyError, config_provider.registerProvider,
                       Dummy2Provider)
Example #3
0
    def getClusterConfig(self, clusterid):
        '''get cluster config from db.'''
        session = database.current_session()
        cluster = session.query(Cluster).filter_by(id=clusterid).first()
        if cluster:
            return cluster.config
        else:
            return {}

    def getHostConfig(self, hostid):
        '''get host config from db.'''
        session = database.current_session()
        host = session.query(ClusterHost).filter_by(id=hostid).first()
        if host:
            return host.config
        else:
            return {}

    def updateHostConfig(self, hostid, config):
        '''update hsot config to db.'''
        session = database.current_session()
        host = session.query(ClusterHost).filter_by(id=hostid).first()
        if not host:
            return
        filtered_config = self.HOST_FILTER.filter(config)
        host.config = filtered_config


config_provider.registerProvider(DBProvider)
 def test_found_provider(self):
     config_provider.registerProvider(DummyProvider)
     provider = config_provider.getProviderByName(DummyProvider.NAME)
     self.assertIsInstance(provider, DummyProvider)
        except Exception as error:
            logging.error('failed to read file %s', filename)
            logging.exception(error)
            return {}

        if cls._configFormatIsPython(config_format):
            try:
                exec(content, config_globals, config_locals)
            except Exception as error:
                logging.error('failed to exec %s', content)
                logging.exception(error)
                return {}

        elif cls._configFormatIsJson(config_format):
            try:
                config_locals = json.loads(content)
            except Exception as error:
                logging.error('failed to load json data %s', content)
                logging.exception(error)
                return {}

        return config_locals

    def getGlobalConfig(self):
        '''read global config from file.'''
        return self._readConfigFromFile(self._globalConfigFilename(),
                                        self._getConfigFormat())


config_provider.registerProvider(FileProvider)
            setting.CLUSTER_CONFIG_PROVIDER)
        self.host_provider = config_provider.getProviderByName(
            setting.HOST_CONFIG_PROVIDER)

    def getGlobalConfig(self):
        '''get global config.'''
        return self.global_provider.getGlobalConfig()

    def getClusterConfig(self, clusterid):
        '''get cluster config.'''
        return self.cluster_provider.getClusterConfig(clusterid)

    def getHostConfig(self, hostid):
        '''get host config.'''
        return self.host_provider.getHostConfig(hostid)

    def updateGlobalConfig(self, config):
        '''update global config.'''
        self.global_provider.updateGlobalConfig(config)

    def updateClusterConfig(self, clusterid, config):
        '''update cluster config.'''
        self.cluster_provider.updateClusterConfig(clusterid, config)

    def updateHostConfig(self, hostid, config):
        '''update host config.'''
        self.host_provider.updateHostConfig(hostid, config)


config_provider.registerProvider(MixProvider)
            logging.error('failed to read file %s', filename)
            logging.exception(error)
            return {}

        if cls._configFormatIsPython(config_format):
            try:
                exec(content, config_globals, config_locals)
            except Exception as error:
                logging.error('failed to exec %s', content)
                logging.exception(error)
                return {}

        elif cls._configFormatIsJson(config_format):
            try:
                config_locals = json.loads(content)
            except Exception as error:
                logging.error('failed to load json data %s', content)
                logging.exception(error)
                return {}

        return config_locals

    def getGlobalConfig(self):
        '''read global config from file.'''
        return self._readConfigFromFile(
            self._globalConfigFilename(),
            self._getConfigFormat())


config_provider.registerProvider(FileProvider)
Example #8
0
    def getClusterConfig(self, clusterid):
        '''get cluster config from db.'''
        session = database.current_session()
        cluster = session.query(Cluster).filter_by(id=clusterid).first()
        if cluster:
            return cluster.config
        else:
            return {}

    def getHostConfig(self, hostid):
        '''get host config from db.'''
        session = database.current_session()
        host = session.query(ClusterHost).filter_by(id=hostid).first()
        if host:
            return host.config
        else:
            return {}

    def updateHostConfig(self, hostid, config):
        '''update hsot config to db.'''
        session = database.current_session()
        host = session.query(ClusterHost).filter_by(id=hostid).first()
        if not host:
            return
        filtered_config = self.HOST_FILTER.filter(config)
        host.config = filtered_config


config_provider.registerProvider(DBProvider)