云服务器内容精选

  • Go 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 main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" dbss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dbss/v1/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := dbss.NewDbssClient( dbss.DbssClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.CreateInstancesPeriodOrderRequest{} var listTagsbody = []model.KeyValueBean{ { Key: "key_test", Value: "1", }, } var listProductInfosbody = []model.CreateInstancePeriodRequestProductInfos{ { ProductId: "00301-225396-0--0", CloudServiceType: "hws.service.type.dbss", ResourceType: "hws.resource.type.dbss", ResourceSpecCode: "dbss.bypassaudit.low", ProductSpecDesc: "test", }, } var listSecurityGroupsbody = []model.CreateInstancePeriodRequestSecurityGroups{ { Id: "04088976-9c63-4e6b-9070-84e6a30c782b", }, } var listNicsbody = []model.CreateInstancePeriodRequestNics{ { SubnetId: "6201dcf2-1374-43ec-ae8b-78b4081572d3", }, } isAutoRenewCreateInstancePeriodRequest:= int32(0) promotionInfoCreateInstancePeriodRequest:= "" commentCreateInstancePeriodRequest:= "" request.Body = &model.CreateInstancePeriodRequest{ IsAutoRenew: &isAutoRenewCreateInstancePeriodRequest, PromotionInfo: &promotionInfoCreateInstancePeriodRequest, Tags: &listTagsbody, ProductInfos: listProductInfosbody, SubscriptionNum: int32(1), PeriodNum: int32(1), PeriodType: int32(2), ChargingMode: int32(0), CloudServiceType: "hws.service.type.dbss", Region: "cn-north-7", Comment: &commentCreateInstancePeriodRequest, SecurityGroups: listSecurityGroupsbody, Nics: listNicsbody, EnterpriseProjectId: "0", AvailabilityZone: "cn-north-7c", VpcId: "4c035747-f77b-4c6d-b23b-cb3a2b96c7e6", Name: "DBSS-acc3", FlavorRef: "st6.xlarge.4", } response, err := client.CreateInstancesPeriodOrder(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • Python 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkdbss.v1.region.dbss_region import DbssRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkdbss.v1 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = DbssClient.new_builder() \ .with_credentials(credentials) \ .with_region(DbssRegion.value_of("cn-north-4")) \ .build() try: request = CreateInstancesPeriodOrderRequest() listTagsbody = [ KeyValueBean( key="key_test", value="1" ) ] listProductInfosbody = [ CreateInstancePeriodRequestProductInfos( product_id="00301-225396-0--0", cloud_service_type="hws.service.type.dbss", resource_type="hws.resource.type.dbss", resource_spec_code="dbss.bypassaudit.low", product_spec_desc="test" ) ] listSecurityGroupsbody = [ CreateInstancePeriodRequestSecurityGroups( id="04088976-9c63-4e6b-9070-84e6a30c782b" ) ] listNicsbody = [ CreateInstancePeriodRequestNics( subnet_id="6201dcf2-1374-43ec-ae8b-78b4081572d3" ) ] request.body = CreateInstancePeriodRequest( is_auto_renew=0, promotion_info="", tags=listTagsbody, product_infos=listProductInfosbody, subscription_num=1, period_num=1, period_type=2, charging_mode=0, cloud_service_type="hws.service.type.dbss", region="cn-north-7", comment="", security_groups=listSecurityGroupsbody, nics=listNicsbody, enterprise_project_id="0", availability_zone="cn-north-7c", vpc_id="4c035747-f77b-4c6d-b23b-cb3a2b96c7e6", name="DBSS-acc3", flavor_ref="st6.xlarge.4" ) response = client.create_instances_period_order(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
  • 响应参数 状态码: 200 表8 响应Body参数 参数 参数类型 描述 description String 描述 code String 返回码 order_id String 订单ID 状态码: 400 表9 响应Body参数 参数 参数类型 描述 error Object 错误信息返回体。 表10 ErrorDetail 参数 参数类型 描述 error_code String 错误请求返回的错误码。 error_msg String 错误请求返回的错误信息。 状态码: 403 表11 响应Body参数 参数 参数类型 描述 error Object 错误信息返回体。 表12 ErrorDetail 参数 参数类型 描述 error_code String 错误请求返回的错误码。 error_msg String 错误请求返回的错误信息。 状态码: 500 表13 响应Body参数 参数 参数类型 描述 error Object 错误信息返回体。 表14 ErrorDetail 参数 参数类型 描述 error_code String 错误请求返回的错误码。 error_msg String 错误请求返回的错误信息。
  • 请求示例 创建一个包周期计费"chargin_mode : 0"的实例,版本为基础版:"resource_spec_code" : "dbss.bypassaudit.low"。 /v2/{project_id}/dbss/audit/charge/period/order { "flavor_ref" : "st6.xlarge.4", "name" : "DBSS-acc3", "vpc_id" : "4c035747-f77b-4c6d-b23b-cb3a2b96c7e6", "availability_zone" : "cn-north-7c", "comment" : "", "region" : "cn-north-7", "nics" : [ { "subnet_id" : "6201dcf2-1374-43ec-ae8b-78b4081572d3" } ], "security_groups" : [ { "id" : "04088976-9c63-4e6b-9070-84e6a30c782b" } ], "cloud_service_type" : "hws.service.type.dbss", "charging_mode" : 0, "period_type" : 2, "period_num" : 1, "subscription_num" : 1, "is_auto_renew" : 0, "product_infos" : [ { "product_id" : "00301-225396-0--0", "cloud_service_type" : "hws.service.type.dbss", "resource_type" : "hws.resource.type.dbss", "resource_spec_code" : "dbss.bypassaudit.low", "product_spec_desc" : "{\"specDesc\":{\"zh-cn\":{\"key1\":\"value1\"},\"en-us\":{\"key1\":\"value1\"}}}" } ], "promotion_info" : "", "enterprise_project_id" : "0", "tags" : [ { "key" : "key_test", "value" : "1" } ] } 创建一个包周期计费"chargin_mode : 0"的实例,版本为专业版:"resource_spec_code" : "dbss.bypassaudit.medium"。 { "flavor_ref": "c6.2xlarge.2", "name": "DBSS-test", "vpc_id": "4c035747-f77b-4c6d-b23b-cb3a2b96c7e6", "availability_zone": "cn-north-7b", "comment": "", "region": "cn-north-7", "nics": [ { "subnet_id": "6201dcf2-1374-43ec-ae8b-78b4081572d3" } ], "security_groups": [ { "id": "59c45017-a484-481b-8440-18c2214ccb06" } ], "cloud_service_type": "hws.service.type.dbss", "charging_mode": 0, "period_type": 2, "period_num": 1, "subscription_num": 1, "is_auto_renew": 0, "product_infos": [ { "product_id": "00301-225396-0--0", "cloud_service_type": "hws.service.type.dbss", "resource_type": "hws.resource.type.dbss", "resource_spec_code": "dbss.bypassaudit.medium", "product_spec_desc": "{\"specDesc\":{\"zh-cn\":{\"key1\":\"value1\"},\"en-us\":{\"key1\":\"value1\"}}}" } ], "promotion_info": "", "enterprise_project_id": "0" }
  • 请求参数 表2 请求Header参数 参数 是否必选 参数类型 描述 X-Auth-Token 是 String 用户Token 表3 请求Body参数 参数 是否必选 参数类型 描述 flavor_ref 是 String 云服务器使用的规格ID name 是 String 云服务器名称。 取值范围: 只能由中文字符、英文字母、数字、下划线、中划线组成,且长度小于等于64个字符。 创建的云服务器数量大于1时,长度小于等于59个字符 vpc_id 是 String VPC的ID availability_zone 是 String 云服务器对应可用分区信息。(两个主备分区,中间用“,”分割,例如az1.dc1,az2.dc2) enterprise_project_id 是 String 企业项目ID nics 是 Array of nics objects 云服务器对应的网卡信息 security_groups 是 Array of security_groups objects 云服务器对应安全组信息 comment 否 String 备注信息 region 是 String 云服务器所在区域ID cloud_service_type 是 String 服务类型: 默认hws.service.type.dbss charging_mode 是 Integer 计费模式: 0:包周期计费 1:按需计费 period_type 是 Integer 订购周期类型: 0:天; 1:周; 2:月; 3:年; 4:小时; 5:绝对时间 period_num 是 Integer 订购周期数 subscription_num 是 Integer 订购数量: DBSS只支持订购1套,不支持多套 product_infos 是 Array of product_infos objects 产品信息列表 tags 否 Array of KeyValueBean objects 资源标签 promotion_info 否 String 折扣信息 is_auto_renew 是 Integer 自动续费 1表示自动续费,0表示不自动续费 表4 nics 参数 是否必选 参数类型 描述 subnet_id 是 String 网卡对应的子网ID ip_address 否 String IP地址,不填或空字符串为自动分配 表5 security_groups 参数 是否必选 参数类型 描述 id 是 String 云服务器对应的安全组ID,会对创建云服务器中配置的网卡生效 表6 product_infos 参数 是否必选 参数类型 描述 product_id 是 String 产品ID cloud_service_type 是 String 服务类型: 默认hws.service.type.dbss resource_type 是 String 资源类型: 默认hws.resource.type.dbss resource_spec_code 是 String 资源规格:dbss.bypassaudit.low、dbss.bypassaudit.medium、dbss.bypassaudit.high product_spec_desc 是 String 产品规格描述, json字符串格式 :{"specDesc":{"zh-cn":{"key1":"value1"},"en-us":{"key1":"value1"}}} 表7 KeyValueBean 参数 是否必选 参数类型 描述 key 是 String 键 value 是 String 值
  • 响应示例 状态码: 200 成功 { "servers" : [ { "name" : "DBSS-Test", "comment" : "", "connect_ipv6" : null, "status" : "ACTIVE", "task" : "NO_TASK", "id" : "8c53ed03-8ed7-4ff2-ad97-7b2d6d1dd364", "specification" : "Low | 3 Proxy", "zone" : "cn-cmcc1a-01", "created" : "2021-04-21 04:37:54", "expired" : null, "subnet_id" : "97ef0bb5-3759-4db4-aa49-0d087ed49ce5", "cpu" : 4, "ram" : 16384, "region" : "cn-cmcc1", "version" : "21.04.16.164614", "charge_model" : "Demand", "remain_days" : null, "config_num" : 1, "effect" : null, "scene" : null, "connect_ip" : "192.168.0.229", "port_id" : "dc4bd420-e01c-4d12-a7ff-814f17c63079", "resource_id" : "062212d8-8e30-4783-9671-43f3f1f3bb1e", "vpc_id" : "76d98391-5abc-46ed-b8a8-f664202cb166", "security_group_id" : "f0fbec06-bcf6-4c7e-99fa-f0ddfbb1d9bd", "resource_spec_code" : "dbss.bypassaudit.low", "keep_days" : null, "new_version" : null, "database_limit" : 3 } ], "total" : 1 } 状态码: 400 失败 { "error" : { "error_code" : "DBSS.XXXX", "error_msg" : "XXX" } }
  • 响应参数 状态码: 200 表4 响应Body参数 参数 参数类型 描述 servers Array of AuditInstanceListBean objects 实例信息列表 total Integer 总数 表5 AuditInstanceListBean 参数 参数类型 描述 charge_model String 付费模式 Period:包周期 Demand:按需。 comment String 备注信息。 config_num Integer 配置的数据库总数。 connect_ip String 连接地址。 connect_ipv6 String ipv6连接地址。 cpu Integer CPU个数 created String 创建时间 database_limit Integer 支持的数据库总数 effect Integer 1.冻结可释放 2.冻结不可释放 3.冻结后不可续费 expired String 过期时间 id String ID keep_days String 剩余天数 name String 实例别名 new_version String 如果有返回,则需要升级,如果没有,则为null port_id String 绑定弹性IP的portID ram Integer 内存 region String 实例所在region remain_days String 到期天数 resource_id String 资源ID resource_spec_code String 实例的规格 scene String 场景 security_group_id String 安全组 specification String 实例规格 status String 实例状态: SHUTOFF(已关闭) ACTIVE(运行中,允许任何操作) DELETING(删除中,不允许任何操作) BUILD(创建中,不允许任何操作) DELETED(已删除,不需要展示) ERROR(故障,只允许删除) HAWAIT(等待备机创建成功,不允许任何操作) FROZEN(已冻结,只允许续费、绑定/解绑) UPGRADING(升级中,不允许升级操作) subnet_id String 子网ID task String 任务状态: powering-on(正在开启,实例可以绑定、解绑) powering-off(正在关闭,实例可以绑定、解绑) rebooting(正在重启,实例可以绑定、解绑) delete_wait(等待删除,集群与实例不允许任何操作) NO_TASK(不展示) version String 实例的当前版本 vpc_id String 虚拟私有云 zone String 可用区 状态码: 400 表6 响应Body参数 参数 参数类型 描述 error Object 错误信息返回体。 表7 ErrorDetail 参数 参数类型 描述 error_code String 错误请求返回的错误码。 error_msg String 错误请求返回的错误信息。 状态码: 403 表8 响应Body参数 参数 参数类型 描述 error Object 错误信息返回体。 表9 ErrorDetail 参数 参数类型 描述 error_code String 错误请求返回的错误码。 error_msg String 错误请求返回的错误信息。 状态码: 500 表10 响应Body参数 参数 参数类型 描述 error Object 错误信息返回体。 表11 ErrorDetail 参数 参数类型 描述 error_code String 错误请求返回的错误码。 error_msg String 错误请求返回的错误信息。