创建数据库实例
功能介绍
创建云数据库TaurusDB实例。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/instances
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 租户在某一Region下的project ID。 获取方法请参见获取项目ID。 约束限制: 不涉及。 取值范围: 只能由英文字母、数字组成,且长度为32个字符。 默认取值: 不涉及。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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。 取值范围: 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个只读节点。 取值范围: 1-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-11:00~+12:00内的所有整点时间。 默认取值: UTC。 |
master_availability_zone |
否 |
String |
参数解释: 主可用区ID。 约束限制: 创建单可用区实例选填,多可用区实例必填。 取值范围: 请参考地区和终端节点。 默认取值: 不涉及。 |
volume |
否 |
MysqlVolume object |
参数解释: volume信息。 约束限制: 创建包年/包月实例可选。创建按需实例时不可选。 |
tags |
否 |
Array of MysqlTags objects |
参数解释: 标签列表,根据标签键值对创建实例。 约束限制: 如果创建实例时同时使用多个标签键值对,中间使用逗号分隔开,最多包含20组。 |
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。 取值范围: gaussdb-mysql。 默认取值: 不涉及。 |
version |
是 |
String |
参数解释: 数据库版本。 约束限制: 不涉及。 取值范围: 两位数的大版本号,获取方法请参见查询数据库引擎的版本返回的name字段。 默认取值: 不涉及。 |
kernel_version |
否 |
String |
参数解释: 内核数据库版本。如果需要指定具体的内核版本,请联系客服人员添加白名单。 约束限制: 不涉及。 取值范围 完整的四位内核数据库版本,获取方法请参见查询数据库引擎的版本返回的kernel_version字段。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
charge_mode |
是 |
String |
参数解释: 计费模式。 约束限制: 不涉及。 取值范围: 默认取值: postPaid。 |
period_type |
否 |
String |
参数解释: 包周期付费模式下的订购周期类型。 约束限制: charge_mode为prePaid时生效,且为必选值。 取值范围: 默认取值: 不涉及。 |
period_num |
否 |
Integer |
参数解释: 包周期付费模式下的订购时间。 约束限制: charge_mode为prePaid时生效,且为必选值。 取值范围: 默认取值: 不涉及。 |
is_auto_renew |
否 |
String |
参数解释: 创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。 约束限制: charge_mode为prePaid时生效。 取值范围: 默认取值: false。 |
is_auto_pay |
否 |
String |
参数解释: 创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。 约束限制: charge_mode为prePaid时生效。 取值范围: 默认取值: true。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
start_time |
是 |
String |
参数解释: 自动备份开始时间段。自动备份将在该时间一个小时内触发。 约束限制: 不涉及。 取值范围: 非空,格式必须为hh:mm-HH:MM且有效,当前时间指UTC时间。 默认取值: 不涉及。 |
keep_days |
否 |
String |
参数解释: 自动备份保留天数。 约束限制: 值为正整数。 取值范围: 1-732。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
size |
是 |
String |
参数解释: 磁盘大小,单位GB。 约束限制: 必须为10的整数倍。 取值范围: 10-128000。 默认取值: 10。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
key |
是 |
String |
参数解释: 标签键。 约束限制: key不能为空或者空字符串,不能为空格。 取值范围: 最大长度36个unicode字符。字符集:A-Z,a-z ,0-9,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)。 默认取值: 不涉及。 |
value |
是 |
String |
参数解释: 标签值。 约束限制: 可以为空字符串。 取值范围: 最大长度43个unicode字符。字符集:A-Z,a-z ,0-9,‘-’,‘_’,UNICODE字符(\u4E00-\u9FFF)。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
source_instance_id |
是 |
String |
参数解释: 源实例ID。 约束限制: 不涉及。 取值范围: 只能由英文字母、数字组成,后缀为in07,长度为36个字符。 默认取值: 不涉及。 |
restore_time |
否 |
Long |
参数解释: 需要恢复的备份时间点。 约束限制: 格式为UNIX时间戳,单位是毫秒,时区为UTC标准时区。传参时需要将对应时区的时间转为标准时区对应的时间戳,比如,北京时区的时间点需要-8h后再转为时间戳。 取值范围: 通过查询可恢复时间段获取。 默认取值: 不涉及。 |
backup_id |
否 |
String |
参数解释: 备份文件ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
type |
否 |
String |
参数解释: 备份类型。 约束限制: 当参数为空时,backup_id不能为空,即默认按备份文件恢复 取值范围: 当参数不为空时,取值范围: 默认取值: 不涉及。 |
响应参数
状态码:201
参数 |
参数类型 |
描述 |
---|---|---|
instance |
MysqlInstanceResponse object |
参数解释: 实例信息。 |
job_id |
String |
参数解释 实例创建的任务ID。 仅创建按需实例时会返回该参数。 取值范围: 不涉及。 |
order_id |
String |
参数解释: 订单号,创建包年包月时返回该参数。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
参数解释: 实例ID。 取值范围: 只能由英文字母、数字组成,后缀为in07,长度为36个字符。 |
name |
String |
参数解释: 实例名称。 取值范围: 与请求参数中的实例名称一致。 |
status |
String |
参数解释: 实例状态。 取值范围: 不涉及。 |
datastore |
MysqlDatastoreInRes object |
参数解释: 数据库信息。 |
mode |
String |
参数解释: 实例模式。 取值范围: 与请求参数中的实例模式一致。 |
configuration_id |
String |
参数解释: 参数组ID。 取值范围: 不涉及。 |
port |
String |
参数解释: 数据库端口信息。 取值范围: 不涉及。 |
backup_strategy |
MysqlBackupStrategy object |
参数解释: 自动备份策略。 约束限制: 不涉及。 |
enterprise_project_id |
String |
参数解释: 企业项目ID。 取值范围: 和请求参数中的企业项目ID保持一致。 |
region |
String |
参数解释: 区域ID。 取值范围: 与请求参数中的区域ID一致。 |
availability_zone_mode |
String |
参数解释: 可用区模式。 取值范围: 与请求参数中的可用区模式一致。 |
master_availability_zone |
String |
参数解释: 主可用区ID。 取值范围: 与请求参数中的主可用区ID一致。 |
vpc_id |
String |
参数解释: 虚拟私有云ID,与请求参数相同。 取值范围: 与请求参数中的虚拟私有云ID一致。 |
security_group_id |
String |
参数解释: 安全组ID,与请求参数相同。 取值范围: 与请求参数中的安全组ID一致。 |
subnet_id |
String |
参数解释: 子网ID,与请求参数相同。 取值范围: 与请求参数中的子网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 |
参数解释: 计费模式。 约束限制: 不涉及。 取值范围: 默认取值: postPaid。 |
period_type |
String |
参数解释: 包周期付费模式下的订购周期类型。 约束限制: charge_mode为prePaid时生效,且为必选值。 取值范围: 默认取值: 不涉及。 |
period_num |
Integer |
参数解释: 包周期付费模式下的订购时间。 约束限制: charge_mode为prePaid时生效,且为必选值。 取值范围: 默认取值: 不涉及。 |
is_auto_renew |
String |
参数解释: 创建包年/包月实例时可指定,表示是否自动续订,续订的周期和原周期相同,且续订时会自动支付。 约束限制: charge_mode为prePaid时生效。 取值范围: 默认取值: false。 |
is_auto_pay |
String |
参数解释: 创建包年/包月实例时可指定,表示是否自动从客户的账户中支付,此字段不影响自动续订的支付方式。 约束限制: charge_mode为prePaid时生效。 取值范围: 默认取值: true。 |
状态码: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代码示例。
-
创建计费模式为按需计费,自动备份开始时间是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. |
错误码
请参见错误码。