From: Patrick Hemmer Date: Sun, 29 Apr 2018 18:23:48 +0000 (-0400) Subject: MINOR: lua: Add server name & puid to LUA Server class. X-Git-Tag: v1.9-dev1~273 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a62ae7ed9a87bc4e620bc075e7ab2807a6b32582;p=thirdparty%2Fhaproxy.git MINOR: lua: Add server name & puid to LUA Server class. --- diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index 9b6d18f462..9a9e7ceef8 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -922,6 +922,14 @@ Server class This class provides a way for manipulating servers and retrieving information. +.. js:attribute:: Server.name + + Contain the name of the server. + +.. js:attribute:: Server.puid + + Contain the proxy unique identifier of the server. + .. js:function:: Server.is_draining(sv) Return true if the server is currently draining sticky connections. diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index a8d53d45b7..86e5c2c749 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -490,6 +490,8 @@ int hlua_listener_get_stats(lua_State *L) int hlua_fcn_new_server(lua_State *L, struct server *srv) { + char buffer[12]; + lua_newtable(L); /* Pop a class sesison metatable and affect it to the userdata. */ @@ -498,6 +500,18 @@ int hlua_fcn_new_server(lua_State *L, struct server *srv) lua_pushlightuserdata(L, srv); lua_rawseti(L, -2, 0); + + /* Add server name. */ + lua_pushstring(L, "name"); + lua_pushstring(L, srv->id); + lua_settable(L, -3); + + /* Add server puid. */ + lua_pushstring(L, "puid"); + snprintf(buffer, sizeof(buffer), "%d", srv->puid); + lua_pushstring(L, buffer); + lua_settable(L, -3); + return 1; }