def get_my_nodes_settings(): """ Return the mapping from node port to the node settings (which include the port as well, btw). This mapping is taken from the node.conf file exclusively. @rtype: dict @postcondition: consists_of(result.iterkeys(), int) @postcondition: consists_of(result.itervalues(), NodeConfSettings) """ parser = common_settings.get_conf_parser('node.conf', relative_path='.') node_sections = [s for s in parser.sections() if s.startswith('node-')] result = {} # Should do that iteratively, to generate proper error logs for sect in node_sections: # Read and validate all options for this node try: _port = parser.getint(sect, 'port') except: logger.critical('Cannot read port for section %s', sect) continue try: _uuid = UUID(parser.get(sect, 'uuid')) except: logger.critical('Cannot read uuid for section %s', sect) continue try: _control_sockets = parser.get(sect, 'control-sockets').split() except ConfigParserError: logger.critical('Cannot read control-sockets for section %s', sect) continue # Seems all required options are present, add the node. assert _port not in result result[_port] = NodeConfSettings(port=_port, uuid=_uuid, control_sockets=_control_sockets) return result
def reread_from_conf_file(cls): """ Reread the conf-file and return a new instance of C{ConfSettings} with the settings as defined in the node.conf file. This includes three build versions (version timestamps): the node build version, the required version and the recommended version. The first one is calculated from the code, the latter two are defined in the node.conf file. If they are absent, they are returned equal to the node own version. @note: each call to this function perform complete parsing of the Mercurial repository, and of the config file if applicable. @returns: the tuple containing all the node-specific settings. @rtype: ConfSettingsTuple @raises Exception: if something important cannot be determined or failed to be parsed. """ parser = common_settings.get_conf_parser('node.conf', relative_path='.') _conf_dir = common_settings.conf_dir() try: with open(os.path.join(_conf_dir, parser.get('common', 'ssl-cert')), 'r') as fh: _cert = crypto.load_certificate(crypto.FILETYPE_PEM, fh.read()) except Exception: #raise Exception("Cannot read ssl-cert setting: %s" % e) _cert = None try: with open(os.path.join(_conf_dir, parser.get('common', 'ssl-pkey')), 'r') as fh: _pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, fh.read()) except Exception: #raise Exception("Cannot read ssl-pkey setting: %s" % e) _pkey = None _build = get_build_timestamp() _edition = _parser_get_raw(parser, 'common', 'edition') # Read raw values from the conf file. _req = _parser_get_raw(parser, 'common', 'required-version', _build) _rec = _parser_get_raw(parser, 'common', 'recommended-version', _build) _rel_db_url = _parser_get_raw(parser, 'common', 'rel-db-url') _fast_db_url = _parser_get_raw(parser, 'common', 'fast-db-url') _big_db_url = _parser_get_raw(parser, 'common', 'big-db-url') return cls(edition=_edition, ssl_cert=_cert, ssl_pkey=_pkey, build_version=_build, required_version=_req, recommended_version=_rec, rel_db_url=_rel_db_url, fast_db_url=_fast_db_url, big_db_url=_big_db_url)
def reread_from_conf_file(cls): """ Reread the conf-file and return a new instance of C{ConfSettings} with the settings as defined in the node.conf file. This includes three build versions (version timestamps): the node build version, the required version and the recommended version. The first one is calculated from the code, the latter two are defined in the node.conf file. If they are absent, they are returned equal to the node own version. @note: each call to this function perform complete parsing of the Mercurial repository, and of the config file if applicable. @returns: the tuple containing all the node-specific settings. @rtype: ConfSettingsTuple @raises Exception: if something important cannot be determined or failed to be parsed. """ parser = common_settings.get_conf_parser('node.conf', relative_path='.') _conf_dir = common_settings.conf_dir() try: with open( os.path.join(_conf_dir, parser.get('common', 'ssl-cert')), 'r') as fh: _cert = crypto.load_certificate(crypto.FILETYPE_PEM, fh.read()) except Exception: #raise Exception("Cannot read ssl-cert setting: %s" % e) _cert = None try: with open( os.path.join(_conf_dir, parser.get('common', 'ssl-pkey')), 'r') as fh: _pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, fh.read()) except Exception: #raise Exception("Cannot read ssl-pkey setting: %s" % e) _pkey = None _build = get_build_timestamp() _edition = _parser_get_raw(parser, 'common', 'edition') # Read raw values from the conf file. _req = _parser_get_raw(parser, 'common', 'required-version', _build) _rec = _parser_get_raw(parser, 'common', 'recommended-version', _build) _rel_db_url = _parser_get_raw(parser, 'common', 'rel-db-url') _fast_db_url = _parser_get_raw(parser, 'common', 'fast-db-url') _big_db_url = _parser_get_raw(parser, 'common', 'big-db-url') return cls(edition=_edition, ssl_cert=_cert, ssl_pkey=_pkey, build_version=_build, required_version=_req, recommended_version=_rec, rel_db_url=_rel_db_url, fast_db_url=_fast_db_url, big_db_url=_big_db_url)