]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua_fcn: add Server.get_proxy()
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 3 Apr 2023 12:00:58 +0000 (14:00 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 May 2023 14:28:32 +0000 (16:28 +0200)
Server.get_proxy(): get the proxy to which the server belongs
(or nil if not available)

doc/lua-api/index.rst
include/haproxy/hlua_fcn.h
src/hlua_fcn.c

index 042f2319881f3dc5d15d148a35a0fc8e0eb986f8..fd3d47c77f8e5d4b2adb6fbcf72d601c4d39f23d 100644 (file)
@@ -1233,6 +1233,14 @@ Server class
    server.
   :returns: a key/value table containing stats
 
+.. js:function:: Server.get_proxy(sv)
+
+  Returns the parent proxy to which the server belongs.
+
+  :param class_server sv: A :ref:`server_class` which indicates the manipulated
+   server.
+  :returns: a :ref:`proxy_class` or nil if not available
+
 .. js:function:: Server.shut_sess(sv)
 
   Shutdown all the sessions attached to the server. See the management socket
index 8516514feb655bcf812522cf50381e523e7dda27..ff9250afe3f09758caadb04061fb91e4e3f64d29 100644 (file)
@@ -34,6 +34,7 @@ void *hlua_checkudata(lua_State *L, int ud, int class_ref);
 int hlua_register_metatable(struct lua_State *L, char *name);
 void hlua_fcn_reg_core_fcn(lua_State *L);
 int hlua_dump_object(lua_State *L);
+int hlua_fcn_new_proxy(lua_State *L, struct proxy *px);
 int hlua_fcn_new_server(lua_State *L, struct server *srv);
 int hlua_fcn_new_event_sub(lua_State *L, struct event_hdl_sub *sub);
 
index 308e1d82193ac03be0f21fd5480b2e18f10e4b89..7150b0ca34c113b2b065d7817d7973aecb50f436 100644 (file)
@@ -941,6 +941,25 @@ int hlua_server_get_stats(lua_State *L)
 
 }
 
+int hlua_server_get_proxy(lua_State *L)
+{
+       struct server *srv;
+
+       srv = hlua_check_server(L, 1);
+       if (srv == NULL) {
+               lua_pushnil(L);
+               return 1;
+       }
+
+       if (!srv->proxy) {
+               lua_pushnil(L);
+               return 1;
+       }
+
+       hlua_fcn_new_proxy(L, srv->proxy);
+       return 1;
+}
+
 int hlua_server_get_addr(lua_State *L)
 {
        struct server *srv;
@@ -1503,6 +1522,7 @@ int hlua_fcn_new_server(lua_State *L, struct server *srv)
        hlua_class_function(L, "set_addr", hlua_server_set_addr);
        hlua_class_function(L, "get_addr", hlua_server_get_addr);
        hlua_class_function(L, "get_stats", hlua_server_get_stats);
+       hlua_class_function(L, "get_proxy", hlua_server_get_proxy);
        hlua_class_function(L, "shut_sess", hlua_server_shut_sess);
        hlua_class_function(L, "set_drain", hlua_server_set_drain);
        hlua_class_function(L, "set_maint", hlua_server_set_maint);