华为云用户手册

  • Go 创建一个企业路由器,名称为“my_er”,开启默认路由表关联和默认路由表传播功能 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" er "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := er.NewErClient( er.ErClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.CreateEnterpriseRouterRequest{} var listAvailabilityZoneIdsInstance = []string{ "az1", "az2", } keyTags:= "key1" valueTags:= "value1" var listTagsInstance = []model.Tag{ { Key: &keyTags, Value: &valueTags, }, } descriptionInstance:= "this is my first enterprise router" enableDefaultPropagationInstance:= true enableDefaultAssociationInstance:= true instancebody := &model.CreateEnterpriseRouter{ Name: "my_er", Description: &descriptionInstance, Asn: int64(64512), Tags: &listTagsInstance, EnableDefaultPropagation: &enableDefaultPropagationInstance, EnableDefaultAssociation: &enableDefaultAssociationInstance, AvailabilityZoneIds: listAvailabilityZoneIdsInstance, } request.Body = &model.CreateEnterpriseRouterRequestBody{ Instance: instancebody, } response, err := client.CreateEnterpriseRouter(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • 请求参数 表2 请求Header参数 参数 是否必选 参数类型 描述 X-Client-Token 否 String 幂等性标识 最小长度:1 最大长度:64 表3 请求Body参数 参数 是否必选 参数类型 描述 instance 是 CreateEnterpriseRouter object 企业路由器 表4 CreateEnterpriseRouter 参数 是否必选 参数类型 描述 name 是 String 企业路由器实例名称,取值范围:1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点) 最小长度:1 最大长度:64 description 否 String 企业路由器实例描述信息 最小长度:0 最大长度:255 asn 是 Long 企业路由器实例的BGP AS号 enterprise_project_id 否 String 企业项目ID charge_mode 否 String 计费模式 按需 缺省值:postPaid tags 否 Array of Tag objects 标签信息 enable_default_propagation 否 Boolean 是否开启默认路由表传播,默认false不开启 缺省值:false enable_default_association 否 Boolean 是否开启默认路由表关联,默认false不开启 缺省值:false availability_zone_ids 是 Array of strings 企业路由器所在的可用区列表 最小长度:0 最大长度:128 auto_accept_shared_attachments 否 Boolean 是否开启自动接受共享连接创建,默认false不开启 缺省值:false 表5 Tag 参数 是否必选 参数类型 描述 key 否 String 标签键,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2._sys_开头属于系统标签,租户不能输入。 3.标签key不能为空(长度不能为0)。 4.长度在1-128之间。 最小长度:1 最大长度:128 value 否 String 标签值,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2.资源标签值可以为空(empty or null)。 3.长度在0-255之间。 最小长度:0 最大长度:255
  • 响应参数 状态码: 202 表6 响应Header参数 参数 参数类型 描述 X-Client-Token - 幂等性标识 表7 响应Body参数 参数 参数类型 描述 instance EnterpriseRouter object 企业路由器 request_id String 请求ID 表8 EnterpriseRouter 参数 参数类型 描述 id String 企业路由器实例的ID name String 企业路由器实例名称 description String 企业路由器实例描述信息 state String 运行状态:pending|available|modifying|deleting|deleted|failed tags Array of Tag objects 标签信息 charge_mode String 计费模式 按需 缺省值:postPaid created_at String 创建时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ updated_at String 更新时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ enterprise_project_id String 企业项目ID project_id String 项目ID asn Long 企业路由器实例的BGP AS号 enable_default_propagation Boolean 是否开启默认路由表传播,默认false不开启 enable_default_association Boolean 是否开启默认路由表关联,默认false不开启 default_propagation_route_table_id String 默认传播路由表id default_association_route_table_id String 默认关联路由表id availability_zone_ids Array of strings 企业路由器所在可用区信息 auto_accept_shared_attachments Boolean 是否自动接受共享连接创建,默认false不开启 表9 Tag 参数 参数类型 描述 key String 标签键,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2._sys_开头属于系统标签,租户不能输入。 3.标签key不能为空(长度不能为0)。 4.长度在1-128之间。 最小长度:1 最大长度:128 value String 标签值,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2.资源标签值可以为空(empty or null)。 3.长度在0-255之间。 最小长度:0 最大长度:255
  • 请求示例 创建一个企业路由器,名称为“my_er”,开启默认路由表关联和默认路由表传播功能 POST https://{erouter_endpoint}/v3/08d5a9564a704afda6039ae2babbef3c/enterprise-router/instances { "instance" : { "name" : "my_er", "description" : "this is my first enterprise router", "asn" : 64512, "enable_default_association" : true, "enable_default_propagation" : true, "tags" : [ { "key" : "key1", "value" : "value1" } ], "availability_zone_ids" : [ "az1", "az2" ] } }
  • Go 更新企业路由器内路由表的信息,修改路由表名称为“new-rtb” 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" er "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := er.NewErClient( er.ErClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.UpdateRouteTableRequest{} nameRouteTable:= "new-rtb" routeTablebody := &model.UpdateRouteTable{ Name: &nameRouteTable, } request.Body = &model.UpdateRouteTableRequestBody{ RouteTable: routeTablebody, } response, err := client.UpdateRouteTable(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • 响应参数 状态码: 200 表4 响应Body参数 参数 参数类型 描述 route_table RouteTable object 路由表 request_id String 请求ID 表5 RouteTable 参数 参数类型 描述 id String 路由表的id name String 路由表名字 description String 描述信息 is_default_association Boolean 是否为默认关联的路由表 缺省值:false is_default_propagation Boolean 是否为默认传递路由表 state String 路由表状态,支持的状态有pending | available | deleting | deleted | failed tags Array of Tag objects 标签 created_at String 创建时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ updated_at String 更新时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ 表6 Tag 参数 参数类型 描述 key String 标签键,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2._sys_开头属于系统标签,租户不能输入。 3.标签key不能为空(长度不能为0)。 4.长度在1-128之间。 最小长度:1 最大长度:128 value String 标签值,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2.资源标签值可以为空(empty or null)。 3.长度在0-255之间。 最小长度:0 最大长度:255
  • 响应示例 状态码: 200 OK { "route_table" : { "id" : "4ab54142-7c92-48ad-8288-77727a231052", "name" : "new-rtb", "is_default_association" : false, "is_default_propagation" : false, "state" : "pending", "created_at" : "2020-03-11T15:13:31Z", "updated_at" : "2020-03-11T15:13:31Z" }, "request_id" : "915a14a6-867b-4af7-83d1-70efceb146f9" }
  • 请求参数 表2 请求Body参数 参数 是否必选 参数类型 描述 route_table 否 UpdateRouteTable object 更新路由表请求体 表3 UpdateRouteTable 参数 是否必选 参数类型 描述 name 否 String 路由器表名称,取值范围:1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点) 最小长度:1 最大长度:64 description 否 String 路由器表描述信息 最小长度:0 最大长度:255
  • 请求示例 更新企业路由器内路由表的信息,修改路由表名称为“new-rtb” PUT https://{erouter_endpoint}/v3/08d5a9564a704afda6039ae2babbef3c/enterprise-router/915a14a6-867b-4af7-83d1-70efceb146f5/route-tables/4ab54142-7c92-48ad-8288-77727a231052 { "route_table" : { "name" : "new-rtb" } }
  • Python 更新企业路由器内路由表的信息,修改路由表名称为“new-rtb” 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdker.v3.region.er_region import ErRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdker.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.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ErClient.new_builder() \ .with_credentials(credentials) \ .with_region(ErRegion.value_of("cn-north-4")) \ .build() try: request = UpdateRouteTableRequest() routeTablebody = UpdateRouteTable( name="new-rtb" ) request.body = UpdateRouteTableRequestBody( route_table=routeTablebody ) response = client.update_route_table(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
  • Java 更新企业路由器内路由表的信息,修改路由表名称为“new-rtb” 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 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.er.v3.region.ErRegion; import com.huaweicloud.sdk.er.v3.*; import com.huaweicloud.sdk.er.v3.model.*; public class UpdateRouteTableSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ErClient client = ErClient.newBuilder() .withCredential(auth) .withRegion(ErRegion.valueOf("cn-north-4")) .build(); UpdateRouteTableRequest request = new UpdateRouteTableRequest(); UpdateRouteTableRequestBody body = new UpdateRouteTableRequestBody(); UpdateRouteTable routeTablebody = new UpdateRouteTable(); routeTablebody.withName("new-rtb"); body.withRouteTable(routeTablebody); request.withBody(body); try { UpdateRouteTableResponse response = client.updateRouteTable(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()); } } }
  • Python 在企业路由器内创建路由表,名称为“my-route-table” 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdker.v3.region.er_region import ErRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdker.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.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ErClient.new_builder() \ .with_credentials(credentials) \ .with_region(ErRegion.value_of("cn-north-4")) \ .build() try: request = CreateRouteTableRequest() listTagsRouteTable = [ Tag( key="key", value="value" ) ] routeTablebody = CreateRouteTable( name="my-route-table", tags=listTagsRouteTable ) request.body = CreateRouteTableRequestBody( route_table=routeTablebody ) response = client.create_route_table(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
  • 请求示例 在企业路由器内创建路由表,名称为“my-route-table” POST https://{erouter_endpoint}/v3/08d5a9564a704afda6039ae2babbef3c/enterprise-router/915a14a6-867b-4af7-83d1-70efceb146f0/route-tables { "route_table" : { "name" : "my-route-table", "tags" : [ { "key" : "key", "value" : "value" } ] } }
  • 响应示例 状态码: 202 Accepted { "route_table" : { "id" : "4ab54142-7c92-48ad-8288-77727a231052", "name" : "my-route-table", "is_default_association" : false, "is_default_propagation" : false, "state" : "pending", "created_at" : "2020-03-11T15:13:31Z", "updated_at" : "2020-03-11T15:13:31Z", "tags" : [ { "key" : "key", "value" : "value" } ] }, "request_id" : "915a14a6-867b-4af7-83d1-70efceb146f9" }
  • Go 在企业路由器内创建路由表,名称为“my-route-table” 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" er "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := er.NewErClient( er.ErClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.CreateRouteTableRequest{} keyTags:= "key" valueTags:= "value" var listTagsRouteTable = []model.Tag{ { Key: &keyTags, Value: &valueTags, }, } routeTablebody := &model.CreateRouteTable{ Name: "my-route-table", Tags: &listTagsRouteTable, } request.Body = &model.CreateRouteTableRequestBody{ RouteTable: routeTablebody, } response, err := client.CreateRouteTable(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • 请求参数 表2 请求Header参数 参数 是否必选 参数类型 描述 X-Client-Token 否 String 幂等性标识 最小长度:1 最大长度:64 表3 请求Body参数 参数 是否必选 参数类型 描述 route_table 否 CreateRouteTable object 路由表 表4 CreateRouteTable 参数 是否必选 参数类型 描述 name 是 String 路由器表名称,取值范围:1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点) 最小长度:1 最大长度:64 description 否 String 路由器表描述信息 最小长度:0 最大长度:255 tags 否 Array of Tag objects 标签信息 表5 Tag 参数 是否必选 参数类型 描述 key 否 String 标签键,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2._sys_开头属于系统标签,租户不能输入。 3.标签key不能为空(长度不能为0)。 4.长度在1-128之间。 最小长度:1 最大长度:128 value 否 String 标签值,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2.资源标签值可以为空(empty or null)。 3.长度在0-255之间。 最小长度:0 最大长度:255
  • 响应参数 状态码: 202 表6 响应Header参数 参数 参数类型 描述 X-Client-Token - 幂等性标识 表7 响应Body参数 参数 参数类型 描述 route_table RouteTable object 路由表 request_id String 请求ID 表8 RouteTable 参数 参数类型 描述 id String 路由表的id name String 路由表名字 description String 描述信息 is_default_association Boolean 是否为默认关联的路由表 缺省值:false is_default_propagation Boolean 是否为默认传递路由表 state String 路由表状态,支持的状态有pending | available | deleting | deleted | failed tags Array of Tag objects 标签 created_at String 创建时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ updated_at String 更新时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ 表9 Tag 参数 参数类型 描述 key String 标签键,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2._sys_开头属于系统标签,租户不能输入。 3.标签key不能为空(长度不能为0)。 4.长度在1-128之间。 最小长度:1 最大长度:128 value String 标签值,规则: 1.可用 UTF-8 格式表示的字母(包含中文)、数字和空格,以及字符:下划线“_”,点“.”,冒号“:”,等号“=”,加号“+”,中划线“-”,“@”。 2.资源标签值可以为空(empty or null)。 3.长度在0-255之间。 最小长度:0 最大长度:255
  • 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdker.v3.region.er_region import ErRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdker.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.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ErClient.new_builder() \ .with_credentials(credentials) \ .with_region(ErRegion.value_of("cn-north-4")) \ .build() try: request = DeleteFlowLogRequest() response = client.delete_flow_log(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
  • 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" er "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := er.NewErClient( er.ErClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.DeleteFlowLogRequest{} response, err := client.DeleteFlowLog(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • Java 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 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.er.v3.region.ErRegion; import com.huaweicloud.sdk.er.v3.*; import com.huaweicloud.sdk.er.v3.model.*; public class DeleteFlowLogSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ErClient client = ErClient.newBuilder() .withCredential(auth) .withRegion(ErRegion.valueOf("cn-north-4")) .build(); DeleteFlowLogRequest request = new DeleteFlowLogRequest(); try { DeleteFlowLogResponse response = client.deleteFlowLog(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()); } } }
  • 请求消息体(可选) 该部分可选。请求消息体通常以结构化格式(如JSON或XML)发出,与请求消息头中Content-Type对应,传递除请求消息头之外的内容。若请求消息体中的参数支持中文,则中文字符必须为UTF-8编码。 每个接口的请求消息体内容不同,也并不是每个接口都需要有请求消息体(或者说消息体为空),GET、DELETE操作类型的接口就不需要消息体,消息体具体内容需要根据具体接口而定。 对于获取用户Token接口,您可以从接口的请求部分看到所需的请求参数及参数说明。将消息体加入后的请求如下所示,加粗的斜体字段需要根据实际值填写,其中username为用户名,domainname为用户所属的账号名称,********为用户登录密码,xxxxxxxxxxxxxxxxxx为project的名称,如“cn-north-1”,您可以从地区和终端节点获取。 scope参数定义了Token的作用域,下面示例中获取的Token仅能访问project下的资源。您还可以设置Token的作用域为某个账号下所有资源或账号的某个project下的资源,详细定义请参见获取用户Token。 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 POST https://iam.cn-north-1.myhuaweicloud.com/v3/auth/tokens Content-Type: application/json { "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", "password": "********", "domain": { "name": "domainname" } } } }, "scope": { "project": { "name": "xxxxxxxxxxxxxxxxxx" } } } } 到这里为止这个请求需要的内容就具备齐全了,您可以使用curl、Postman或直接编写代码等方式发送请求调用API。对于获取用户Token接口,返回的响应消息头中的“x-subject-token”就是需要获取的用户Token。有了Token之后,您就可以使用Token认证调用其他API。
  • 请求方法 HTTP请求方法(也称为操作或动词),它告诉服务您正在请求什么类型的操作。 表2 HTTP方法 方法 说明 GET 请求服务器返回指定资源。 PUT 请求服务器更新指定资源。 POST 请求服务器新增资源或执行特殊操作。 DELETE 请求服务器删除指定资源,如删除对象等。 HEAD 请求服务器资源头部。 PATCH 请求服务器更新资源的部分内容。 当资源不存在的时候,PATCH可能会去创建一个新的资源。 在获取用户Token的URI部分,您可以看到其请求方法为“POST”,则其请求为: 1 POST https://iam.cn-north-1.myhuaweicloud.com/v3/auth/tokens
  • 请求消息头 附加请求头字段,如指定的URI和HTTP方法所要求的字段。例如定义消息体类型的请求头“Content-Type”,请求鉴权信息等。 详细的公共请求消息头字段请参见表3。 表3 公共请求消息头 名称 描述 是否必选 示例 Host 请求的服务器信息,从服务API的URL中获取。值为hostname[:port]。端口缺省时使用默认的端口,https的默认端口为443。 否 使用AK/SK认证时该字段必选。 code.test.com or code.test.com:443 Content-Type 消息体的类型(格式)。推荐用户使用默认值application/json,有其他取值时会在具体接口中专门说明。 是 application/json Content-Length 请求body长度,单位为Byte。 否 3495 X-Project-Id project id,项目编号。请参考获取项目ID章节获取项目编号。 否 如果是专属云场景采用AK/SK认证方式的接口请求,或者多project场景采用AK/SK认证的接口请求,则该字段必选。 e9993fc787d94b6c886cbaa340f9c0f4 X-Auth-Token 用户Token。 用户Token也就是调用获取用户Token接口的响应值,该接口是唯一不需要认证的接口。 请求响应成功后在响应消息头(Headers)中包含的“X-Subject-Token”的值即为Token值。 否 使用Token认证时该字段必选。 注:以下仅为Token示例片段。 MIIPAgYJKoZIhvcNAQcCo...ggg1BBIINPXsidG9rZ API同时支持使用AK/SK认证,AK/SK认证使用SDK对请求进行签名,签名过程会自动往请求中添加Authorization(签名认证信息)和X-Sdk-Date(请求发送的时间)请求头。 AK/SK认证的详细说明请参见认证鉴权的“AK/SK认证”。 对于获取用户Token接口,由于不需要认证,所以只添加“Content-Type”即可,添加消息头后的请求如下所示。 1 2 POST https://iam.cn-north-1.myhuaweicloud.com/v3/auth/tokens Content-Type: application/json
  • 请求URI 请求URI由如下部分组成: {URI-scheme}://{Endpoint}/{resource-path}?{query-string} 尽管请求URI包含在请求消息头中,但大多数语言或框架都要求您从请求消息中单独传递它,所以在此单独强调。 表1 URI中的参数说明 参数 描述 URI-scheme 表示用于传输请求的协议,当前所有API均采用HTTPS协议。 Endpoint 指定承载REST服务端点的服务器域名或IP,不同服务不同区域的Endpoint不同,您可以从地区和终端节点获取。 例如IAM服务在“华北-北京四”区域的Endpoint为“iam.cn-north-4.myhuaweicloud.com”。 resource-path 资源路径,即API访问路径。从具体API的URI模块获取,例如“获取用户Token”API的resource-path为“/v3/auth/tokens”。 query-string 查询参数,是可选部分,并不是每个API都有查询参数。查询参数前面需要带一个“?”,形式为“参数名=参数取值”,例如“?limit=10”,表示查询不超过10条数据。 例如您需要获取IAM在“华北-北京四”区域的Token,则需使用“华北-北京四”区域的Endpoint(iam.cn-north-4.myhuaweicloud.com),并在获取用户Token的URI部分找到resource-path(/v3/auth/tokens),拼接起来如下所示。 1 https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens 图1 URI示意图 为方便查看,在每个具体API的URI部分,只给出resource-path部分,并将请求方法写在一起。这是因为URI-scheme都是HTTPS,而Endpoint在同一个区域也相同,所以简洁起见将这两部分省略。
  • Java 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 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.er.v3.region.ErRegion; import com.huaweicloud.sdk.er.v3.*; import com.huaweicloud.sdk.er.v3.model.*; public class DeleteEnterpriseRouterSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ErClient client = ErClient.newBuilder() .withCredential(auth) .withRegion(ErRegion.valueOf("cn-north-4")) .build(); DeleteEnterpriseRouterRequest request = new DeleteEnterpriseRouterRequest(); try { DeleteEnterpriseRouterResponse response = client.deleteEnterpriseRouter(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()); } } }
  • 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" er "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := er.NewErClient( er.ErClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.DeleteEnterpriseRouterRequest{} response, err := client.DeleteEnterpriseRouter(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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdker.v3.region.er_region import ErRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdker.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.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ErClient.new_builder() \ .with_credentials(credentials) \ .with_region(ErRegion.value_of("cn-north-4")) \ .build() try: request = DeleteEnterpriseRouterRequest() response = client.delete_enterprise_router(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
  • Python 创建一个VPC连接,名称为“vpc-atta”,并指定连接的VPC和子网资源 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 # coding: utf-8 from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdker.v3.region.er_region import ErRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdker.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.getenv("CLOUD_SDK_AK") sk = os.getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = ErClient.new_builder() \ .with_credentials(credentials) \ .with_region(ErRegion.value_of("cn-north-4")) \ .build() try: request = CreateVpcAttachmentRequest() vpcAttachmentbody = VpcAttachmentCreateRequest( vpc_id="b715e131-3371-4e17-a2de-4f669e24439a", name="vpc-atta", virsubnet_id="aacdc21d-90f9-45ef-ab48-80ec1bbe15b8" ) request.body = CreateVpcAttachmentBody( vpc_attachment=vpcAttachmentbody ) response = client.create_vpc_attachment(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
  • Go 创建一个VPC连接,名称为“vpc-atta”,并指定连接的VPC和子网资源 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 package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" er "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/er/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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := er.NewErClient( er.ErClientBuilder(). WithRegion(region.ValueOf("cn-north-4")). WithCredential(auth). Build()) request := &model.CreateVpcAttachmentRequest{} vpcAttachmentbody := &model.VpcAttachmentCreateRequest{ VpcId: "b715e131-3371-4e17-a2de-4f669e24439a", Name: "vpc-atta", VirsubnetId: "aacdc21d-90f9-45ef-ab48-80ec1bbe15b8", } request.Body = &model.CreateVpcAttachmentBody{ VpcAttachment: vpcAttachmentbody, } response, err := client.CreateVpcAttachment(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • Java 创建一个VPC连接,名称为“vpc-atta”,并指定连接的VPC和子网资源 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 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.er.v3.region.ErRegion; import com.huaweicloud.sdk.er.v3.*; import com.huaweicloud.sdk.er.v3.model.*; public class CreateVpcAttachmentSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); ErClient client = ErClient.newBuilder() .withCredential(auth) .withRegion(ErRegion.valueOf("cn-north-4")) .build(); CreateVpcAttachmentRequest request = new CreateVpcAttachmentRequest(); CreateVpcAttachmentBody body = new CreateVpcAttachmentBody(); VpcAttachmentCreateRequest vpcAttachmentbody = new VpcAttachmentCreateRequest(); vpcAttachmentbody.withVpcId("b715e131-3371-4e17-a2de-4f669e24439a") .withName("vpc-atta") .withVirsubnetId("aacdc21d-90f9-45ef-ab48-80ec1bbe15b8"); body.withVpcAttachment(vpcAttachmentbody); request.withBody(body); try { CreateVpcAttachmentResponse response = client.createVpcAttachment(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()); } } }
共100000条