创建集群
功能介绍
创建集群接口。
调用方法
请参见如何调用API。
URI
POST /v1.1/{project_id}/clusters
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方法请参见项目ID和账号ID |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
X-Language |
是 |
String |
请求语言。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
cluster |
是 |
cluster object |
集群对象,请参见cluster参数说明。 |
auto_remind |
否 |
Boolean |
选择是否开启消息通知。开启后,支持配置5个手机号码或邮箱,作业(目前仅支持表/文件迁移的作业)失败时、EIP异常时会发送短信或邮件通知用。 |
phone_num |
否 |
String |
接收消息通知的手机号码 |
否 |
String |
接收消息通知的邮箱 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
scheduleBootTime |
否 |
String |
定时开机的时间,CDM集群会在每天这个时间开机。 |
isScheduleBootOff |
否 |
Boolean |
选择是否启用定时开关机功能。定时开关机功能和自动关机功能不可同时开启。 |
instances |
否 |
Array of instance objects |
节点列表,请参见instances参数说明。 |
datastore |
否 |
Datastore object |
集群信息,请参见•datastore参数说明。 |
extended_properties |
否 |
ExtendedProperties object |
扩展属性,请参见•extended_properties参数说明。 |
scheduleOffTime |
否 |
String |
定时关机的时间,定时关机时系统不会等待未完成的作业执行完成。 |
vpcId |
否 |
String |
指定虚拟私有云ID,用于集群网络配置。 |
name |
否 |
String |
集群名称 |
sys_tags |
否 |
Array of sys_tags objects |
企业项目信息,请参见•sys_tags参数说明。 |
isAutoOff |
否 |
Boolean |
选择是否启用自动关机功能,自动关机功能和定时开关机功能不可同时开启。如果选择自动关机,则当集群中无作业运行且无定时作业时,等待15分钟后集群将自动关机来帮您节约成本 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
availability_zone |
是 |
String |
集群的可用分区。可通过https://developer.huaweicloud.com/intl/zh-cn/endpoint获取 |
nics |
是 |
Array of nics objects |
网卡列表,最多两个网卡。请参见•nics参数说明 |
flavorRef |
是 |
String |
实例规格:
|
type |
是 |
String |
节点类型,当前只有“cdm”一种类型 |
响应参数
状态码: 202
参数 |
参数类型 |
描述 |
---|---|---|
name |
String |
集群名称 |
id |
String |
集群ID |
task |
Task object |
任务信息 |
datastore |
Datastore object |
集群信息 |
instances |
Array of ClusterInstance objects |
集群的节点信息 |
请求示例
创建一个1.8.10版本,集群名为cdm-ab82的CDM集群。
POST /v1.1/1551c7f6c808414d8e9f3c514a170f2e/clusters { "cluster" : { "scheduleBootTime" : "", "isScheduleBootOff" : false, "instances" : [ { "availability_zone" : "xx-xxx", "nics" : [ { "securityGroupId" : "c37852d2-2d12-41cb-af47-65c80e995c80", "net-id" : "2d120298-6130-44d4-a438-454912fff901" } ], "flavorRef" : "5ddb1071-c5d7-40e0-a874-8a032e81a697", "type" : "cdm" } ], "datastore" : { "type" : "cdm", "version" : "1.8.10" }, "scheduleOffTime" : "", "vpcId" : "67c06084-2212-4242-bcd4-d2144c2385a9", "name" : "cdm-ab82", "sys_tags" : [ { "value" : "1ce45885-4033-40d2-bdde-d4dbaceb387d", "key" : "_sys_enterprise_project_id" } ], "isAutoOff" : false }, "auto_remind" : false, "phone_num" : "", "email" : "" }
响应示例
状态码: 202
Accepted
{ "id" : "befc862c-9286-46a0-a1d6-300d98b63aad", "name" : "cdm-4ef213", "task" : { "id" : "2c9080047f1b1185017f1ef6ad0500ac", "name" : "rdsCreateBackupJob" }, "datastore" : { "type" : "cdm", "version" : "2.9.1.100" }, "instances" : [ { "id" : "b2672e7d-2faf-423f-96bb-0664cd743cfd", "name" : "cdm-4ef213-cdm-dn-1-1", "type" : "cdm", "shard_id" : "dn-1" } ] }
SDK代码示例
SDK代码示例如下。
创建一个1.8.10版本,集群名为cdm-ab82的CDM集群。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.cdm.v1.region.cdmRegion; import com.huaweicloud.sdk.cdm.v1.*; import com.huaweicloud.sdk.cdm.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreateClusterSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); cdmClient client = cdmClient.newBuilder() .withCredential(auth) .withRegion(cdmRegion.valueOf("<YOUR REGION>")) .build(); CreateClusterRequest request = new CreateClusterRequest(); CdmCreateClusterReq body = new CdmCreateClusterReq(); List<SysTags> listClusterSysTags = new ArrayList<>(); listClusterSysTags.add( new SysTags() .withValue("1ce45885-4033-40d2-bdde-d4dbaceb387d") .withKey("_sys_enterprise_project_id") ); Datastore datastoreCluster = new Datastore(); datastoreCluster.withType("cdm") .withVersion("1.8.10"); List<Nics> listInstancesNics = new ArrayList<>(); listInstancesNics.add( new Nics() .withSecurityGroupId("c37852d2-2d12-41cb-af47-65c80e995c80") .withNetId("2d120298-6130-44d4-a438-454912fff901") ); List<Instance> listClusterInstances = new ArrayList<>(); listClusterInstances.add( new Instance() .withAvailabilityZone("xx-xxx") .withNics(listInstancesNics) .withFlavorRef("5ddb1071-c5d7-40e0-a874-8a032e81a697") .withType("cdm") ); CdmCreateClusterReqCluster clusterbody = new CdmCreateClusterReqCluster(); clusterbody.withScheduleBootTime("") .withIsScheduleBootOff(false) .withInstances(listClusterInstances) .withDatastore(datastoreCluster) .withScheduleOffTime("") .withVpcId("67c06084-2212-4242-bcd4-d2144c2385a9") .withName("cdm-ab82") .withSysTags(listClusterSysTags) .withIsAutoOff(false); body.withEmail(""); body.withPhoneNum(""); body.withAutoRemind(false); body.withCluster(clusterbody); request.withBody(body); try { CreateClusterResponse response = client.createCluster(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
创建一个1.8.10版本,集群名为cdm-ab82的CDM集群。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkcdm.v1.region.cdm_region import cdmRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkcdm.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = __import__('os').getenv("CLOUD_SDK_AK") sk = __import__('os').getenv("CLOUD_SDK_SK") projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) \ client = cdmClient.new_builder() \ .with_credentials(credentials) \ .with_region(cdmRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateClusterRequest() listSysTagsCluster = [ SysTags( value="1ce45885-4033-40d2-bdde-d4dbaceb387d", key="_sys_enterprise_project_id" ) ] datastoreCluster = Datastore( type="cdm", version="1.8.10" ) listNicsInstances = [ Nics( security_group_id="c37852d2-2d12-41cb-af47-65c80e995c80", net_id="2d120298-6130-44d4-a438-454912fff901" ) ] listInstancesCluster = [ Instance( availability_zone="xx-xxx", nics=listNicsInstances, flavor_ref="5ddb1071-c5d7-40e0-a874-8a032e81a697", type="cdm" ) ] clusterbody = CdmCreateClusterReqCluster( schedule_boot_time="", is_schedule_boot_off=False, instances=listInstancesCluster, datastore=datastoreCluster, schedule_off_time="", vpc_id="67c06084-2212-4242-bcd4-d2144c2385a9", name="cdm-ab82", sys_tags=listSysTagsCluster, is_auto_off=False ) request.body = CdmCreateClusterReq( email="", phone_num="", auto_remind=False, cluster=clusterbody ) response = client.create_cluster(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
创建一个1.8.10版本,集群名为cdm-ab82的CDM集群。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" cdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cdm.NewcdmClient( cdm.cdmClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateClusterRequest{} var listSysTagsCluster = []model.SysTags{ { Value: "1ce45885-4033-40d2-bdde-d4dbaceb387d", Key: "_sys_enterprise_project_id", }, } typeDatastore:= "cdm" versionDatastore:= "1.8.10" datastoreCluster := &model.Datastore{ Type: &typeDatastore, Version: &versionDatastore, } var listNicsInstances = []model.Nics{ { SecurityGroupId: "c37852d2-2d12-41cb-af47-65c80e995c80", NetId: "2d120298-6130-44d4-a438-454912fff901", }, } var listInstancesCluster = []model.Instance{ { AvailabilityZone: "xx-xxx", Nics: listNicsInstances, FlavorRef: "5ddb1071-c5d7-40e0-a874-8a032e81a697", Type: "cdm", }, } scheduleBootTimeCluster:= "" isScheduleBootOffCluster:= false scheduleOffTimeCluster:= "" vpcIdCluster:= "67c06084-2212-4242-bcd4-d2144c2385a9" nameCluster:= "cdm-ab82" isAutoOffCluster:= false clusterbody := &model.CdmCreateClusterReqCluster{ ScheduleBootTime: &scheduleBootTimeCluster, IsScheduleBootOff: &isScheduleBootOffCluster, Instances: &listInstancesCluster, Datastore: datastoreCluster, ScheduleOffTime: &scheduleOffTimeCluster, VpcId: &vpcIdCluster, Name: &nameCluster, SysTags: &listSysTagsCluster, IsAutoOff: &isAutoOffCluster, } emailCdmCreateClusterReq:= "" phoneNumCdmCreateClusterReq:= "" autoRemindCdmCreateClusterReq:= false request.Body = &model.CdmCreateClusterReq{ Email: &emailCdmCreateClusterReq, PhoneNum: &phoneNumCdmCreateClusterReq, AutoRemind: &autoRemindCdmCreateClusterReq, Cluster: clusterbody, } response, err := client.CreateCluster(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
202 |
Accepted |
400 |
请求错误 |
401 |
鉴权失败 |
403 |
没有操作权限 |
404 |
找不到资源 |
500 |
服务内部接口异常 |
503 |
服务不可用 |
错误码
请参见错误码。