1.功能介绍
查看指定集群的详细信息。该接口不兼容Sahara。
需要先在平台创建集群成功,然后再通过该接口查询集群详细信息。
所有示例中涉及的ID和AKSK,请提前准备并在提交请求时根据实际情况替换。
2.前置条件
1.已注册华为云,并完成实名认证
2.获取华为云开发工具包(SDK),您也可以查看安装Python SDK。
3.已获取华为云账号对应的Access Key(AK)和Secret Access Key(SK)。 请在华为云控制台“我的凭证 > 访问密钥”页面上创建和查看您的AK/SK。具体请参见 访问密钥 。
4.已获取华为云账号对应的project ID。请在华为云控制台“我的凭证 > api凭证”页面上查看您的project ID。具体请参见 api凭证 。
5.已获取对应的可用区ID。具体请参见 可用分区 。
6..已创建MapReduce服务集群。获取对应的集群ID,集群概览页“集群ID”。
7.已具备开发环境,支持Python3及以上版本。
3.代码示例
1.查询集群详细信息,更多参数请参考API参考
Copied!
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.exceptions.exceptions import ClientRequestException
from huaweicloudsdkcore.exceptions.exceptions import ServerResponseException
from huaweicloudsdkmrs.v1.mrs_client import MrsClient
from huaweicloudsdkmrs.v1.model.show_cluster_details_request import ShowClusterDetailsRequest
from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
import os
class ShowClusterDetails:
def __init__(self):
pass
@staticmethod
def main(args):
ak = os.environ["HUAWEICLOUD_SDK_AK"]
sk = os.environ["HUAWEICLOUD_SDK_SK"]
project_id = "{******your project id******}"
auth = BasicCredentials(
ak=ak,
sk=sk,
project_id=project_id
)
client = MrsClient.new_builder() \
.with_credentials(credentials=auth) \
.with_region(region=MrsRegion.value_of(region_id="{******region id******}")) \
.build()
request = ShowClusterDetailsRequest(
cluster_id="{******your cluster id******}"
)
try:
response = client.show_cluster_details(request)
print(str(response.http_status_code))
print(response)
except ClientRequestException as e:
print(e.status_code)
print(e)
except ServerResponseException as e:
print(e.status_code)
print(e)
if __name__ == "__main__":
ShowClusterDetails().main(any)
查询集群详细信息示例(Python版本)
0.版本说明
本示例基于华为云SDK开发
1.功能介绍
查看指定集群的详细信息。该接口不兼容Sahara。
需要先在平台创建集群成功,然后再通过该接口查询集群详细信息。
所有示例中涉及的ID和AKSK,请提前准备并在提交请求时根据实际情况替换。
2.前置条件
1.已注册华为云,并完成实名认证
2.获取华为云开发工具包(SDK),您也可以查看安装Python SDK。
3.已获取华为云账号对应的Access Key(AK)和Secret Access Key(SK)。 请在华为云控制台“我的凭证 > 访问密钥”页面上创建和查看您的AK/SK。具体请参见 访问密钥 。
4.已获取华为云账号对应的project ID。请在华为云控制台“我的凭证 > api凭证”页面上查看您的project ID。具体请参见 api凭证 。
5.已获取对应的可用区ID。具体请参见 可用分区 。
6..已创建MapReduce服务集群。获取对应的集群ID,集群概览页“集群ID”。
7.已具备开发环境,支持Python3及以上版本。
3.代码示例
1.查询集群详细信息,更多参数请参考API参考
from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcore.exceptions.exceptions import ClientRequestException from huaweicloudsdkcore.exceptions.exceptions import ServerResponseException from huaweicloudsdkmrs.v1.mrs_client import MrsClient from huaweicloudsdkmrs.v1.model.show_cluster_details_request import ShowClusterDetailsRequest from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion import os class ShowClusterDetails: def __init__(self): pass @staticmethod def main(args): # 基础认证信息: # ak: 华为云账号Access Key # sk: 华为云账号Secret Access Key # 认证用的ak和sk直接写到代码中有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全; # 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。 ak = os.environ["HUAWEICLOUD_SDK_AK"] sk = os.environ["HUAWEICLOUD_SDK_SK"] # projectId: 项目ID project_id = "{******your project id******}" # 1.初始化sdk auth = BasicCredentials( ak=ak, sk=sk, project_id=project_id ) # 2.创建MrsClient实例,regionId根据实际情况进行修改 client = MrsClient.new_builder() \ .with_credentials(credentials=auth) \ .with_region(region=MrsRegion.value_of(region_id="{******region id******}")) \ .build() # 3.创建请求,添加参数 request = ShowClusterDetailsRequest( cluster_id="{******your cluster id******}" ) # 4.查询集群详情 try: response = client.show_cluster_details(request) print(str(response.http_status_code)) print(response) except ClientRequestException as e: print(e.status_code) print(e) except ServerResponseException as e: print(e.status_code) print(e) if __name__ == "__main__": ShowClusterDetails().main(any)
4.参考
更多信息请参考APIExplorer
5.修订记录