端口移除安全组
功能介绍
当您需要调整云服务器实例关联的安全组,您可以通过调用该接口从弹性网卡绑定的安全组列表中移除安全组。
调用方法
请参见如何调用API。
URI
PUT /v3/{project_id}/ports/{port_id}/remove-security-groups
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
port_id |
是 |
String |
参数解释: 端口的资源ID,可以是弹性网卡的资源ID。 取值范围: 不涉及。 |
project_id |
是 |
String |
参数解释: 项目ID。获取方式请参见获取项目ID。 取值范围: 不涉及。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
port |
是 |
RemoveSecurityGroupOption object |
参数解释: 端口移除安全组的请求体。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
dry_run |
否 |
Boolean |
参数解释: 是否只预检此次请求。 约束限制: 不涉及。 取值范围:
默认取值: false |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
security_groups |
是 |
Array of strings |
参数解释: 待移除的安全组的ID列表,例如:"security_groups": ["a0608cbf-d047-4f54-8b28-cd7b59853fff"]。您可以先通过查询安全组列表API获取目标安全组ID,再使用当前API从弹性网卡绑定的安全组列表中移除安全组。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
request_id |
String |
参数解释: 请求ID。 取值范围: 不涉及。 |
port |
Port object |
参数解释: 端口移除安全组的响应体。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
admin_state_up |
Boolean |
参数解释: 端口的管理状态。 取值范围: true,false,默认值true。 |
binding:host_id |
String |
参数解释: 端口所在的主机ID。 取值范围: 不涉及。 |
binding:profile |
Object |
参数解释: 端口的用户自定义信息。 取值范围: 不涉及。 |
binding:vif_details |
binding:vif_details object |
参数解释: VIF的详细信息。 取值范围: 不涉及。 |
binding:vif_type |
String |
参数解释: 端口的接口类型 (ovs/hw_veb等),扩展属性。 取值范围: 不涉及。 |
binding:vnic_type |
String |
参数解释: 绑定的vNIC类型。 取值范围:
|
created_at |
String |
参数解释: 端口的创建时间。 取值范围: UTC时间,格式: yyyy-MM-ddTHH:mm:ss。 |
updated_at |
String |
参数解释: 端口的最近一次更新的时间。 取值范围: UTC时间,格式: yyyy-MM-ddTHH:mm:ss。 |
description |
String |
参数解释: 端口的描述信息。 取值范围: 0-255个字符,不能包含“<”和“>”。 |
device_id |
String |
参数解释: 端口所属的设备ID。 取值范围: 带“-”的标准UUID格式。 |
device_owner |
String |
参数解释: 端口所属的设备名称。 取值范围:
|
ecs_flavor |
String |
参数解释: 标识此端口所属云服务器的flavor。 取值范围: 不涉及。 |
id |
String |
参数解释: 端口的资源ID。 取值范围: 带“-”的标准UUID格式。 |
instance_id |
String |
参数解释: 端口所属的云服务实例ID,例如RDS实例ID。 取值范围: 不涉及。 |
instance_type |
String |
参数解释: 端口所属的云服务实例类型,例如“RDS”。 取值范围: 不涉及。 |
mac_address |
String |
参数解释: 端口的MAC地址。 取值范围: 不涉及 |
name |
String |
参数解释: 端口的名称。 取值范围: 默认为空,最大长度不超过255。 |
port_security_enabled |
Boolean |
参数解释: 端口的安全使能标记,如果不使能,则安全组和DHCP防欺骗不生效。 取值范围:
|
private_ips |
Array of PrivateIpInfo objects |
参数解释: 端口的私有IP地址。 取值范围: 不涉及。 |
project_id |
String |
参数解释: 端口所属的项目ID。 取值范围: 不涉及。 |
security_groups |
Array of strings |
参数解释: 端口绑定的安全组列表。 取值范围: 不涉及。 |
status |
String |
参数解释: 端口的状态。 取值范围:
|
tenant_id |
String |
参数解释: 端口所属的租户ID。 取值范围: 不涉及。 |
virsubnet_id |
String |
参数解释: 端口所在的虚拟子网ID。 取值范围: 带“-”的标准UUID格式。 |
vpc_id |
String |
参数解释: 端口所在的VPC的ID。 取值范围: 带“-”的标准UUID格式。 |
vpc_tenant_id |
String |
参数解释: 端口所在的VPC的租户ID。 取值范围: 不涉及。 |
vtep_ip |
String |
参数解释: 端口的VTEP IP地址,即虚拟隧道端点的 IP 地址。 取值范围: 不涉及。 |
enable_efi |
Boolean |
参数解释: 是否使能efi,使能则表示端口支持vRoCE能力。 取值范围:
|
scope |
String |
参数解释: 端口所在子网的作用域(边缘云场景)。 取值范围:
|
zone_id |
String |
参数解释: 端口所属的可用分区的ID。 取值范围: 不涉及。 |
binding:migration_info |
Object |
参数解释: 端口迁移的目的节点信息,包括目的节点的binding:vif_details和binding:vif_type。 取值范围: 不涉及。 |
extra_dhcp_opts |
Array of ExtraDhcpOpt objects |
参数解释: DHCP的扩展属性。 取值范围: 不涉及。 |
position_type |
String |
参数解释: 边缘场景端口的位置类型。 取值范围: 默认值center。 |
instance_info |
Object |
参数解释: 端口绑定的实例信息。 取值范围: 不涉及。 |
tags |
Array of ResponseTag objects |
参数解释: 端口的标签信息,包括标签键和标签值,可用来分类和标识资源。详情请参见Tag对象。 取值范围: 不涉及。 |
allowed_address_pairs |
Array of AllowedAddressPair objects |
参数解释: 端口的IP/Mac对列表。 取值范围:
|
参数 |
参数类型 |
描述 |
---|---|---|
primary_interface |
Boolean |
参数解释: 表示该网卡是否为云服务器的主网卡。 取值范围:
|
port_filter |
Boolean |
参数解释: 表示该网络服务提供端口过滤特性,如安全组和反MAC/IP欺骗。 取值范围:
|
ovs_hybrid_plug |
Boolean |
参数解释: 是否为ovs/bridge混合模式。 取值范围:
|
参数 |
参数类型 |
描述 |
---|---|---|
subnet_cidr_id |
String |
参数解释: 端口所属的子网ID。 取值范围: 不涉及。 |
ip_address |
String |
参数解释: 端口的私有IP地址。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
opt_name |
String |
参数解释: DHCP属性名称。在DHCP服务器为客户端分配IP地址时,传递的额外的控制信息或网络配置参数的名称。 取值范围: 不涉及。 |
opt_value |
String |
参数解释: DHCP属性值。在DHCP服务器为客户端分配IP地址时,传递的额外的控制信息或网络配置参数的值。 取值范围: 不涉及。 |
请求示例
指定端口移除安全组,移除端口99fd0c77-56b4-4bf6-8365-df352e45d5fc关联的安全组8edd3747-ccd4-49a1-82b9-a165eec314b4、6c2d4540-3b7d-4207-a319-a7231b439995。
PUT https://{Endpoint}/v3/f5dab68cd75740e68c599e9af5fe0aed/ports/99fd0c77-56b4-4bf6-8365-df352e45d5fc/remove-security-groups { "port" : { "security_groups" : [ "8edd3747-ccd4-49a1-82b9-a165eec314b4", "6c2d4540-3b7d-4207-a319-a7231b439995" ] } }
响应示例
状态码:200
PUT操作正常返回,更多状态码请参见状态码。
{ "port" : { "name" : "", "id" : "99fd0c77-56b4-4bf6-8365-df352e45d5fc", "admin_state_up" : true, "status" : "DOWN", "project_id" : "f5dab68cd75740e68c599e9af5fe0aed", "device_id" : "", "mac_address" : "fa:16:3e:1f:17:df", "device_owner" : "", "description" : "", "zone_id" : "", "scope" : "center", "position_type" : "center", "created_at" : "2023-05-10T01:35:02.000+00:00", "updated_at" : "2023-05-10T01:35:02.000+00:00", "port_security_enabled" : true, "tags" : [ ], "security_groups" : [ "567be4e3-d171-46ce-9e8a-c15e91cfe86a", "4940b983-5992-4663-bed9-d1d1e15d1009" ], "allowed_address_pairs" : [ ], "extra_dhcp_opts" : [ ], "instance_id" : "", "instance_type" : "", "ecs_flavor" : "", "enable_efi" : false, "virsubnet_id" : "3847b263-2370-45c0-8236-38a1de568049", "private_ips" : [ { "subnet_cidr_id" : "ffe98087-6d4f-45cd-988b-1c87f75d2d53", "ip_address" : "192.168.158.228" } ], "binding:host_id" : "", "binding:vif_type" : "unbound", "binding:vnic_type" : "normal", "binding:vif_details" : { }, "binding:profile" : { }, "binding:migration_info" : { } }, "request_id" : "abd08c76-c853-4967-a898-12804330efab" }
SDK代码示例
SDK代码示例如下。
指定端口移除安全组,移除端口99fd0c77-56b4-4bf6-8365-df352e45d5fc关联的安全组8edd3747-ccd4-49a1-82b9-a165eec314b4、6c2d4540-3b7d-4207-a319-a7231b439995。
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 |
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 RemoveSecurityGroupsSolution { 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(); RemoveSecurityGroupsRequest request = new RemoveSecurityGroupsRequest(); request.withPortId("{port_id}"); RemoveSecurityGroupsRequestBody body = new RemoveSecurityGroupsRequestBody(); List<String> listPortSecurityGroups = new ArrayList<>(); listPortSecurityGroups.add("8edd3747-ccd4-49a1-82b9-a165eec314b4"); listPortSecurityGroups.add("6c2d4540-3b7d-4207-a319-a7231b439995"); RemoveSecurityGroupOption portbody = new RemoveSecurityGroupOption(); portbody.withSecurityGroups(listPortSecurityGroups); body.withPort(portbody); request.withBody(body); try { RemoveSecurityGroupsResponse response = client.removeSecurityGroups(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()); } } } |
指定端口移除安全组,移除端口99fd0c77-56b4-4bf6-8365-df352e45d5fc关联的安全组8edd3747-ccd4-49a1-82b9-a165eec314b4、6c2d4540-3b7d-4207-a319-a7231b439995。
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 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 = RemoveSecurityGroupsRequest() request.port_id = "{port_id}" listSecurityGroupsPort = [ "8edd3747-ccd4-49a1-82b9-a165eec314b4", "6c2d4540-3b7d-4207-a319-a7231b439995" ] portbody = RemoveSecurityGroupOption( security_groups=listSecurityGroupsPort ) request.body = RemoveSecurityGroupsRequestBody( port=portbody ) response = client.remove_security_groups(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
指定端口移除安全组,移除端口99fd0c77-56b4-4bf6-8365-df352e45d5fc关联的安全组8edd3747-ccd4-49a1-82b9-a165eec314b4、6c2d4540-3b7d-4207-a319-a7231b439995。
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 |
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.RemoveSecurityGroupsRequest{} request.PortId = "{port_id}" var listSecurityGroupsPort = []string{ "8edd3747-ccd4-49a1-82b9-a165eec314b4", "6c2d4540-3b7d-4207-a319-a7231b439995", } portbody := &model.RemoveSecurityGroupOption{ SecurityGroups: listSecurityGroupsPort, } request.Body = &model.RemoveSecurityGroupsRequestBody{ Port: portbody, } response, err := client.RemoveSecurityGroups(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
PUT操作正常返回,更多状态码请参见状态码。 |
错误码
请参见错误码。