MINOR: hlua_fcn: add Server.get_proxy()
Server.get_proxy(): get the proxy to which the server belongs
(or nil if not available)
diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index 042f231..fd3d47c 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -1233,6 +1233,14 @@
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
diff --git a/include/haproxy/hlua_fcn.h b/include/haproxy/hlua_fcn.h
index 8516514..ff9250a 100644
--- a/include/haproxy/hlua_fcn.h
+++ b/include/haproxy/hlua_fcn.h
@@ -34,6 +34,7 @@
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);
diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index 308e1d8..7150b0c 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -941,6 +941,25 @@
}
+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 @@
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);