MRS实例查询集群列表
引导式阅读
Python
MRS实例查询集群列表
作者
c***r
上架时间
2024-12-28 10:56:53

产品介绍

1.您可以在 API Explorer 中直接运行调试该接口。

2.在本样例中,您可以查询集群列表。

3.查看用户创建的集群列表信息。该接口不兼容Sahara。

前置条件

1.已 注册 华为云,并完成 实名认证

2.获取华为云开发工具包(SDK)。

3.已获取华为云账号对应的Access Key(AK)和Secret Access Key(SK)。请在华为云控制台“我的凭证 > 访问密钥”页面上创建和查看您的AK/SK。具体请参见 访问密钥

4.已具备开发环境,支持python3及以上版本。

5.已开通MRS服务。

6.使用服务端SDK前,您需要安装“huaweicloud-sdk-mrs”,具体的SDK版本号请参见SDK开发中心

pip install huaweicloudsdkmrs

代码示例

# coding: utf-8 # Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved. import logging import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmrs.v1 import MrsClient, ListClustersRequest if __name__ == "__main__": # 认证用的ak和sk直接写到代码中有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量CLOUD_SDK_AK和CLOUD_SDK_SK。 ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] logging.basicConfig(level=logging.NOTSET) credentials = BasicCredentials(ak, sk) client = MrsClient.new_builder() \ .with_credentials(credentials) \ .with_region(MrsRegion.value_of("cn-north-4")) \ .build() try: request = ListClustersRequest() # 每页的最大数量 request.page_size = "<PAGE SIZE>" # 当前查询页码 request.current_page = "<CURRENT PAGE>" response = client.list_clusters(request) logging.info(response) except exceptions.ClientRequestException as e: logging.error(e.status_code) logging.error(e.request_id) logging.error(e.error_code) logging.error(e.error_msg)

返回结果示例

{ "clusterTotal": 8, "clusters": [ { "clusterId": "6ef8fa22-95f5-*****-164863d3d545", "clusterName": "mrs_Vu9J", "totalNodeNum": "5", "clusterState": "运行中", "stageDesc": null, "stagePercent": null, "createAt": "1733477720", "updateAt": "1733710319", "chargingStartTime": "1733478231", "billingType": "按需付费", "dataCenter": "cn-north-4", "vpc": "vpc", "vpcId": "9bc19799-5cb9-*****-aa5bfff10979", "duration": "0", "fee": "0.0", "hadoopVersion": "", "componentList": [ { "id": "79***5", "componentId": "MRS 3.*.5_019", "componentName": "ZooKeeper", "componentVersion": "3.6.3", "external_datasources": null, "componentDesc": "Zookeeper是一个集中的服务,它用于维护配置信息、命名、提供分布式的同步和提供分组服务。", "componentDescEn": null, "multi_service_name": null, "multi_service_names": null }, { "id": "79***6", "componentId": "MRS 3.*.5_027", "componentName": "ClickHouse", "componentVersion": "21.3.4.25", "external_datasources": null, "componentDesc": "ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS)。", "componentDescEn": null, "multi_service_name": null, "multi_service_names": null } ], "externalIp": "214.**.**.178", "externalAlternateIp": "214.**.**.115", "internalIp": "192.**.**.174", "deploymentId": "6ef8fa22-95f5-*****-164863d3d545", "remark": "", "orderId": "MRS17****80VXeu", "azId": "15dcd3f78****ece9c5eb547", "azName": "可用区7", "azCode": "cn-north-4g", "availabilityZoneId": "cn-north-**", "multiAzDeployment": false, "arbitrationAzCode": "", "instanceId": "6ef8fa22-95f5-*****-164863d3d545", "vnc": "v2/16d59f309*****147e1441cd15/servers/eff8eb97-*****-93c8-ad7bd5d0815e/action", "tenantId": "16d59f309*****147e1441cd15", "volumeSize": 0, "supportRollingPatch": false, "volumeType": null, "subnetId": "5b5a21b5-c2ab-*****-ba92005df339", "subnetName": "subnet-guan", "securityGroupsId": "51b7d5e1-59b8-*****-1c383bc36e6b", "slaveSecurityGroupsId": "51b7d5e1-59b8-*****-1c383bc36e6b", "bootstrapScripts": null, "safeMode": 0, "clusterVersion": "MRS 3.1.5", "nodePublicCertName": "", "masterNodeIp": "192.**.**.174", "privateIpFirst": "192.**.**.188", "errorInfo": null, "tags": null, "clusterType": 3, "logCollection": 0, "periodType": null, "purchaseMode": null, "logUri": null, "isAffiliationRelativeTypeEnable": 0, "eipId": null, "eipAddress": null, "eipv6Address": null, "scale": "", "clusterProductId": null, "clusterSpecId": null, "clusterResourceId": null, "enterpriseProjectId": "336079ca-0842-*****-d9ca812795ef", "installedPatches": null, "dataVolumeEvsEncryptKmsKey": null, "sysVolumeEvsEncryptKmsKey": null, "authorizations": null, "decProject": false, "promotoionActivityId": null, "compositeProductId": null, "discountId": null, "mrsEcsDefaultAgency": "", "nodeTotal": 5, "securityAuthorize": 0, "isEdgeAz": false, "nodeScaleUpProgress": "0/0", "clusterVersionType": null, "ipv6Enable": null, "krb5SupportedEnctypes": null, "licenseVersion": "2", "controlScopes": null, "canResumeIgnoreFailedNodes": false, "canNotResumeIgnoreFailedNodesReason": null, "errorMessage": null, "domainId": "7046a839d8b*****9bc6f8b55644", "userName": "uname", "sccAlgorithm": null, "masterNodeNum": "3", "coreNodeNum": null, "masterNodeSize": "ac7.4xlarge.4.linux.bigdata", "coreNodeSize": null, "masterNodeProductId": "OFFI73*****602030080", "masterNodeSpecId": "ac7.4xlarge.*", "coreNodeProductId": null, "coreNodeSpecId": null, "masterDataVolumeType": "SSD", "masterDataVolumeSize": 200, "masterDataVolumeCount": 1, "coreDataVolumeType": null, "coreDataVolumeSize": 0, "coreDataVolumeCount": 0, "omsBusinessIp": null, "omsAlternateBusinessIp": null, "omsBusinessIpPort": "20029", "edgeAz": false, "mrsManagerFinish": false, "nodeGroups": [ { "periodic": false, "ccePodType": false, "SeqId": 42***7, "GroupName": "master_node_default_group", "clusterId": "6ef8fa22-95f5-*****-164863d3d545", "NodeNum": 3, "NodeSize": "ac7.4xlarge.4.linux.bigdata", "NodeSpecId": "ac7.4xlarge.*", "VmProductId": "OFFI7064*****66847504", "VmSpecCode": "ac7.4xlarge.4.linux", "NodeProductId": "OFFI73*****602030080", "RootVolumeSize": 100, "RootVolumeProductId": "00301-1****0-0--0", "RootVolumeType": "SSD", "RootVolumeResourceSpecCode": null, "RootVolumeResourceType": null, "DataVolumeType": "SSD", "DataVolumeCount": 1, "DataVolumeSize": 200, "DataVolumeProductId": "00301-1****0-0--0", "DataVolumeResourceSpecCode": null, "DataVolumeResourceType": null, "volumeDssClusterType": null, "volumeDssClusterId": null, "hypervisorType": null, "dccNodeSize": null, "dccNodeProductId": null, "NeedLvm": false, "serverGroupId": "7f3af286-5d69-*****-505f04b3615d", "AutoScalingPolicy": null, "BillingType": 12, "disabled": false, "cpuType": "X86", "assignedRoles": [ "OMSServer:1,2", "SlapdServer:1,2", "KerberosServer:1,2", "KerberosAdmin:1,2", "quorumpeer:1,2,3", "KerberosClient", "SlapdClient", "meta", "ClickHouseBalancer:1,2" ], "nodeType": "Master", "isSpotInstance": false, "spotPrice": null, "currency": null, "az_placement_expression": null, "instance_type": null, "cce_instance_info": null }, { "periodic": false, "ccePodType": false, "SeqId": 42***8, "GroupName": "ClickHouse", "clusterId": "6ef8fa22-95f5-*****-164863d3d545", "NodeNum": 2, "NodeSize": "ac7.4xlarge.4.linux.bigdata", "NodeSpecId": "ac7.4xlarge.*", "VmProductId": "OFFI7064*****66847504", "VmSpecCode": "ac7.4xlarge.4.linux", "NodeProductId": "OFFI73*****602030080", "RootVolumeSize": 100, "RootVolumeProductId": "00301-1****0-0--0", "RootVolumeType": "SSD", "RootVolumeResourceSpecCode": null, "RootVolumeResourceType": null, "DataVolumeType": "SSD", "DataVolumeCount": 1, "DataVolumeSize": 200, "DataVolumeProductId": "00301-1****0-0--0", "DataVolumeResourceSpecCode": null, "DataVolumeResourceType": null, "volumeDssClusterType": null, "volumeDssClusterId": null, "hypervisorType": null, "dccNodeSize": null, "dccNodeProductId": null, "NeedLvm": false, "serverGroupId": null, "AutoScalingPolicy": null, "BillingType": 12, "disabled": false, "cpuType": "X86", "assignedRoles": [ "ClickHouseServer", "meta", "KerberosClient", "SlapdClient" ], "nodeType": "Core", "isSpotInstance": false, "spotPrice": null, "currency": null, "az_placement_expression": null, "instance_type": null, "cce_instance_info": null } ], "elb_infos": null, "components_metadata": null, "taskNodeGroups": [ null ] } ] }

修订记录

发布日期 文档版本 修订说明
2024/12/9 1.0 文档首次发布