公网NAT网关按需转包 - UpdateNatGatewayToPeriod
功能介绍
公网NAT网关按需转包。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/nat_gateways/{nat_gateway_id}/change_to_period
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
project_id |
是 |
String |
项目的ID。 |
|
nat_gateway_id |
是 |
String |
公网NAT网关实例的ID。 |
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
prepaid_options |
否 |
PrepaidOptions object |
支付属性 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
period_type |
是 |
String |
订购周期类型,当前支持包月和包年: month: 包月 year: 包年 |
|
period_num |
是 |
Integer |
订购周期数,取值会随运营策略变化。 period_type为month时,为[1,9], period_type为year时,为[1,3] |
|
is_auto_renew |
否 |
Boolean |
是否自动续订; true:自动续订 false:不自动续订 |
|
is_auto_pay |
否 |
Boolean |
下单订购后,是否自动从客户的账户中支付; true:自动支付 false:不自动支付。 |
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
order_id |
String |
订单ID。 |
请求示例
POST https://{NAT_endpoint}/v2/70505c941b9b4dfd82fd351932328a2f/nat_gateways/e1cacb3c-46a0-4c8e-9c4a-91eb63635f62/change_to_period
{
"prepaid_options" : {
"period_type" : "month",
"period_num" : 1,
"is_auto_renew" : false,
"is_auto_pay" : true
}
}
响应示例
状态码:200
公网NAT网关按需转包成功。
{
"order_id" : "CS2304211201WYELB"
}
SDK代码示例
SDK代码示例如下。
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 |
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.nat.v2.region.NatRegion; import com.huaweicloud.sdk.nat.v2.*; import com.huaweicloud.sdk.nat.v2.model.*; public class UpdateNatGatewayToPeriodSolution { 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); NatClient client = NatClient.newBuilder() .withCredential(auth) .withRegion(NatRegion.valueOf("<YOUR REGION>")) .build(); UpdateNatGatewayToPeriodRequest request = new UpdateNatGatewayToPeriodRequest(); request.withNatGatewayId("{nat_gateway_id}"); UpdateNatGatewayToPeriodRequestBody body = new UpdateNatGatewayToPeriodRequestBody(); PrepaidOptions prepaidOptionsbody = new PrepaidOptions(); prepaidOptionsbody.withPeriodType(PrepaidOptions.PeriodTypeEnum.fromValue("month")) .withPeriodNum(1) .withIsAutoRenew(false) .withIsAutoPay(true); body.withPrepaidOptions(prepaidOptionsbody); request.withBody(body); try { UpdateNatGatewayToPeriodResponse response = client.updateNatGatewayToPeriod(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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdknat.v2.region.nat_region import NatRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdknat.v2 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 = NatClient.new_builder() \ .with_credentials(credentials) \ .with_region(NatRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateNatGatewayToPeriodRequest() request.nat_gateway_id = "{nat_gateway_id}" prepaidOptionsbody = PrepaidOptions( period_type="month", period_num=1, is_auto_renew=False, is_auto_pay=True ) request.body = UpdateNatGatewayToPeriodRequestBody( prepaid_options=prepaidOptionsbody ) response = client.update_nat_gateway_to_period(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 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" nat "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/nat/v2/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 := nat.NewNatClient( nat.NatClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.UpdateNatGatewayToPeriodRequest{} request.NatGatewayId = "{nat_gateway_id}" isAutoRenewPrepaidOptions:= false isAutoPayPrepaidOptions:= true prepaidOptionsbody := &model.PrepaidOptions{ PeriodType: model.GetPrepaidOptionsPeriodTypeEnum().MONTH, PeriodNum: int32(1), IsAutoRenew: &isAutoRenewPrepaidOptions, IsAutoPay: &isAutoPayPrepaidOptions, } request.Body = &model.UpdateNatGatewayToPeriodRequestBody{ PrepaidOptions: prepaidOptionsbody, } response, err := client.UpdateNatGatewayToPeriod(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
公网NAT网关按需转包成功。 |
错误码
请参见错误码。