]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] stats: add support for numeric IDs in set weight/get weight
authorWilly Tarreau <w@1wt.eu>
Sat, 10 Oct 2009 20:33:08 +0000 (22:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Oct 2009 20:33:08 +0000 (22:33 +0200)
Krzysztof reported that using names only for get weight/set weight
was not enough because it's still possible to have multiple servers
with the same name (and my test config is one of those). He suggested
to be able to designate them by their unique numeric IDs by prefixing
the ID with a dash.

That way we can have :

     set weight #120/#2

as well as

     get weight static/srv1 10

doc/configuration.txt
src/proxy.c

index 276f660b21bc29490ec46c8d65b59391e6736b93..65a8cefb4abb493a35c6fd386ce0229bbcf34feb 100644 (file)
@@ -6874,7 +6874,9 @@ get weight <backend>/<server>
   Report the current weight and the initial weight of server <server> in
   backend <backend> or an error if either doesn't exist. The initial weight is
   the one that appears in the configuration file. Both are normally equal
-  unless the current weight has been changed.
+  unless the current weight has been changed. Both the backend and the server
+  may be specified either by their name or by their numeric ID, prefixed with a
+  dash ('#').
 
 set weight <backend>/<server> <weight>[%]
   Change a server's weight to the value passed in argument. If the value ends
@@ -6888,7 +6890,9 @@ set weight <backend>/<server> <weight>[%]
   requests to consider changes. A typical usage of this command is to disable
   a server during an update by setting its weight to zero, then to enable it
   again after the update by setting it back to 100%. This command is restricted
-  and can only be issued on sockets configured for level "admin".
+  and can only be issued on sockets configured for level "admin". Both the
+  backend and the server may be specified either by their name or by their
+  numeric ID, prefixed with a dash ('#').
 
 
 /*
index e44d3d90540710b620a87ba2d4e729fe9ee40d5b..dd6504802696dc014360419b154aefcbafa3962d 100644 (file)
@@ -88,11 +88,21 @@ int get_backend_server(const char *bk_name, const char *sv_name,
 {
        struct proxy *p;
        struct server *s;
+       int pid, sid;
 
        *sv = NULL;
 
+       pid = 0;
+       if (*bk_name == '#')
+               pid = atoi(bk_name + 1);
+       sid = 0;
+       if (*sv_name == '#')
+               sid = atoi(sv_name + 1);
+
        for (p = proxy; p; p = p->next)
-               if ((p->cap & PR_CAP_BE) && (strcmp(p->id, bk_name) == 0))
+               if ((p->cap & PR_CAP_BE) &&
+                   ((pid && p->uuid == pid) ||
+                    (!pid && strcmp(p->id, bk_name) == 0)))
                        break;
        if (bk)
                *bk = p;
@@ -100,7 +110,8 @@ int get_backend_server(const char *bk_name, const char *sv_name,
                return 0;
 
        for (s = p->srv; s; s = s->next)
-               if (strcmp(s->id, sv_name) == 0)
+               if ((sid && s->puid == sid) ||
+                   (!sid && strcmp(s->id, sv_name) == 0))
                        break;
        *sv = s;
        if (!s)