MINOR: hlua_fcn: add server->get_rid() method
Server revision ID was recently added to haproxy with 61e3894
("MINOR: server: add srv->rid (revision id) value")
Let's add it to the hlua server class.
diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index e20042d..146c050 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -1042,6 +1042,17 @@
Returns the proxy unique identifier of the server.
+.. js:function:: Server.get_rid(sv)
+
+ Returns the rid (revision ID) of the server.
+ It is an unsigned integer that is set upon server creation. Value is derived
+ from a global counter that starts at 0 and is incremented each time one or
+ multiple server deletions are followed by a server addition (meaning that
+ old name/id reuse could occur).
+
+ Combining server name/id with server rid yields a process-wide unique
+ identifier.
+
.. 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 ff90321..5f96f5c 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -990,6 +990,22 @@
return 1;
}
+int hlua_server_get_rid(lua_State *L)
+{
+ struct server *srv;
+ char buffer[12];
+
+ srv = hlua_check_server(L, 1);
+ if (srv == NULL) {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ snprintf(buffer, sizeof(buffer), "%d", srv->rid);
+ lua_pushstring(L, buffer);
+ return 1;
+}
+
int hlua_server_get_name(lua_State *L)
{
struct server *srv;
@@ -1373,6 +1389,7 @@
/* set public methods */
hlua_class_function(L, "get_name", hlua_server_get_name);
hlua_class_function(L, "get_puid", hlua_server_get_puid);
+ hlua_class_function(L, "get_rid", hlua_server_get_rid);
hlua_class_function(L, "is_draining", hlua_server_is_draining);
hlua_class_function(L, "set_maxconn", hlua_server_set_maxconn);
hlua_class_function(L, "get_maxconn", hlua_server_get_maxconn);