HA 节点获取

描述

integer/array hanode.get(object parameters)

该方法允许根据给定的参数检索一个高可用集群节点的列表。

这个方法只适用于AdminSuper admin用户类型。 前往用户角色以了解更多信息。

参数

(object) 参数定义所期望的输出。

该方法支持以下参数。

参数类型描述
ha_nodeidsstring/array只返回具有给定节点ID的节点。
filterobject只返回那些与给定过滤器完全匹配的结果。

接受一个数组,其中键是属性名称,而值是一个单一的值或一个数组的值来匹配。

允许通过节点属性进行过滤: nameaddressstatus.
sortfieldstring/array按给定的属性对结果进行排序。

可能的取值: namelastaccessstatus.
countOutputflag这些参数是所有 get 方法的共同参数,在参考注释中详细描述。
limitinteger
outputquery
preservekeysboolean
sortorderstring/array

返回值

返回 (integer/array) 其中之一:

  • 一个对象的数组;
  • 如果使用了 countOutput 参数,则为检索到的对象的数量。

示例

获取一个按状态排序的节点列表

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hanode.get",
  4. "params": {
  5. "preservekeys": true,
  6. "sortfield": "status",
  7. "sortorder": "DESC"
  8. },
  9. "auth": "3a57200802b24cda67c4e4010b50c065",
  10. "id": 1
  11. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "ckuo7i1nw000h0sajj3l3hh8u": {
  5. "ha_nodeid": "ckuo7i1nw000h0sajj3l3hh8u",
  6. "name": "node-active",
  7. "address": "192.168.1.13",
  8. "port": "10051",
  9. "lastaccess": "1635335704",
  10. "status": "3"
  11. },
  12. "ckuo7i1nw000e0sajwfttc1mp": {
  13. "ha_nodeid": "ckuo7i1nw000e0sajwfttc1mp",
  14. "name": "node6",
  15. "address": "192.168.1.10",
  16. "port": "10053",
  17. "lastaccess": "1635332902",
  18. "status": "2"
  19. },
  20. "ckuo7i1nv000c0sajz85xcrtt": {
  21. "ha_nodeid": "ckuo7i1nv000c0sajz85xcrtt",
  22. "name": "node4",
  23. "address": "192.168.1.8",
  24. "port": "10052",
  25. "lastaccess": "1635334214",
  26. "status": "1"
  27. },
  28. "ckuo7i1nv000a0saj1fcdkeu4": {
  29. "ha_nodeid": "ckuo7i1nv000a0saj1fcdkeu4",
  30. "name": "node2",
  31. "address": "192.168.1.6",
  32. "port": "10051",
  33. "lastaccess": "1635335705",
  34. "status": "0"
  35. }
  36. },
  37. "id": 1
  38. }

通过节点ID获取特定节点的列表

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hanode.get",
  4. "params": {
  5. "ha_nodeids": ["ckuo7i1nw000e0sajwfttc1mp", "ckuo7i1nv000c0sajz85xcrtt"]
  6. },
  7. "auth": "3a57200802b24cda67c4e4010b50c065",
  8. "id": 1
  9. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "ha_nodeid": "ckuo7i1nv000c0sajz85xcrtt",
  6. "name": "node4",
  7. "address": "192.168.1.8",
  8. "port": "10052",
  9. "lastaccess": "1635334214",
  10. "status": "1"
  11. },
  12. {
  13. "ha_nodeid": "ckuo7i1nw000e0sajwfttc1mp",
  14. "name": "node6",
  15. "address": "192.168.1.10",
  16. "port": "10053",
  17. "lastaccess": "1635332902",
  18. "status": "2"
  19. }
  20. ],
  21. "id": 1
  22. }

获得一个停用的节点列表

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hanode.get",
  4. "params": {
  5. "output": ["ha_nodeid", "address", "port"],
  6. "filter": {
  7. "status": 1
  8. }
  9. },
  10. "auth": "3a57200802b24cda67c4e4010b50c065",
  11. "id": 1
  12. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "ha_nodeid": "ckuo7i1nw000g0sajjsjre7e3",
  6. "address": "192.168.1.12",
  7. "port": "10051"
  8. },
  9. {
  10. "ha_nodeid": "ckuo7i1nv000c0sajz85xcrtt",
  11. "address": "192.168.1.8",
  12. "port": "10052"
  13. },
  14. {
  15. "ha_nodeid": "ckuo7i1nv000d0sajd95y1b6x",
  16. "address": "192.168.1.9",
  17. "port": "10053"
  18. }
  19. ],
  20. "id": 1
  21. }

获取备用节点的数量

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hanode.get",
  4. "params": {
  5. "countOutput": true,
  6. "filter": {
  7. "status": 0
  8. }
  9. },
  10. "auth": "3a57200802b24cda67c4e4010b50c065",
  11. "id": 1
  12. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": "3",
  4. "id": 1
  5. }

检查特定IP地址的节点的状态

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hanode.get",
  4. "params": {
  5. "output": ["name", "status"],
  6. "filter": {
  7. "address": ["192.168.1.7", "192.168.1.13"]
  8. }
  9. },
  10. "auth": "3a57200802b24cda67c4e4010b50c065",
  11. "id": 1
  12. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "name": "node3",
  6. "status": "0"
  7. },
  8. {
  9. "name": "node-active",
  10. "status": "3"
  11. }
  12. ],
  13. "id": 1
  14. }

来源

ui/include/classes/api/services/CHaNode.php 的 CHaNode::get()。