hanode.get

描述

integer/array hanode.get(object parameters)

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

此方法仅适用于超级管理员用户类型 更多信息请参阅User roles

参数

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

该方法支持以下参数.

参数 数据类型 描述
ha_nodeids string/array 仅返回具有指定节点ID的节点.
filter object 仅返回完全匹配给定过滤条件的结果.

接受一个array, 其中键为属性名称, 值为要匹配的单个值或array值集合.

允许通过以下节点属性进行过滤: name, address, status.
sortfield string/array 按指定属性对结果进行排序.

可能的值为: name, lastaccess, status.
countOutput flag 这些参数在通用get方法参数中有描述.
limit integer
output query
preservekeys boolean
sortorder string/array

返回值

(integer/array) 返回以下两种情况之一:

  • 一个包含array的objects数组
  • 检索到的objects数量(当使用了countOutput参数时)

示例

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

请求:

{
    "jsonrpc": "2.0",
    "method": "hanode.get",
    "params": {
        "preservekeys": true,
        "sortfield": "status",
        "sortorder": "DESC"
    },
    "auth": "3a57200802b24cda67c4e4010b50c065",
    "id": 1
}

响应:

{
  "jsonrpc": "2.0",
  "result": {
    "ckuo7i1nw000h0sajj3l3hh8u": {
      "ha_nodeid": "ckuo7i1nw000h0sajj3l3hh8u",
      "name": "node-active",
      "address": "192.168.1.13",
      "port": "10051",
      "lastaccess": "1635335704",
      "status": "3"
    },
    "ckuo7i1nw000e0sajwfttc1mp": {
      "ha_nodeid": "ckuo7i1nw000e0sajwfttc1mp",
      "name": "node6",
      "address": "192.168.1.10",
      "port": "10053",
      "lastaccess": "1635332902",
      "status": "2"
    },
    "ckuo7i1nv000c0sajz85xcrtt": {
      "ha_nodeid": "ckuo7i1nv000c0sajz85xcrtt",
      "name": "node4",
      "address": "192.168.1.8",
      "port": "10052",
      "lastaccess": "1635334214",
      "status": "1"
    },
    "ckuo7i1nv000a0saj1fcdkeu4": {
      "ha_nodeid": "ckuo7i1nv000a0saj1fcdkeu4",
      "name": "node2",
      "address": "192.168.1.6",
      "port": "10051",
      "lastaccess": "1635335705",
      "status": "0"
    }
  },
  "id": 1
}

按节点ID获取特定节点列表

请求:

{
    "jsonrpc": "2.0",
    "method": "hanode.get",
    "params": {
        "ha_nodeids": ["ckuo7i1nw000e0sajwfttc1mp", "ckuo7i1nv000c0sajz85xcrtt"]
    },
    "auth": "3a57200802b24cda67c4e4010b50c065",
    "id": 1
}

响应:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "ha_nodeid": "ckuo7i1nv000c0sajz85xcrtt",
            "name": "node4",
            "address": "192.168.1.8",
            "port": "10052",
            "lastaccess": "1635334214",
            "status": "1"
        },
        {
            "ha_nodeid": "ckuo7i1nw000e0sajwfttc1mp",
            "name": "node6",
            "address": "192.168.1.10",
            "port": "10053",
            "lastaccess": "1635332902",
            "status": "2"
        }
    ],
    "id": 1
}

获取已停止节点列表

请求:

{
    "jsonrpc": "2.0",
    "method": "hanode.get",
    "params": {
        "output": ["ha_nodeid", "address", "port"],
        "filter": {
            "status": 1
        }
    },
    "auth": "3a57200802b24cda67c4e4010b50c065",
    "id": 1
}

响应:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "ha_nodeid": "ckuo7i1nw000g0sajjsjre7e3",
            "address": "192.168.1.12",
            "port": "10051"
        },
        {
            "ha_nodeid": "ckuo7i1nv000c0sajz85xcrtt",
            "address": "192.168.1.8",
            "port": "10052"
        },
        {
            "ha_nodeid": "ckuo7i1nv000d0sajd95y1b6x",
            "address": "192.168.1.9",
            "port": "10053"
        }
    ],
    "id": 1
}

获取备用节点数量

请求:

{
    "jsonrpc": "2.0",
    "method": "hanode.get",
    "params": {
        "countOutput": true,
        "filter": {
            "status": 0
        }
    },
    "auth": "3a57200802b24cda67c4e4010b50c065",
    "id": 1
}

响应:

{
    "jsonrpc": "2.0",
    "result": "3",
    "id": 1
}

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

请求:

{
    "jsonrpc": "2.0",
    "method": "hanode.get",
    "params": {
        "output": ["name", "status"],
        "filter": {
            "address": ["192.168.1.7", "192.168.1.13"]
        }
    },
    "auth": "3a57200802b24cda67c4e4010b50c065",
    "id": 1
}

响应:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "name": "node3",
            "status": "0"
        },
        {
            "name": "node-active",
            "status": "3"
        }
    ],
    "id": 1
}

来源

CHaNode::get() 位于 ui/include/classes/api/services/CHaNode.php 文件中。