创建数据库实例
功能介绍
创建云数据库GaussDB(for MySQL)实例。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/instances
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
租户在某一Region下的project ID。 获取方法请参见获取项目ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取。 请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。 |
X-Language |
否 |
String |
请求语言类型。默认en-us。 取值范围:
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
region |
是 |
String |
区域ID。 |
name |
是 |
String |
实例名称。用于表示实例的名称,同一租户下,同类型的实例名可重名。 取值范围:最小为4个字符,最大为64个字符且不超过64个字节(注意:一个中文字符占用3个字节),必须以字母或中文开头,区分大小写,可以包含字母、数字、中划线、下划线或中文,不能包含其他特殊字符。 |
datastore |
是 |
MysqlDatastoreInReq object |
数据库信息。 |
mode |
是 |
String |
实例类型,目前仅支持Cluster。 |
flavor_ref |
是 |
String |
规格码。使用可参考查询数据库规格响应消息表5中的“spec_code”。 |
vpc_id |
是 |
String |
虚拟私有云ID,获取方法如下:
|
subnet_id |
是 |
String |
子网的网络ID,获取方法如下:
|
password |
是 |
String |
数据库密码。 取值范围:至少包含以下字符的三种:大小写字母、数字和特殊符号|.~!@#$%^*-_=+?,()&,长度8~32个字符。 建议您输入高强度密码,以提高安全性,防止出现密码被暴力破解等安全风险。如果您输入弱密码,系统会自动判定密码非法。 |
availability_zone_mode |
是 |
String |
可用区类型。 取值范围:
|
slave_count |
是 |
Integer |
只读节点个数。单次接口调用最多支持创建9个只读节点。 |
charge_info |
否 |
MysqlChargeInfo object |
计费类型信息,支持包年包月和按需,默认为按需。 说明:DeC专属云账号不支持创建包年/包月实例。 |
security_group_id |
否 |
String |
安全组ID。如果实例所选用的子网开启网络ACL进行访问控制,则该参数非必选。如果未开启ACL进行访问控制,则该参数必选。获取方法如下:
|
configuration_id |
否 |
String |
参数模板ID。使用可参考查询参数模板中响应消息表5的“id”。 |
backup_strategy |
否 |
MysqlBackupStrategy object |
自动备份策略。 |
time_zone |
否 |
String |
时区。默认时区为UTC。 |
master_availability_zone |
否 |
String |
主可用区ID,请参考地区和终端节点。 |
volume |
否 |
MysqlVolume object |
volume信息。创建包年/包月实例可选。创建按需实例时不可选。 |
tags |
否 |
Array of MysqlTags objects |
标签列表,根据标签键值对创建实例。
如果创建实例时同时使用多个标签键值对,中间使用逗号分隔开,最多包含10组。 |
lower_case_table_names |
否 |
Integer |
表名大小写是否敏感,默认值是1。 取值范围:
|
enterprise_project_id |
否 |
String |
企业项目ID。如果账户开通企业项目服务则该参数必选,未开启该参数不可选。 |
dedicated_resource_id |
否 |
String |
专属资源池ID,只有开通专属资源池后才支持此参数。 |
restore_point |
否 |
MysqlRestorePoint object |
备份恢复信息。 |
tde_info |
否 |
MysqlTdeInfo object |
透明数据加密配置信息,支持AES256、SM4加密算法。 透明加密功能目前处于公测阶段,如需使用,请提交工单联系客服人员申请权限。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
数据库引擎,现在只支持gaussdb-mysql。 |
version |
是 |
String |
数据库版本。 两位数的大版本号,获取方法请参见查询数据库引擎的版本返回的name字段。 |
kernel_version |
否 |
String |
内核数据库版本。如果需要指定具体的内核版本,请联系客服人员添加白名单。 完整的四位内核数据库版本,获取方法请参见查询数据库引擎的版本返回的kernel_version字段。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
charge_mode |
是 |
String |
计费模式。 取值范围:
|
period_type |
否 |
String |
订购周期类型。 取值范围:
说明:“charge_mode”为“prePaid”时生效,且为必选值。 |
period_num |
否 |
Integer |
“charge_mode”为“prePaid”时生效,且为必选值,指定订购的时间。 取值范围:
|
is_auto_renew |
否 |
String |
创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。
|
is_auto_pay |
否 |
String |
创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
start_time |
是 |
String |
自动备份开始时间段。自动备份将在该时间一个小时内触发。 取值范围:非空,格式必须为hh:mm-HH:MM且有效,当前时间指UTC时间。
|
keep_days |
否 |
String |
自动备份保留天数,取值范围:1-732。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
标签键。最大长度36个unicode字符。key不能为空或者空字符串,不能为空格。 字符集:A-Z,a-z ,0-9,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)。 |
value |
是 |
String |
标签值。最大长度43个unicode字符。可以为空字符串。 字符集:A-Z,a-z ,0-9,‘.’,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)。 |
响应参数
状态码: 201
参数 |
参数类型 |
描述 |
---|---|---|
instance |
MysqlInstanceResponse object |
实例信息 |
job_id |
String |
实例创建的任务ID。 仅创建按需实例时会返回该参数。 |
order_id |
String |
订单号,创建包年包月时返回该参数。 |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
实例ID,严格匹配UUID规则。 |
name |
String |
实例名称。用于表示实例的名称。 |
status |
String |
实例状态。 |
datastore |
MysqlDatastoreInRes object |
数据库信息。 |
mode |
String |
实例类型,仅支持Cluster。 |
configuration_id |
String |
参数组ID。 |
port |
String |
数据库端口信息。 |
backup_strategy |
MysqlBackupStrategy object |
自动备份策略。 |
enterprise_project_id |
String |
企业项目ID。 |
region |
String |
区域ID,与请求参数相同。 |
availability_zone_mode |
String |
可用区模式,与请求参数相同。 |
master_availability_zone |
String |
主可用区ID。 |
vpc_id |
String |
虚拟私有云ID,与请求参数相同。 |
security_group_id |
String |
安全组ID,与请求参数相同。 |
subnet_id |
String |
子网ID,与请求参数相同。 |
flavor_ref |
String |
规格码,与请求参数相同。 |
charge_info |
MysqlChargeInfo object |
计费类型信息,支持包年包月和按需,默认为按需。 |
volume |
MysqlVolumeResp object |
volume信息。创建包年/包月实例有返回。 |
参数 |
参数类型 |
描述 |
---|---|---|
type |
String |
数据库引擎,现在只支持gaussdb-mysql。 |
version |
String |
数据库版本。 |
kernel_version |
String |
内核数据库版本。 |
参数 |
参数类型 |
描述 |
---|---|---|
start_time |
String |
自动备份开始时间段。自动备份将在该时间一个小时内触发。 取值范围:非空,格式必须为hh:mm-HH:MM且有效,当前时间指UTC时间。
|
keep_days |
String |
自动备份保留天数,取值范围:1-732。 |
参数 |
参数类型 |
描述 |
---|---|---|
charge_mode |
String |
计费模式。 取值范围:
|
period_type |
String |
订购周期类型。 取值范围:
说明:“charge_mode”为“prePaid”时生效,且为必选值。 |
period_num |
Integer |
“charge_mode”为“prePaid”时生效,且为必选值,指定订购的时间。 取值范围:
|
is_auto_renew |
String |
创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。
|
is_auto_pay |
String |
创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。
|
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
错误消息。 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
错误消息。 |
请求示例
-
创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。
POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances { "name" : "gaussdb-mysql-instance1", "region" : "br-iaas-odin1", "charge_info" : { "charge_mode" : "postPaid" }, "datastore" : { "type" : "gaussdb-mysql", "version" : "8.0" }, "mode" : "Cluster", "flavor_ref" : "gaussdb.mysql.xlarge.arm.4", "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58", "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad", "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55", "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07", "password" : "***", "backup_strategy" : { "start_time" : "08:00-09:00" }, "availability_zone_mode" : "single", "slave_count" : 1, "enterprise_project_id" : 0 }
-
将备份文件恢复到按需计费的新实例。
POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances { "name" : "gaussdb-mysql-instance2", "region" : "br-iaas-odin1", "charge_info" : { "charge_mode" : "postPaid" }, "datastore" : { "type" : "gaussdb-mysql", "version" : "8.0" }, "mode" : "Cluster", "flavor_ref" : "gaussdb.mysql.xlarge.arm.4", "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58", "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad", "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55", "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07", "password" : "***", "backup_strategy" : { "start_time" : "08:00-09:00" }, "availability_zone_mode" : "single", "slave_count" : 1, "enterprise_project_id" : 0, "restore_point" : { "source_instance_id" : "7033e7c3cf93438797d44ad7ae0a7d95in07", "backup_id" : "7ffbf305376b4cbea0ae491257b6aaf9br07", "type" : "backup" } }
-
按时间点恢复到按需计费的新实例。
POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances { "name" : "gaussdb-mysql-instance3", "region" : "br-iaas-odin1", "charge_info" : { "charge_mode" : "postPaid" }, "datastore" : { "type" : "gaussdb-mysql", "version" : "8.0" }, "mode" : "Cluster", "flavor_ref" : "gaussdb.mysql.xlarge.arm.4", "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58", "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad", "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55", "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07", "password" : "***", "backup_strategy" : { "start_time" : "08:00-09:00" }, "availability_zone_mode" : "single", "slave_count" : 1, "enterprise_project_id" : 0, "restore_point" : { "source_instance_id" : "7033e7c3cf93438797d44ad7ae0a7d95in07", "restore_time" : 1673852043000, "type" : "timestamp" } }
-
创建周期为一个月的包年/包月实例。
POST https://{endpoint}/v3/054e292c9880d4992f02c0196d3ea468/instances { "name" : "gaussdb-mysql-instance4", "region" : "br-iaas-odin1", "charge_info" : { "charge_mode" : "prePaid", "period_type" : "month", "period_num" : 1, "is_auto_renew" : false, "is_auto_pay" : true }, "volume" : { "size" : 10 }, "datastore" : { "type" : "gaussdb-mysql", "version" : "8.0" }, "mode" : "Cluster", "flavor_ref" : "gaussdb.mysql.xlarge.arm.4", "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58", "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad", "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55", "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07", "password" : "***", "backup_strategy" : { "start_time" : "08:00-09:00" }, "availability_zone_mode" : "single", "slave_count" : 1, "enterprise_project_id" : 0, "restore_point" : { "source_instance_id" : "7033e7c3cf93438797d44ad7ae0a7d95in07", "restore_time" : 1673852043000, "type" : "timestamp" } }
响应示例
状态码: 201
Success.
-
创建按需实例。
{ "instance" : { "id" : "5eebbb4c0f9f4a99b42ed1b6334569aain07", "name" : "gaussdb-mysql-instance1", "status" : "BUILD", "region" : "br-iaas-odin1", "charge_info" : { "charge_mode" : "postPaid" }, "datastore" : { "type" : "gaussdb-mysql", "version" : "8.0", "kernel_version" : "2.0.28.18" }, "mode" : "Cluster", "port" : 3306, "enterprise_project_id" : 0, "flavor_ref" : "gaussdb.mysql.xlarge.arm.4", "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58", "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad", "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55", "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07", "backup_strategy" : { "start_time" : "08:00-09:00", "keep_days" : 7 }, "availability_zone_mode" : "single" }, "job_id" : "dff1d289-4d03-4942-8b9f-463ea07c000d" }
-
创建周期为一个月的包年/包月实例。
{ "instance" : { "id" : "945419c2208e4a5d828b8dddc00223e1in07", "name" : "gaussdb-mysql-instance4", "status" : "BUILD", "region" : "br-iaas-odin1", "charge_info" : { "charge_mode" : "prePaid", "period_type" : "month", "period_num" : 1, "is_auto_renew" : false, "is_auto_pay" : true }, "volume" : { "size" : 10 }, "datastore" : { "type" : "gaussdb-mysql", "version" : "8.0", "kernel_version" : "2.0.28.18" }, "mode" : "Cluster", "port" : 3306, "enterprise_project_id" : 0, "flavor_ref" : "gaussdb.mysql.xlarge.arm.4", "vpc_id" : "3cedfc54-b105-4652-a4e0-847b11576b58", "subnet_id" : "c1cfa53c-65d3-431e-8552-326bf310c7ad", "security_group_id" : "fc577a1a-f202-424a-977f-24faec3fdd55", "configuration_id" : "43570e0de32e40c5a15f831aa5ce4176pr07", "backup_strategy" : { "start_time" : "08:00-09:00", "keep_days" : 7 }, "availability_zone_mode" : "single" }, "order_id" : "CS2308241236EEXVF" }
SDK代码示例
SDK代码示例如下。
-
创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。
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
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.gaussdb.v3.region.GaussDBRegion; import com.huaweicloud.sdk.gaussdb.v3.*; import com.huaweicloud.sdk.gaussdb.v3.model.*; public class CreateGaussMySqlInstanceSolution { 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); GaussDBClient client = GaussDBClient.newBuilder() .withCredential(auth) .withRegion(GaussDBRegion.valueOf("<YOUR REGION>")) .build(); CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest(); MysqlInstanceRequest body = new MysqlInstanceRequest(); MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy(); backupStrategybody.withStartTime("08:00-09:00"); MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq(); datastorebody.withType("gaussdb-mysql") .withVersion("8.0"); MysqlChargeInfo chargeInfobody = new MysqlChargeInfo(); chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("postPaid")); body.withEnterpriseProjectId("0"); body.withSlaveCount(1); body.withAvailabilityZoneMode("single"); body.withBackupStrategy(backupStrategybody); body.withPassword("***"); body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07"); body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55"); body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad"); body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58"); body.withFlavorRef("gaussdb.mysql.xlarge.arm.4"); body.withMode("Cluster"); body.withDatastore(datastorebody); body.withName("gaussdb-mysql-instance1"); body.withRegion("br-iaas-odin1"); body.withChargeInfo(chargeInfobody); request.withBody(body); try { CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(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 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
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.gaussdb.v3.region.GaussDBRegion; import com.huaweicloud.sdk.gaussdb.v3.*; import com.huaweicloud.sdk.gaussdb.v3.model.*; public class CreateGaussMySqlInstanceSolution { 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); GaussDBClient client = GaussDBClient.newBuilder() .withCredential(auth) .withRegion(GaussDBRegion.valueOf("<YOUR REGION>")) .build(); CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest(); MysqlInstanceRequest body = new MysqlInstanceRequest(); MysqlRestorePoint restorePointbody = new MysqlRestorePoint(); restorePointbody.withSourceInstanceId("7033e7c3cf93438797d44ad7ae0a7d95in07") .withBackupId("7ffbf305376b4cbea0ae491257b6aaf9br07") .withType("backup"); MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy(); backupStrategybody.withStartTime("08:00-09:00"); MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq(); datastorebody.withType("gaussdb-mysql") .withVersion("8.0"); MysqlChargeInfo chargeInfobody = new MysqlChargeInfo(); chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("postPaid")); body.withRestorePoint(restorePointbody); body.withEnterpriseProjectId("0"); body.withSlaveCount(1); body.withAvailabilityZoneMode("single"); body.withBackupStrategy(backupStrategybody); body.withPassword("***"); body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07"); body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55"); body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad"); body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58"); body.withFlavorRef("gaussdb.mysql.xlarge.arm.4"); body.withMode("Cluster"); body.withDatastore(datastorebody); body.withName("gaussdb-mysql-instance2"); body.withRegion("br-iaas-odin1"); body.withChargeInfo(chargeInfobody); request.withBody(body); try { CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(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 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
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.gaussdb.v3.region.GaussDBRegion; import com.huaweicloud.sdk.gaussdb.v3.*; import com.huaweicloud.sdk.gaussdb.v3.model.*; public class CreateGaussMySqlInstanceSolution { 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); GaussDBClient client = GaussDBClient.newBuilder() .withCredential(auth) .withRegion(GaussDBRegion.valueOf("<YOUR REGION>")) .build(); CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest(); MysqlInstanceRequest body = new MysqlInstanceRequest(); MysqlRestorePoint restorePointbody = new MysqlRestorePoint(); restorePointbody.withRestoreTime(1673852043000L) .withSourceInstanceId("7033e7c3cf93438797d44ad7ae0a7d95in07") .withType("timestamp"); MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy(); backupStrategybody.withStartTime("08:00-09:00"); MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq(); datastorebody.withType("gaussdb-mysql") .withVersion("8.0"); MysqlChargeInfo chargeInfobody = new MysqlChargeInfo(); chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("postPaid")); body.withRestorePoint(restorePointbody); body.withEnterpriseProjectId("0"); body.withSlaveCount(1); body.withAvailabilityZoneMode("single"); body.withBackupStrategy(backupStrategybody); body.withPassword("***"); body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07"); body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55"); body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad"); body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58"); body.withFlavorRef("gaussdb.mysql.xlarge.arm.4"); body.withMode("Cluster"); body.withDatastore(datastorebody); body.withName("gaussdb-mysql-instance3"); body.withRegion("br-iaas-odin1"); body.withChargeInfo(chargeInfobody); request.withBody(body); try { CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(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 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
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.gaussdb.v3.region.GaussDBRegion; import com.huaweicloud.sdk.gaussdb.v3.*; import com.huaweicloud.sdk.gaussdb.v3.model.*; public class CreateGaussMySqlInstanceSolution { 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); GaussDBClient client = GaussDBClient.newBuilder() .withCredential(auth) .withRegion(GaussDBRegion.valueOf("<YOUR REGION>")) .build(); CreateGaussMySqlInstanceRequest request = new CreateGaussMySqlInstanceRequest(); MysqlInstanceRequest body = new MysqlInstanceRequest(); MysqlRestorePoint restorePointbody = new MysqlRestorePoint(); restorePointbody.withRestoreTime(1673852043000L) .withSourceInstanceId("7033e7c3cf93438797d44ad7ae0a7d95in07") .withType("timestamp"); MysqlVolume volumebody = new MysqlVolume(); volumebody.withSize("10"); MysqlBackupStrategy backupStrategybody = new MysqlBackupStrategy(); backupStrategybody.withStartTime("08:00-09:00"); MysqlDatastoreInReq datastorebody = new MysqlDatastoreInReq(); datastorebody.withType("gaussdb-mysql") .withVersion("8.0"); MysqlChargeInfo chargeInfobody = new MysqlChargeInfo(); chargeInfobody.withChargeMode(MysqlChargeInfo.ChargeModeEnum.fromValue("prePaid")) .withPeriodType(MysqlChargeInfo.PeriodTypeEnum.fromValue("month")) .withPeriodNum(1) .withIsAutoRenew("false") .withIsAutoPay("true"); body.withRestorePoint(restorePointbody); body.withEnterpriseProjectId("0"); body.withVolume(volumebody); body.withSlaveCount(1); body.withAvailabilityZoneMode("single"); body.withBackupStrategy(backupStrategybody); body.withPassword("***"); body.withConfigurationId("43570e0de32e40c5a15f831aa5ce4176pr07"); body.withSecurityGroupId("fc577a1a-f202-424a-977f-24faec3fdd55"); body.withSubnetId("c1cfa53c-65d3-431e-8552-326bf310c7ad"); body.withVpcId("3cedfc54-b105-4652-a4e0-847b11576b58"); body.withFlavorRef("gaussdb.mysql.xlarge.arm.4"); body.withMode("Cluster"); body.withDatastore(datastorebody); body.withName("gaussdb-mysql-instance4"); body.withRegion("br-iaas-odin1"); body.withChargeInfo(chargeInfobody); request.withBody(body); try { CreateGaussMySqlInstanceResponse response = client.createGaussMySqlInstance(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()); } } }
-
创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。
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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkgaussdb.v3 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 = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = GaussDBClient.new_builder() \ .with_credentials(credentials) \ .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateGaussMySqlInstanceRequest() backupStrategybody = MysqlBackupStrategy( start_time="08:00-09:00" ) datastorebody = MysqlDatastoreInReq( type="gaussdb-mysql", version="8.0" ) chargeInfobody = MysqlChargeInfo( charge_mode="postPaid" ) request.body = MysqlInstanceRequest( enterprise_project_id="0", slave_count=1, availability_zone_mode="single", backup_strategy=backupStrategybody, password="***", configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07", security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55", subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad", vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58", flavor_ref="gaussdb.mysql.xlarge.arm.4", mode="Cluster", datastore=datastorebody, name="gaussdb-mysql-instance1", region="br-iaas-odin1", charge_info=chargeInfobody ) response = client.create_gauss_my_sql_instance(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 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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkgaussdb.v3 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 = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = GaussDBClient.new_builder() \ .with_credentials(credentials) \ .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateGaussMySqlInstanceRequest() restorePointbody = MysqlRestorePoint( source_instance_id="7033e7c3cf93438797d44ad7ae0a7d95in07", backup_id="7ffbf305376b4cbea0ae491257b6aaf9br07", type="backup" ) backupStrategybody = MysqlBackupStrategy( start_time="08:00-09:00" ) datastorebody = MysqlDatastoreInReq( type="gaussdb-mysql", version="8.0" ) chargeInfobody = MysqlChargeInfo( charge_mode="postPaid" ) request.body = MysqlInstanceRequest( restore_point=restorePointbody, enterprise_project_id="0", slave_count=1, availability_zone_mode="single", backup_strategy=backupStrategybody, password="***", configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07", security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55", subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad", vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58", flavor_ref="gaussdb.mysql.xlarge.arm.4", mode="Cluster", datastore=datastorebody, name="gaussdb-mysql-instance2", region="br-iaas-odin1", charge_info=chargeInfobody ) response = client.create_gauss_my_sql_instance(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 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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkgaussdb.v3 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 = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = GaussDBClient.new_builder() \ .with_credentials(credentials) \ .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateGaussMySqlInstanceRequest() restorePointbody = MysqlRestorePoint( restore_time=1673852043000, source_instance_id="7033e7c3cf93438797d44ad7ae0a7d95in07", type="timestamp" ) backupStrategybody = MysqlBackupStrategy( start_time="08:00-09:00" ) datastorebody = MysqlDatastoreInReq( type="gaussdb-mysql", version="8.0" ) chargeInfobody = MysqlChargeInfo( charge_mode="postPaid" ) request.body = MysqlInstanceRequest( restore_point=restorePointbody, enterprise_project_id="0", slave_count=1, availability_zone_mode="single", backup_strategy=backupStrategybody, password="***", configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07", security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55", subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad", vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58", flavor_ref="gaussdb.mysql.xlarge.arm.4", mode="Cluster", datastore=datastorebody, name="gaussdb-mysql-instance3", region="br-iaas-odin1", charge_info=chargeInfobody ) response = client.create_gauss_my_sql_instance(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 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
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkgaussdb.v3 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 = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = GaussDBClient.new_builder() \ .with_credentials(credentials) \ .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateGaussMySqlInstanceRequest() restorePointbody = MysqlRestorePoint( restore_time=1673852043000, source_instance_id="7033e7c3cf93438797d44ad7ae0a7d95in07", type="timestamp" ) volumebody = MysqlVolume( size="10" ) backupStrategybody = MysqlBackupStrategy( start_time="08:00-09:00" ) datastorebody = MysqlDatastoreInReq( type="gaussdb-mysql", version="8.0" ) chargeInfobody = MysqlChargeInfo( charge_mode="prePaid", period_type="month", period_num=1, is_auto_renew="false", is_auto_pay="true" ) request.body = MysqlInstanceRequest( restore_point=restorePointbody, enterprise_project_id="0", volume=volumebody, slave_count=1, availability_zone_mode="single", backup_strategy=backupStrategybody, password="***", configuration_id="43570e0de32e40c5a15f831aa5ce4176pr07", security_group_id="fc577a1a-f202-424a-977f-24faec3fdd55", subnet_id="c1cfa53c-65d3-431e-8552-326bf310c7ad", vpc_id="3cedfc54-b105-4652-a4e0-847b11576b58", flavor_ref="gaussdb.mysql.xlarge.arm.4", mode="Cluster", datastore=datastorebody, name="gaussdb-mysql-instance4", region="br-iaas-odin1", charge_info=chargeInfobody ) response = client.create_gauss_my_sql_instance(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
创建计费模式为按需计费,自动备份开始时间是08:00-09:00的实例。
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/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 := gaussdb.NewGaussDBClient( gaussdb.GaussDBClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateGaussMySqlInstanceRequest{} backupStrategybody := &model.MysqlBackupStrategy{ StartTime: "08:00-09:00", } datastorebody := &model.MysqlDatastoreInReq{ Type: "gaussdb-mysql", Version: "8.0", } chargeInfobody := &model.MysqlChargeInfo{ ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().POST_PAID, } enterpriseProjectIdMysqlInstanceRequest:= "0" configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07" securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55" request.Body = &model.MysqlInstanceRequest{ EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest, SlaveCount: int32(1), AvailabilityZoneMode: "single", BackupStrategy: backupStrategybody, Password: "***", ConfigurationId: &configurationIdMysqlInstanceRequest, SecurityGroupId: &securityGroupIdMysqlInstanceRequest, SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad", VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58", FlavorRef: "gaussdb.mysql.xlarge.arm.4", Mode: "Cluster", Datastore: datastorebody, Name: "gaussdb-mysql-instance1", Region: "br-iaas-odin1", ChargeInfo: chargeInfobody, } response, err := client.CreateGaussMySqlInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
将备份文件恢复到按需计费的新实例。
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/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 := gaussdb.NewGaussDBClient( gaussdb.GaussDBClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateGaussMySqlInstanceRequest{} backupIdRestorePoint:= "7ffbf305376b4cbea0ae491257b6aaf9br07" typeRestorePoint:= "backup" restorePointbody := &model.MysqlRestorePoint{ SourceInstanceId: "7033e7c3cf93438797d44ad7ae0a7d95in07", BackupId: &backupIdRestorePoint, Type: &typeRestorePoint, } backupStrategybody := &model.MysqlBackupStrategy{ StartTime: "08:00-09:00", } datastorebody := &model.MysqlDatastoreInReq{ Type: "gaussdb-mysql", Version: "8.0", } chargeInfobody := &model.MysqlChargeInfo{ ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().POST_PAID, } enterpriseProjectIdMysqlInstanceRequest:= "0" configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07" securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55" request.Body = &model.MysqlInstanceRequest{ RestorePoint: restorePointbody, EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest, SlaveCount: int32(1), AvailabilityZoneMode: "single", BackupStrategy: backupStrategybody, Password: "***", ConfigurationId: &configurationIdMysqlInstanceRequest, SecurityGroupId: &securityGroupIdMysqlInstanceRequest, SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad", VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58", FlavorRef: "gaussdb.mysql.xlarge.arm.4", Mode: "Cluster", Datastore: datastorebody, Name: "gaussdb-mysql-instance2", Region: "br-iaas-odin1", ChargeInfo: chargeInfobody, } response, err := client.CreateGaussMySqlInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
按时间点恢复到按需计费的新实例。
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/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 := gaussdb.NewGaussDBClient( gaussdb.GaussDBClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateGaussMySqlInstanceRequest{} restoreTimeRestorePoint:= int64(1673852043000) typeRestorePoint:= "timestamp" restorePointbody := &model.MysqlRestorePoint{ RestoreTime: &restoreTimeRestorePoint, SourceInstanceId: "7033e7c3cf93438797d44ad7ae0a7d95in07", Type: &typeRestorePoint, } backupStrategybody := &model.MysqlBackupStrategy{ StartTime: "08:00-09:00", } datastorebody := &model.MysqlDatastoreInReq{ Type: "gaussdb-mysql", Version: "8.0", } chargeInfobody := &model.MysqlChargeInfo{ ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().POST_PAID, } enterpriseProjectIdMysqlInstanceRequest:= "0" configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07" securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55" request.Body = &model.MysqlInstanceRequest{ RestorePoint: restorePointbody, EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest, SlaveCount: int32(1), AvailabilityZoneMode: "single", BackupStrategy: backupStrategybody, Password: "***", ConfigurationId: &configurationIdMysqlInstanceRequest, SecurityGroupId: &securityGroupIdMysqlInstanceRequest, SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad", VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58", FlavorRef: "gaussdb.mysql.xlarge.arm.4", Mode: "Cluster", Datastore: datastorebody, Name: "gaussdb-mysql-instance3", Region: "br-iaas-odin1", ChargeInfo: chargeInfobody, } response, err := client.CreateGaussMySqlInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
创建周期为一个月的包年/包月实例。
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
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/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 := gaussdb.NewGaussDBClient( gaussdb.GaussDBClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateGaussMySqlInstanceRequest{} restoreTimeRestorePoint:= int64(1673852043000) typeRestorePoint:= "timestamp" restorePointbody := &model.MysqlRestorePoint{ RestoreTime: &restoreTimeRestorePoint, SourceInstanceId: "7033e7c3cf93438797d44ad7ae0a7d95in07", Type: &typeRestorePoint, } volumebody := &model.MysqlVolume{ Size: "10", } backupStrategybody := &model.MysqlBackupStrategy{ StartTime: "08:00-09:00", } datastorebody := &model.MysqlDatastoreInReq{ Type: "gaussdb-mysql", Version: "8.0", } periodTypeChargeInfo:= model.GetMysqlChargeInfoPeriodTypeEnum().MONTH periodNumChargeInfo:= int32(1) isAutoRenewChargeInfo:= "false" isAutoPayChargeInfo:= "true" chargeInfobody := &model.MysqlChargeInfo{ ChargeMode: model.GetMysqlChargeInfoChargeModeEnum().PRE_PAID, PeriodType: &periodTypeChargeInfo, PeriodNum: &periodNumChargeInfo, IsAutoRenew: &isAutoRenewChargeInfo, IsAutoPay: &isAutoPayChargeInfo, } enterpriseProjectIdMysqlInstanceRequest:= "0" configurationIdMysqlInstanceRequest:= "43570e0de32e40c5a15f831aa5ce4176pr07" securityGroupIdMysqlInstanceRequest:= "fc577a1a-f202-424a-977f-24faec3fdd55" request.Body = &model.MysqlInstanceRequest{ RestorePoint: restorePointbody, EnterpriseProjectId: &enterpriseProjectIdMysqlInstanceRequest, Volume: volumebody, SlaveCount: int32(1), AvailabilityZoneMode: "single", BackupStrategy: backupStrategybody, Password: "***", ConfigurationId: &configurationIdMysqlInstanceRequest, SecurityGroupId: &securityGroupIdMysqlInstanceRequest, SubnetId: "c1cfa53c-65d3-431e-8552-326bf310c7ad", VpcId: "3cedfc54-b105-4652-a4e0-847b11576b58", FlavorRef: "gaussdb.mysql.xlarge.arm.4", Mode: "Cluster", Datastore: datastorebody, Name: "gaussdb-mysql-instance4", Region: "br-iaas-odin1", ChargeInfo: chargeInfobody, } response, err := client.CreateGaussMySqlInstance(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
201 |
Success. |
400 |
Client error. |
500 |
Server error. |
错误码
请参见错误码。