def config_from_string(data): """ Given a string representing a HAProxy configuration, returns a Config object representing it. """ config = Config() for line in data.split("\n"): if zato_item_token in line: value, config_token_name = line.split(zato_item_token) value = value.strip() for token_name in config_tokens_grammar: if config_token_name.startswith(token_name): result = config_tokens_grammar[token_name].parseString(value) config.set_value(token_name, result) return config
def validate_save(req, cluster_id): """ A common handler for both validating and saving a HAProxy config using a pretty GUI form. """ save = _get_validate_save_flag(cluster_id, req.POST) cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one() client = get_lb_client(cluster) lb_config = Config() lb_config.global_["log"] = {} lb_config.frontend["front_http_plain"] = {} lb_config.frontend["front_http_plain"]["bind"] = {} lb_config.global_["log"]["host"] = req.POST["global_log_host"] lb_config.global_["log"]["port"] = req.POST["global_log_port"] lb_config.global_["log"]["level"] = req.POST["global_log_level"] lb_config.global_["log"]["facility"] = req.POST["global_log_facility"] lb_config.defaults["timeout_connect"] = req.POST["timeout_connect"] lb_config.defaults["timeout_client"] = req.POST["timeout_client"] lb_config.defaults["timeout_server"] = req.POST["timeout_server"] lb_config.frontend["front_http_plain"]["bind"]["address"] = req.POST["http_plain_bind_address"] lb_config.frontend["front_http_plain"]["bind"]["port"] = req.POST["http_plain_bind_port"] lb_config.frontend["front_http_plain"]["log_http_requests"] = req.POST["http_plain_log_http_requests"] lb_config.frontend["front_http_plain"]["maxconn"] = req.POST["http_plain_maxconn"] lb_config.frontend["front_http_plain"]["monitor_uri"] = req.POST["http_plain_monitor_uri"] for key, value in req.POST.items(): if key.startswith("bck_http"): for token in("address", "port", "extra"): splitted = key.split(token) if splitted[0] == key: continue # We don't have the token in that key. backend_type, backend_name = splitted # Get rid of underscores left over from the .split above. backend_type = backend_type[:-1] backend_name = backend_name[1:] lb_config.backend.setdefault(backend_type, {}) lb_config.backend[backend_type].setdefault(backend_name, {}) lb_config.backend[backend_type][backend_name][token] = value # Invoke the LB agent return _client_validate_save(req, client.validate_save, lb_config, save)
def validate_save(req, cluster_id): """ A common handler for both validating and saving a HAProxy config using a pretty GUI form. """ save = _get_validate_save_flag(cluster_id, req.POST) cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one() client = get_lb_client(cluster) lb_config = Config() lb_config.global_["log"] = {} lb_config.frontend["front_http_plain"] = {} lb_config.frontend["front_http_plain"]["bind"] = {} lb_config.global_["log"]["host"] = req.POST["global_log_host"] lb_config.global_["log"]["port"] = req.POST["global_log_port"] lb_config.global_["log"]["level"] = req.POST["global_log_level"] lb_config.global_["log"]["facility"] = req.POST["global_log_facility"] lb_config.defaults["timeout_connect"] = req.POST["timeout_connect"] lb_config.defaults["timeout_client"] = req.POST["timeout_client"] lb_config.defaults["timeout_server"] = req.POST["timeout_server"] lb_config.frontend["front_http_plain"]["bind"]["address"] = req.POST[ "http_plain_bind_address"] lb_config.frontend["front_http_plain"]["bind"]["port"] = req.POST[ "http_plain_bind_port"] lb_config.frontend["front_http_plain"]["log_http_requests"] = req.POST[ "http_plain_log_http_requests"] lb_config.frontend["front_http_plain"]["maxconn"] = req.POST[ "http_plain_maxconn"] lb_config.frontend["front_http_plain"]["monitor_uri"] = req.POST[ "http_plain_monitor_uri"] for key, value in req.POST.items(): if key.startswith("bck_http"): for token in ("address", "port", "extra"): splitted = key.split(token) if splitted[0] == key: continue # We don't have the token in that key. backend_type, backend_name = splitted # Get rid of underscores left over from the .split above. backend_type = backend_type[:-1] backend_name = backend_name[1:] lb_config.backend.setdefault(backend_type, {}) lb_config.backend[backend_type].setdefault(backend_name, {}) lb_config.backend[backend_type][backend_name][token] = value # Invoke the LB agent return _client_validate_save(req, client.validate_save, lb_config, save)
def validate_save(req, cluster_id): """ A common handler for both validating and saving a HAProxy config using a pretty GUI form. """ save = _get_validate_save_flag(cluster_id, req.POST) cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one() client = get_lb_client(cluster) lb_config = Config() lb_config.global_['log'] = {} lb_config.frontend['front_http_plain'] = {} lb_config.frontend['front_http_plain']['bind'] = {} lb_config.global_['log']['host'] = req.POST['global_log_host'] lb_config.global_['log']['port'] = req.POST['global_log_port'] lb_config.global_['log']['level'] = req.POST['global_log_level'] lb_config.global_['log']['facility'] = req.POST['global_log_facility'] lb_config.defaults['timeout_connect'] = req.POST['timeout_connect'] lb_config.defaults['timeout_client'] = req.POST['timeout_client'] lb_config.defaults['timeout_server'] = req.POST['timeout_server'] lb_config.frontend['front_http_plain']['bind']['address'] = req.POST[ 'http_plain_bind_address'] lb_config.frontend['front_http_plain']['bind']['port'] = req.POST[ 'http_plain_bind_port'] lb_config.frontend['front_http_plain']['log_http_requests'] = req.POST[ 'http_plain_log_http_requests'] lb_config.frontend['front_http_plain']['maxconn'] = req.POST[ 'http_plain_maxconn'] lb_config.frontend['front_http_plain']['monitor_uri'] = req.POST[ 'http_plain_monitor_uri'] for key, value in req.POST.items(): if key.startswith('bck_http'): for token in ('address', 'port', 'extra'): splitted = key.split(token) if splitted[0] == key: continue # We don't have the token in that key. backend_type, backend_name = splitted # Get rid of underscores left over from the .split above. backend_type = backend_type[:-1] backend_name = backend_name[1:] lb_config.backend.setdefault(backend_type, {}) lb_config.backend[backend_type].setdefault(backend_name, {}) lb_config.backend[backend_type][backend_name][token] = value # Invoke the LB agent return _client_validate_save(req, client.validate_save, lb_config, save)