华为云用户手册

  • URI POST /v3/{project_id}/enterprise-router/{er_id}/route-tables/{route_table_id}/enable-propagations 表1 路径参数 参数 是否必选 参数类型 描述 project_id 是 String 项目ID er_id 是 String 企业路由器实例ID route_table_id 是 String 路由表ID
  • 请求参数 表2 请求Header参数 参数 是否必选 参数类型 描述 X-Client-Token 否 String 幂等性标识 最小长度:1 最大长度:64 表3 请求Body参数 参数 是否必选 参数类型 描述 attachment_id 否 String 连接唯一标识 route_policy 否 ImportRoutePolicy object 入方向路由策略 表4 ImportRoutePolicy 参数 是否必选 参数类型 描述 import_policy_id 否 String 入方向Ipv4协议路由策略id 最小长度:0 最大长度:36
  • 响应示例 状态码: 200 OK { "propagations" : [ { "id" : "915a14a6-867b-4af7-83d1-70efceb146f9", "er_id" : "7dec531a-7714-11eb-9439-0242ac130002", "route_table_id" : "91c013e2-d65a-474e-9177-c3e1799ca726", "attachment_id" : "a5b7d209-dc02-4c46-a51f-805eadd3de64", "resource_type" : "vpc", "resource_id" : "4e5fe97c-82bc-432e-87d8-06d7e157dffa", "route_policy" : { "import_policy_id" : "" }, "state" : "pending", "created_at" : "2020-03-11T15:13:31Z", "updated_at" : "2020-03-11T15:13:31Z" } ], "page_info" : { "next_marker" : "1", "current_count" : 1 }, "request_id" : "915a14a6-867b-4af7-83d1-70efceb146f9" }
  • 响应参数 状态码: 200 表3 响应Body参数 参数 参数类型 描述 propagations Array of Propagation objects 路由传播列表 数组长度:0 - 2000 request_id String 请求ID page_info PageInfo object 分页查询的信息 表4 Propagation 参数 参数类型 描述 id String 关联唯一标识 project_id String 项目ID er_id String 企业路由器id route_table_id String 路由表唯一标识 attachment_id String 连接唯一标识 resource_type String vpc:虚拟私有云 vpn:vpn网关 vgw:云专线的虚拟网关 peering:对等连接,通过云连接CC加载不同区域的企业路由器来创建“对等连接(Peering)”连接 resource_id String 连接的资源唯一标识 route_policy ImportRoutePolicy object 入方向路由策略 state String 状态:pending|available|modifying|deleting|deleted|failed created_at String 资源创建时间 采用UTC时间 格式:YYYY-MM-DDTHH:mm:ss.sssZ updated_at String 资源更新时间 采用UTC时间 格式:YYYY-MM-DDTHH:mm:ss.sssZ 表5 ImportRoutePolicy 参数 参数类型 描述 import_policy_id String 入方向Ipv4协议路由策略id 最小长度:0 最大长度:36 表6 PageInfo 参数 参数类型 描述 next_marker String 下一个marker标识,为空时表示最后一页 current_count Integer 当前列表中资源数量
  • URI GET /v3/{project_id}/enterprise-router/{er_id}/route-tables/{route_table_id}/propagations 表1 路径参数 参数 是否必选 参数类型 描述 project_id 是 String 项目ID er_id 是 String 企业路由器实例ID route_table_id 是 String 路由表ID 表2 Query参数 参数 是否必选 参数类型 描述 limit 否 Integer 每页返回的个数。 取值范围:0~2000。 最小值:0 最大值:2000 marker 否 String 查询的页码id,为空时为查询第一页。 使用说明:必须与limit一起使用。 最小长度:1 最大长度:128 attachment_id 否 Array 连接ID resource_type 否 Array vpc:虚拟私有云 vpn:vpn网关 vgw:云专线的虚拟网关 peering:对等连接,通过云连接CC加载不同区域的企业路由器来创建“对等连接(Peering)”连接 state 否 Array 企业路由器实例状态:pending|available|modifying|deleting|deleted|failed|freezed sort_key 否 Array 按关键字排序,默认按照id排序,可选值:id|name|state sort_dir 否 Array 返回结果按照升序或降序排列,默认为asc,降序为desc
  • 请求示例 更新企业路由器的可用区 POST https://{erouter_endpoint}/v3/08d5a9564a704afda6039ae2babbef3c/enterprise-router/instances/cccf35ad-fd0d-4043-aab2-dc28ae56f967/change-availability-zone-ids { "availability_zone_ids" : [ "az1" ] }
  • 响应示例 状态码: 202 Accepted { "instance" : { "id" : "94c2b814-99dc-939a-e811-ae84c61ea3ff", "name" : "my_er", "description" : "this is my first enterprise router", "project_id" : "08d5a9564a704afda6039ae2babbef3c", "state" : "pending", "asn" : 64512, "enable_default_association" : true, "enable_default_propagation" : true, "default_association_route_table_id" : "7f7f738f-453c-40b1-be26-28e7b9e390c1", "default_propagation_route_table_id" : "7f7f738f-453c-40b1-be26-28e7b9e390c1", "availability_zone_ids" : [ "az1" ], "created_at" : "2019-09-06 02:11:13Z", "updated_at" : "2019-09-06 02:11:13Z" }, "request_id" : "5f7f738f-453c-40b1-be26-28e7b9e390c2" }
  • 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 # 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 = ChangeAvailabilityZoneRequest() listAvailabilityZoneIdsbody = [ "az1" ] request.body = EnterpriseRouterAZ( availability_zone_ids=listAvailabilityZoneIdsbody ) response = client.change_availability_zone(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 36 37 38 39 40 41 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.ChangeAvailabilityZoneRequest{} var listAvailabilityZoneIdsbody = []string{ "az1", } request.Body = &model.EnterpriseRouterAz{ AvailabilityZoneIds: listAvailabilityZoneIdsbody, } response, err := client.ChangeAvailabilityZone(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • 响应参数 状态码: 202 表3 响应Body参数 参数 参数类型 描述 instance EnterpriseRouter object 企业路由器 request_id String 请求ID 表4 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不开启 表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
  • URI GET /v3/{project_id}/enterprise-router/availability-zones 表1 路径参数 参数 是否必选 参数类型 描述 project_id 是 String 项目ID 表2 Query参数 参数 是否必选 参数类型 描述 instance_id 否 String 企业路由器ID bandwidth_size 否 Integer 带宽大小,单位Mbps 最小值:-1
  • 响应参数 状态码: 200 表3 响应Body参数 参数 参数类型 描述 availability_zones Array of AvailableZone objects 可用区列表 request_id String 请求ID 表4 AvailableZone 参数 参数类型 描述 code String 可用区编码 state String 可用区是否可用available|unavailable
  • 响应参数 状态码: 200 表2 响应Body参数 参数 参数类型 描述 vpc_attachment VpcAttachmentDetails object VPC类型连接 request_id String 请求id 表3 VpcAttachmentDetails 参数 参数类型 描述 id String VPC连接ID name String VPC连接名称 vpc_id String VPC id virsubnet_id String VPC子网id auto_create_vpc_routes Boolean 默认为false,当设置true时,会自动为VPC配置10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16三条路由,下一跳指向企业路由器。 缺省值:false state String VPC连接状态:pending|available|modifying|deleting|deleted|failed|initiating_request|rejected|pending_acceptance|freezed created_at String 创建时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ updated_at String 更新时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ tags Array of Tag objects 标签信息 description String VPC连接描述信息 project_id String 项目ID vpc_project_id String vpc所属项目ID 表4 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 { "vpc_attachment" : { "id" : "b70aee08-c671-4cad-9fd5-7381d163bcc8", "name" : "vpc-attach", "vpc_id" : "b715e131-3371-4e17-a2de-4f669e24439a", "virsubnet_id" : "aacdc21d-90f9-45ef-ab48-80ec1bbe15b8", "project_id" : "08d5a9564a704afda6039ae2babbef3c", "state" : "available", "created_at" : "2020-03-11T15:13:31Z", "updated_at" : "2020-03-11T15:13:31Z" }, "request_id" : "915a14a6-867b-4af7-83d1-70efceb146f9" }
  • 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 ShowVpcAttachmentSolution { 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(); ShowVpcAttachmentRequest request = new ShowVpcAttachmentRequest(); try { ShowVpcAttachmentResponse response = client.showVpcAttachment(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 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 = ShowVpcAttachmentRequest() response = client.show_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 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.ShowVpcAttachmentRequest{} response, err := client.ShowVpcAttachment(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • URI GET /v3/{project_id}/enterprise-router/{er_id}/flow-logs 表1 路径参数 参数 是否必选 参数类型 描述 project_id 是 String 项目ID er_id 是 String 企业路由器实例ID 表2 Query参数 参数 是否必选 参数类型 描述 resource_type 否 String 采集的资源类型 resource_id 否 Array 连接对应的资源ID列表 limit 否 Integer 每页返回的个数。 取值范围:0~2000。 最小值:0 最大值:2000 marker 否 String 查询的页码id,为空时为查询第一页。 使用说明:必须与limit一起使用。 最小长度:1 最大长度:128 sort_key 否 Array 按关键字排序,默认按照id排序,可选值:id|name|state sort_dir 否 Array 返回结果按照升序或降序排列,默认为asc,降序为desc
  • 响应示例 状态码: 200 OK { "flow_logs" : [ { "id" : "b216bc1d-5963-41a7-89f9-779a5128c5ac", "name" : "flow_log", "project_id" : "0605767a9980d5762fbcc00b3537e757", "resource_type" : "attachment", "resource_id" : "6f83b848-8331-4271-ac0c-ef94b7686402", "log_group_id" : "0139393c-eeb2-49f0-bbd4-c5faec6b1497", "log_stream_id" : "d22c3b44-2f71-470f-83f3-96a8af6956ad", "log_store_type" : "LTS", "log_aggregation_interval" : 600, "created_at" : "2020-03-11T15:13:31Z", "updated_at" : "2022-03-11T15:13:31Z", "state" : "available", "enabled" : true, "description" : "ER流日志" } ], "page_info" : { "next_marker" : "1", "current_count" : 1 }, "request_id" : "915a14a6-867b-4af7-83d1-70efceb146f9" }
  • 响应参数 状态码: 200 表3 响应Body参数 参数 参数类型 描述 flow_logs Array of FlowLog objects 流日志详情 request_id String 请求ID total_count Long 总计数量 page_info PageInfo object 分页查询的信息 表4 FlowLog 参数 参数类型 描述 id String 流日志ID name String 流日志名称 description String 流日志描述 project_id String 流日志任务创建者项目ID resource_type String 采集的资源类型:attachment resource_id String 采集的资源ID log_group_id String 日志组ID log_stream_id String 日志流ID log_store_type String 流日志存储类型:LTS log_aggregation_interval Integer 日志聚合时间,单位s,取值范围:60-600 created_at String 创建时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ updated_at String 更新时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ state String 日志资源状态:pending|available|modifying|deleting|deleted|failed enabled Boolean 日志开关:true|false 表5 PageInfo 参数 参数类型 描述 next_marker String 下一个marker标识,为空时表示最后一页 current_count Integer 当前列表中资源数量
  • 基本概念 账号 用户注册时的账号,账号对其所拥有的资源及云服务具有完全的访问权限,可以重置用户密码、分配用户权限等。由于账号是付费主体,为了确保账号安全,建议您不要直接使用账号进行日常管理工作,而是创建用户并使用用户进行日常管理工作。 用户 由账号在IAM中创建的用户,是云服务的使用人员,具有身份凭证(密码和访问密钥)。 在我的凭证下,您可以查看账号ID和IAM用户ID。通常在调用API的鉴权过程中,您需要用到账号、用户和密码等信息。 区域(Region) 从地理位置和网络时延维度划分,同一个Region内共享弹性计算、块存储、对象存储、VPC网络、弹性公网IP、镜像等公共服务。Region分为通用Region和专属Region,通用Region指面向公共租户提供通用云服务的Region;专属Region指只承载同一类业务或只面向特定租户提供业务服务的专用Region。 详情请参见区域和可用区。 可用区(AZ,Availability Zone) 一个可用区是一个或多个物理数据中心的集合,有独立的风火水电,AZ内逻辑上再将计算、网络、存储等资源划分成多个集群。一个Region中的多个AZ间通过高速光纤相连,以满足用户跨AZ构建高可用性系统的需求。 项目 区域默认对应一个项目,这个项目由系统预置,用来隔离物理区域间的资源(计算资源、存储资源和网络资源),以默认项目为单位进行授权,用户可以访问您账号中该区域的所有资源。如果您希望进行更加精细的权限控制,可以在区域默认的项目中创建子项目,并在子项目中创建资源,然后以子项目为单位进行授权,使得用户仅能访问特定子项目中的资源,使得资源的权限控制更加精确。 图1 项目隔离模型 同样在我的凭证下,您可以查看项目ID。 企业项目 企业项目是项目的升级版,针对企业不同项目间的资源进行分组和管理,是逻辑隔离。企业项目中可以包含多个区域的资源,且项目中的资源可以迁入迁出。 关于企业项目ID的获取及企业项目特性的详细信息,请参见《企业管理用户指南》。 父主题: 使用前必读
  • 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 ShowStaticRouteSolution { 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(); ShowStaticRouteRequest request = new ShowStaticRouteRequest(); try { ShowStaticRouteResponse response = client.showStaticRoute(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 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 = ShowStaticRouteRequest() response = client.show_static_route(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.ShowStaticRouteRequest{} response, err := client.ShowStaticRoute(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
  • 响应示例 状态码: 200 OK { "route" : { "id" : "19d334b7-78c1-4e0e-ba29-b797e641e23c", "type" : "static", "destination" : "192.168.0.0/16", "description" : "static route", "attachments" : [ { "resource_id" : "9c4ab06a-0ab4-4fad-93a8-f733f3a4433d", "resource_type" : "VPC", "attachment_id" : "9b3b38a9-1c9d-4f01-9429-81af6b545289" } ], "route_table_id" : "19d334b7-78c1-4e0e-ba29-b797e641e23c", "is_blackhole" : false, "state" : "pending", "created_at" : "2020-03-11T15:13:31", "updated_at" : "2020-03-11T15:13:31" }, "request_id" : "915a14a6-867b-4af7-83d1-70efceb146f9" }
  • 响应参数 状态码: 200 表2 响应Body参数 参数 参数类型 描述 route Route object 路由表项 request_id String 请求ID 表3 Route 参数 参数类型 描述 id String 路由id type String 路由类型:static state String 路由状态:pending|available|modifying|deleting|deleted|failed is_blackhole Boolean 是否为黑洞路由 destination String 路由目的地址 attachments Array of RouteAttachment objects 下一跳列表 route_table_id String 路由表id created_at String 创建时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ updated_at String 更新时间,格式:YYYY-MM-DDTHH:mm:ss.sssZ 表4 RouteAttachment 参数 参数类型 描述 resource_id String 连接关联的资源ID resource_type String 连接关联的资源类型: vpc:虚拟私有云 vpn:vpn网关 vgw:云专线的虚拟网关 peering:对等连接,通过云连接CC加载不同区域的企业路由器来创建“对等连接(Peering)”连接 attachment_id String 连接ID
  • AK/SK认证 AK/SK签名认证方式仅支持消息体大小在12MB以内,12MB以上的请求请使用Token认证。 AK/SK认证就是使用AK/SK对请求进行签名,在请求时将签名信息添加到消息头,从而通过身份认证。 AK(Access Key ID):访问密钥ID。与私有访问密钥关联的唯一标识符;访问密钥ID和私有访问密钥一起使用,对请求进行加密签名。 SK(Secret Access Key):私有访问密钥。与访问密钥ID结合使用,对请求进行加密签名,可标识发送方,并防止请求被修改。 使用AK/SK认证时,您可以基于签名算法使用AK/SK对请求进行签名,也可以使用专门的签名SDK对请求进行签名。详细的签名方法和SDK使用方法请参见API签名指南。 签名SDK只提供签名功能,与服务提供的SDK不同,使用时请注意。
  • Token认证 Token的有效期为24小时,需要使用一个Token鉴权时,可以先缓存起来,避免频繁调用。 Token在计算机系统中代表令牌(临时)的意思,拥有Token就代表拥有某种权限。Token认证就是在调用API的时候将Token加到请求消息头中,从而通过身份认证,获得操作API的权限。Token可通过调用获取用户Token接口获取。 调用本服务API需要项目级别的Token,即调用获取用户Token接口时,请求body中auth.scope的取值需要选择project,如下所示。 { "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", //IAM用户名 "password": "********", //IAM用户密码 "domain": { "name": "domainname" //IAM用户所属帐号名 } } } }, "scope": { "project": { "name": "xxxxxxxx" //项目名称 } } } } 获取Token后,再调用其他接口时,您需要在请求消息头中添加“X-Auth-Token”,其值即为Token。例如Token值为“ABCDEFJ....”,则调用接口时将“X-Auth-Token: ABCDEFJ....”加到请求消息头即可,如下所示。 1 2 3 POST https://iam.cn-north-1.myhuaweicloud.com/v3/auth/projects Content-Type: application/json X-Auth-Token: ABCDEFJ.... 您还可以通过这个视频教程了解如何使用Token认证:https://bbs.huaweicloud.com/videos/101333。
  • Python 创建一个企业路由器,名称为“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 # 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 = CreateEnterpriseRouterRequest() listAvailabilityZoneIdsInstance = [ "az1", "az2" ] listTagsInstance = [ Tag( key="key1", value="value1" ) ] instancebody = CreateEnterpriseRouter( name="my_er", description="this is my first enterprise router", asn=64512, tags=listTagsInstance, enable_default_propagation=True, enable_default_association=True, availability_zone_ids=listAvailabilityZoneIdsInstance ) request.body = CreateEnterpriseRouterRequestBody( instance=instancebody ) response = client.create_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)
  • 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) } }
共100000条