Merge branch 'ryzom/rites' into main/gingo-test
[ryzomcore.git] / ryzom / server / tools / admin_modules_itf.py
blob249cc64a2cfadf67806a8e76c31377fe5ef3902b
1 import logging
2 from nel_message import *
5 class CAdminServiceWeb(CCallbackClient):
7 def globalCmd(self, command):
8 msg = CMessage()
9 msg.setName("GCMD")
10 msg.serialString(command)
11 return self.sendMessage(msg)
13 def controlCmd(self, serviceAlias, command):
14 msg = CMessage()
15 msg.setName("CCMD")
17 msg.serialString(serviceAlias)
18 msg.serialString(command)
20 return self.sendMessage(msg)
23 def serviceCmd(self, serviceAlias, command):
24 msg = CMessage()
25 msg.setName("SCMD")
27 msg.serialString(serviceAlias)
28 msg.serialString(command)
30 return self.sendMessage(msg)
32 def getShardOrders(self):
33 msg = CMessage()
34 msg.setName("GSO")
36 ret = ""
37 ret = sendMessage(msg)
38 if not ret:
39 print("getShardOrders: Error in 'sendMessage'")
40 return False
42 retMsg = waitMessage()
43 if not retMsg:
44 print("getShardOrders: Error in 'waitMessage'")
45 return False
47 if not retMsg.MsgName == "R_GSO":
48 print("getShardOrders: Invalid response, awaited 'R_GSO', received: "+retMsg.MsgName)
49 return False
51 nbElem = 0
52 retMsg.serialUInt32(nbElem)
53 retValue = []
54 for i in range(nbElem):
55 retMsg.serialString(item)
56 retValue.append(item)
58 return retValue
61 def waitCallback(self):
62 message = self.waitMessage()
64 if not message:
65 return False
67 if message.MsgName == "CMDR":
68 self.commandResult_skel(message)
69 else:
70 return False
71 return True
73 def commandResult_skel(self, message):
74 serviceAlias = message.serialString()
75 result = message.serialString()
76 self.commandResult(serviceAlias, result)
78 def commandResult(self, serviceAlias, result):
79 global command_return_data
80 command_return_data = result
84 def queryShard(service_name, fullcmd, waitCallback=True, is_control=False):
85 global command_return_data
87 nel_result = ""
88 nel_status = not waitCallback
89 res = ""
90 p_result = None
92 adminService = CAdminServiceWeb()
94 if adminService.connect("127.0.0.1", 46700, res):
95 command_return_data = ""
97 if isinstance(fullcmd, str):
98 if is_control:
99 adminService.controlCmd(service_name, fullcmd)
100 else:
101 adminService.serviceCmd(service_name, fullcmd)
102 service_command = fullcmd
104 if waitCallback and adminService.waitCallback():
105 nel_status = True
106 nel_result += command_return_data
107 else:
108 for service_command in fullcmd:
109 if is_control:
110 adminService.controlCmd(service_name, service_command)
111 else:
112 adminService.serviceCmd(service_name, service_command)
113 adminService.close()
115 return {"status": nel_status, "query": service_name+":"+fullcmd, "raw": nel_result.split("\n")[1:]}