mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-05-04 12:41:00 +02:00
MINOR: backend: add function to check support for dynamic servers
Move backend compatibility checks performed during 'add server' in a dedicated function be_supports_dynamic_srv(). This should simplify addition of future restriction. This function will be reused when implementing backend creation at runtime.
This commit is contained in:
parent
dc6cf224dd
commit
817003aa31
@ -69,6 +69,7 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
|
||||
int tcp_persist_rdp_cookie(struct stream *s, struct channel *req, int an_bit);
|
||||
|
||||
int be_downtime(struct proxy *px);
|
||||
int be_supports_dynamic_srv(struct proxy *px, char **msg);
|
||||
void recount_servers(struct proxy *px);
|
||||
void update_backend_weight(struct proxy *px);
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ haproxy h1 -cli {
|
||||
|
||||
# invalid load-balancing algo
|
||||
send "add server other/s1 ${s1_addr}:${s1_port}"
|
||||
expect ~ "Backend must use a dynamic load balancing to support dynamic servers."
|
||||
expect ~ "backend 'other' uses a non dynamic load balancing method"
|
||||
|
||||
# invalid mux proto
|
||||
send "add server other2/s1 ${s1_addr}:${s1_port} proto h2"
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
#include <haproxy/task.h>
|
||||
#include <haproxy/ticks.h>
|
||||
#include <haproxy/time.h>
|
||||
#include <haproxy/tools.h>
|
||||
#include <haproxy/trace.h>
|
||||
|
||||
#define TRACE_SOURCE &trace_strm
|
||||
@ -3055,6 +3056,27 @@ int be_downtime(struct proxy *px) {
|
||||
return ns_to_sec(now_ns) - px->last_change + px->down_time;
|
||||
}
|
||||
|
||||
/* Checks if <px> backend supports the addition of servers at runtime. Either a
|
||||
* backend or a defaults proxy are supported. If proxy is incompatible, <msg>
|
||||
* will be allocated to contain a textual explaination.
|
||||
*/
|
||||
int be_supports_dynamic_srv(struct proxy *px, char **msg)
|
||||
{
|
||||
if (px->lbprm.algo && !(px->lbprm.algo & BE_LB_PROP_DYN)) {
|
||||
memprintf(msg, "%s '%s' uses a non dynamic load balancing method",
|
||||
proxy_cap_str(px->cap), px->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (px->mode == PR_MODE_SYSLOG) {
|
||||
memprintf(msg, "%s '%s' uses mode log",
|
||||
proxy_cap_str(px->cap), px->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function returns a string containing the balancing
|
||||
* mode of the proxy in a format suitable for stats.
|
||||
|
||||
12
src/server.c
12
src/server.c
@ -6104,7 +6104,7 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
|
||||
struct add_srv_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
|
||||
struct proxy *be;
|
||||
struct server *srv;
|
||||
char *be_name, *sv_name;
|
||||
char *be_name, *sv_name, *errmsg;
|
||||
int errcode, argc;
|
||||
int next_id;
|
||||
const int parse_flags = SRV_PARSE_DYNAMIC|SRV_PARSE_PARSE_ADDR;
|
||||
@ -6140,13 +6140,9 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
|
||||
if (!be)
|
||||
return cli_err(appctx, "No such backend.\n");
|
||||
|
||||
if (!(be->lbprm.algo & BE_LB_PROP_DYN)) {
|
||||
cli_err(appctx, "Backend must use a dynamic load balancing to support dynamic servers.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (be->mode == PR_MODE_SYSLOG) {
|
||||
cli_err(appctx," Dynamic servers cannot be used with log backends.\n");
|
||||
errmsg = NULL;
|
||||
if (!be_supports_dynamic_srv(be, &errmsg)) {
|
||||
cli_dynerr(appctx, memprintf(&errmsg, "Backend does not support dynamic servers : %s.\n", errmsg));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user