更新辅助弹性网卡
功能介绍
当您的辅助弹性网卡创建成功后,您可以通过调用该接口更新辅助弹性网卡的基本信息,例如辅助弹性网卡关联的安全组、描述信息等。
调用方法
请参见如何调用API。
URI
PUT /v3/{project_id}/vpc/sub-network-interfaces/{sub_network_interface_id}
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 辅助弹性网卡所属的项目ID。获取方式请参见获取项目ID。 取值范围: 不涉及。 |
sub_network_interface_id |
是 |
String |
参数解释: 辅助弹性网卡的资源ID。 取值范围: 不涉及。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
dry_run |
否 |
Boolean |
参数解释: 是否只预检此次请求。 约束限制: 不涉及。 取值范围:
默认取值: false |
sub_network_interface |
是 |
参数解释: 更新辅助弹性网卡的请求体。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
description |
否 |
String |
参数解释: 辅助弹性网卡的描述信息。 约束限制: 0-255个字符,不能包含“<”和“>”。 取值范围: 不涉及。 默认取值: 不涉及。 |
security_groups |
否 |
Array of strings |
参数解释: 辅助弹性网卡关联的安全组的ID列表。例如:"security_groups": ["a0608cbf-d047-4f54-8b28-cd7b59853fff"]。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
allowed_address_pairs |
否 |
Array of AllowedAddressPair objects |
参数解释: 辅助弹性网卡的IP/Mac对列表,详情请参见“AllowedAddressPair”对象表。 约束限制:
取值范围: 不涉及。 默认取值: 不涉及。 |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
request_id |
String |
参数解释: 请求ID。 取值范围: 不涉及。 |
sub_network_interface |
SubNetworkInterface object |
参数解释: 更新辅助弹性网卡的响应体。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
id |
String |
参数解释: 辅助弹性网卡的资源ID。辅助弹性网卡创建成功后,会生成一个辅助弹性网卡 ID,是辅助弹性网卡对应的唯一标识。 取值范围: 带“-”的标准UUID格式。 |
virsubnet_id |
String |
参数解释: 辅助弹性网卡所在的虚拟子网ID。 取值范围: 带“-”的标准UUID格式。 |
private_ip_address |
String |
参数解释: 辅助弹性网卡的私有IPv4地址。 取值范围: 不涉及。 |
ipv6_ip_address |
String |
参数解释: 辅助弹性网卡的私有IPv6地址。 取值范围: 不涉及。 |
mac_address |
String |
参数解释: 辅助弹性网卡的MAC地址。 取值范围: 合法的MAC地址,系统随机分配。 |
parent_device_id |
String |
参数解释: 辅助弹性网卡的宿主网卡所属的设备ID。 取值范围: 带“-”的标准UUID格式。 |
parent_id |
String |
参数解释: 辅助弹性网卡所挂载的弹性网卡的ID。 取值范围: 带“-”的标准UUID格式。 |
description |
String |
参数解释: 辅助弹性网卡的描述信息。 取值范围: 0-255个字符,不能包含“<”和“>”。 |
vpc_id |
String |
参数解释: 辅助弹性网卡所属VPC的ID。 取值范围: 带“-”的标准UUID格式。 |
vlan_id |
Integer |
参数解释: 辅助弹性网卡的VLAN ID。 取值范围: 1-4094 |
security_groups |
Array of strings |
参数解释: 辅助弹性网卡关联的安全组的ID列表。例如:"security_groups": ["a0608cbf-d047-4f54-8b28-cd7b59853fff"]。 取值范围: 如果请求时不指定此参数,辅助弹性网卡创建后会自动关联默认安全组。 |
tags |
Array of ResponseTag objects |
参数解释: 辅助弹性网卡的标签信息,包括标签键和标签值,可用来分类和标识资源。详情请参见Tag对象。 取值范围: 不涉及。 |
project_id |
String |
参数解释: 辅助弹性网卡所属的项目ID。 取值范围: 不涉及。 |
created_at |
String |
参数解释: 辅助弹性网卡的创建时间。 取值范围: UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。 |
allowed_address_pairs |
Array of AllowedAddressPair objects |
参数解释: 辅助弹性网卡的IP/Mac对列表,详情请参见“AllowedAddressPair”对象表。 取值范围: 不涉及。 |
state |
String |
参数解释: 辅助弹性网卡的状态。 取值范围:
|
instance_id |
String |
参数解释: 辅助弹性网卡所属的云服务实例ID,例如RDS实例ID。 取值范围: 不涉及。 |
instance_type |
String |
参数解释: 辅助弹性网卡所属的云服务实例类型,例如“RDS”。 取值范围: 不涉及。 |
scope |
String |
参数解释: 辅助弹性网卡所在站点的公网出口信息。 取值范围:
|
security_enabled |
Boolean |
参数解释: 辅助弹性网卡安全使能标记,如果不使能则安全组不生效。 取值范围: 不涉及。 |
请求示例
更新id为2be868f2-f7c9-48db-abc0-eea0b9105b0d的辅助弹性网卡,更新关联的安全组列表。
PUT https://{Endpoint}/v3/8c6fb137a48a428aaf9a0229dca4edb3/vpc/sub-network-interfaces/2be868f2-f7c9-48db-abc0-eea0b9105b0d { "sub_network_interface" : { "security_groups" : [ "6727c950-9f01-47a2-a7aa-7d3686c4c95b" ], "allowed_address_pairs" : [ { "ip_address" : "1.1.1.1/0" } ] } }
响应示例
状态码:200
PUT操作正常返回,更多状态码请参见状态码。
{ "sub_network_interface" : { "id" : "2be868f2-f7c9-48db-abc0-eea0b9105b0d", "project_id" : "6b32266bded64091a138e9ec19cff361", "virsubnet_id" : "3c15c3b0-0df4-4115-9c18-e67a8a0d7702", "private_ip_address" : "192.168.0.160", "ipv6_ip_address" : null, "mac_address" : "fa:16:3e:26:7e:1e", "parent_device_id" : "285b2e45-2968-4f4c-8992-54e0d4c8da1d", "security_enabled" : false, "security_groups" : [ "6727c950-9f01-47a2-a7aa-7d3686c4c95b" ], "allowed_address_pairs" : [ { "ip_address" : "1.1.1.1/0", "mac_address" : "fa:16:3e:26:7e:1e" } ], "vpc_id" : "c10e1e02-9db2-4bd0-89ef-52536952627e", "instance_id" : "", "instance_type" : "", "description" : "aaa", "parent_id" : "00336617-4552-48c5-9856-f539f4e9aca2", "vlan_id" : 3413, "state" : null, "tags" : [ ], "scope" : "center", "created_at" : "2025-02-10T08:21:16Z" }, "request_id" : "d346a69661d82c7b14bdc7ac0cd62cbd" }
SDK代码示例
SDK代码示例如下。
更新id为2be868f2-f7c9-48db-abc0-eea0b9105b0d的辅助弹性网卡,更新关联的安全组列表。
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 |
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.vpc.v3.region.VpcRegion; import com.huaweicloud.sdk.vpc.v3.*; import com.huaweicloud.sdk.vpc.v3.model.*; import java.util.List; import java.util.ArrayList; public class UpdateSubNetworkInterfaceSolution { 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); VpcClient client = VpcClient.newBuilder() .withCredential(auth) .withRegion(VpcRegion.valueOf("<YOUR REGION>")) .build(); UpdateSubNetworkInterfaceRequest request = new UpdateSubNetworkInterfaceRequest(); request.withSubNetworkInterfaceId("{sub_network_interface_id}"); UpdateSubNetworkInterfaceRequestBody body = new UpdateSubNetworkInterfaceRequestBody(); List<AllowedAddressPair> listSubNetworkInterfaceAllowedAddressPairs = new ArrayList<>(); listSubNetworkInterfaceAllowedAddressPairs.add( new AllowedAddressPair() .withIpAddress("1.1.1.1/0") ); List<String> listSubNetworkInterfaceSecurityGroups = new ArrayList<>(); listSubNetworkInterfaceSecurityGroups.add("6727c950-9f01-47a2-a7aa-7d3686c4c95b"); UpdateSubNetworkInterfaceOption subNetworkInterfacebody = new UpdateSubNetworkInterfaceOption(); subNetworkInterfacebody.withSecurityGroups(listSubNetworkInterfaceSecurityGroups) .withAllowedAddressPairs(listSubNetworkInterfaceAllowedAddressPairs); body.withSubNetworkInterface(subNetworkInterfacebody); request.withBody(body); try { UpdateSubNetworkInterfaceResponse response = client.updateSubNetworkInterface(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()); } } } |
更新id为2be868f2-f7c9-48db-abc0-eea0b9105b0d的辅助弹性网卡,更新关联的安全组列表。
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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkvpc.v3.region.vpc_region import VpcRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkvpc.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 = VpcClient.new_builder() \ .with_credentials(credentials) \ .with_region(VpcRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateSubNetworkInterfaceRequest() request.sub_network_interface_id = "{sub_network_interface_id}" listAllowedAddressPairsSubNetworkInterface = [ AllowedAddressPair( ip_address="1.1.1.1/0" ) ] listSecurityGroupsSubNetworkInterface = [ "6727c950-9f01-47a2-a7aa-7d3686c4c95b" ] subNetworkInterfacebody = UpdateSubNetworkInterfaceOption( security_groups=listSecurityGroupsSubNetworkInterface, allowed_address_pairs=listAllowedAddressPairsSubNetworkInterface ) request.body = UpdateSubNetworkInterfaceRequestBody( sub_network_interface=subNetworkInterfacebody ) response = client.update_sub_network_interface(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
更新id为2be868f2-f7c9-48db-abc0-eea0b9105b0d的辅助弹性网卡,更新关联的安全组列表。
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 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" vpc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/vpc/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 := vpc.NewVpcClient( vpc.VpcClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.UpdateSubNetworkInterfaceRequest{} request.SubNetworkInterfaceId = "{sub_network_interface_id}" ipAddressAllowedAddressPairs:= "1.1.1.1/0" var listAllowedAddressPairsSubNetworkInterface = []model.AllowedAddressPair{ { IpAddress: &ipAddressAllowedAddressPairs, }, } var listSecurityGroupsSubNetworkInterface = []string{ "6727c950-9f01-47a2-a7aa-7d3686c4c95b", } subNetworkInterfacebody := &model.UpdateSubNetworkInterfaceOption{ SecurityGroups: &listSecurityGroupsSubNetworkInterface, AllowedAddressPairs: &listAllowedAddressPairsSubNetworkInterface, } request.Body = &model.UpdateSubNetworkInterfaceRequestBody{ SubNetworkInterface: subNetworkInterfacebody, } response, err := client.UpdateSubNetworkInterface(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
PUT操作正常返回,更多状态码请参见状态码。 |
错误码
请参见错误码。