端口移除安全组
功能介绍
端口移除安全组。
调用方法
请参见如何调用API。
URI
PUT /v3/{project_id}/ports/{port_id}/remove-security-groups
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
port_id |
是 |
String |
端口的唯一标识。 |
project_id |
是 |
String |
项目ID。 获取方式请参见获取项目ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
port |
是 |
RemoveSecurityGroupOption object |
端口移除安全组请求体 |
响应参数
状态码: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 |
Object |
功能描述:vif的详细信息, "ovs_hybrid_plug",表示是否为ovs/bridge混合模式。 |
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 |
功能描述:设备所属(DHCP/Router/ lb/Nova)。 |
ecs_flavor |
String |
功能描述:标识这个端口所属虚拟机的flavor。 |
id |
String |
功能描述:端口唯一标识。 取值范围:标准UUID。 |
instance_id |
String |
功能描述:端口所属实例ID,例如RDS实例ID。 约束:不支持设置和更新,由系统自动维护。 |
instance_type |
String |
功能描述:端口所属实例类型,例如“RDS”。 约束:不支持设置和更新,由系统自动维护。 |
mac_address |
String |
功能描述:MAC地址。 |
name |
String |
功能描述:端口名称。 取值范围:默认为空,最大长度不超过255。 |
port_security_enabled |
Boolean |
功能描述:端口安全使能标记,如果不使能则安全组和dhcp防欺骗不生效。 取值范围:true/false。 |
private_ips |
Array of PrivateIpInfo objects |
功能描述:port的私有IP地址。 |
project_id |
String |
功能描述:项目ID。 |
security_groups |
Array of strings |
功能描述:安全组列表。 |
status |
String |
功能描述:端口状态。 取值范围:ACTIVE,BUILD,DOWN。 |
tenant_id |
String |
功能描述:租户ID。 |
virsubnet_id |
String |
功能描述:所属网络ID。 取值范围:标准UUID。 |
vpc_id |
String |
功能描述:VPC的ID。 取值范围:标准UUID。 |
vpc_tenant_id |
String |
功能描述:VPC_租户ID。 取值范围:UUID。 |
vtep_ip |
String |
功能描述:本地IP。 |
enable_efi |
Boolean |
功能描述:是否使能efi,使能则表示端口支持vRoCE能力。 取值范围:true,false。 |
scope |
String |
功能描述:作用域。 取值范围:
默认值:center。 |
zone_id |
String |
功能描述:端口所属的可用分区。 |
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 strings |
功能描述:端口标签。 |
allowed_address_pairs |
Array of AllowedAddressPair objects |
功能描述:IP/Mac对列表。 约束:
|
请求示例
指定端口移除安全组,移除端口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操作正常返回,更多状态码请参见状态码。 |
错误码
请参见错误码。