更新时间:2025-08-19 GMT+08:00

更新流量镜像筛选条件

功能介绍

更新流量镜像筛选条件

调用方法

请参见如何调用API

URI

PUT /v3/{project_id}/vpc/traffic-mirror-filters/{traffic_mirror_filter_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

流量镜像筛选条件所属的项目ID。获取方式请参见获取项目ID

取值范围

不涉及。

traffic_mirror_filter_id

String

参数解释

流量镜像筛选条件的资源ID。

取值范围

不涉及。

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

traffic_mirror_filter

UpdateTrafficMirrorFilterOption object

流量镜像筛选条件对象

表3 UpdateTrafficMirrorFilterOption

参数

是否必选

参数类型

描述

description

String

功能说明:流量镜像筛选条件的描述信息

取值范围:0-255个字符,不能包含“<”和“>”

name

String

功能说明:流量镜像筛选条件的名称

取值范围:1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点)

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

traffic_mirror_filter

TrafficMirrorFilter object

参数解释

查询流量镜像筛选条件详情的响应体。

取值范围

不涉及。

request_id

String

参数解释

请求ID。

取值范围

不涉及。

表5 TrafficMirrorFilter

参数

参数类型

描述

id

String

参数解释

流量镜像筛选条件的资源D。流量镜像筛选条件创建成功后,会生成一个流量镜像筛选条件 ID,是流量镜像筛选条件对应的唯一标识。

取值范围

不涉及。

project_id

String

参数解释

流量镜像筛选条件所属的项目ID。

取值范围

不涉及。

description

String

参数解释

流量镜像筛选条件的描述信息。

取值范围

0-255个字符,不能包含“<”和“>”

name

String

参数解释

流量镜像筛选条件的名称。

取值范围

1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点)。

ingress_rules

Array of TrafficMirrorFilterRule objects

参数解释

流量镜像筛选条件中的入方向筛选规则列表。

取值范围

不涉及。

egress_rules

Array of TrafficMirrorFilterRule objects

参数解释

流量镜像筛选条件中的出方向筛选规则列表。

取值范围

不涉及。

created_at

String

参数解释

流量镜像筛选条件的创建时间。

取值范围

UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

updated_at

String

参数解释

流量镜像筛选条件的更新时间。

取值范围

UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

type

String

参数解释

流量镜像筛选条件的镜像源类型。

取值范围

  • eni:弹性网卡

表6 TrafficMirrorFilterRule

参数

参数类型

描述

id

String

参数解释

流量镜像筛选规则的资源ID。

取值范围

不涉及。

project_id

String

参数解释

流量镜像筛选规则所属的项目ID。

取值范围

不涉及。

description

String

参数解释

流量镜像筛选规则的描述信息。

取值范围

0-255个字符,不能包含“<”和“>”。

traffic_mirror_filter_id

String

参数解释

流量镜像筛选规则所在流量镜像筛选条件的ID。

取值范围

不涉及。

direction

String

参数解释

流量镜像筛选规则的流量方向。

取值范围

  • ingress:入方向。

  • egress:出方向。

source_cidr_block

String

参数解释

流量镜像筛选规则的源地址。

取值范围

  • 单个IP地址:IP地址/掩码,单个IPv4地址示例为192.168.10.10/32,单个IPv6地址示例为2002:50::44/128。

  • IP网段:IP地址/掩码,IPv4网段示例为192.168.52.0/24,IPv6网段示例为2407:c080:802:469::/64。

  • 所有IP地址:0.0.0.0/0表示匹配所有IPv4地址,::/0表示匹配所有IPv6地址。

destination_cidr_block

String

参数解释

流量镜像筛选规则的目的地址。

取值范围

  • 单个IP地址:IP地址/掩码,单个IPv4地址示例为192.168.10.10/32,单个IPv6地址示例为2002:50::44/128。

  • IP网段:IP地址/掩码,IPv4网段示例为192.168.52.0/24,IPv6网段示例为2407:c080:802:469::/64。

  • 所有IP地址:0.0.0.0/0表示匹配所有IPv4地址,::/0表示匹配所有IPv6地址。

source_port_range

String

参数解释

流量镜像筛选规则的源端口范围。

取值范围

  • 端口取值范围是1~65535。

  • 使用中划线(-)连接起始端口和结束端口,即“起始端口-结束端口”,结束端口取值应大于等于起始端口,例如22-23。

destination_port_range

String

参数解释

流量镜像筛选规则的目的端口范围。

取值范围

  • 端口取值范围是1~65535。

  • 使用中划线(-)连接起始端口和结束端口,即“起始端口-结束端口”,结束端口取值应大于等于起始端口,例如22-23。

ethertype

String

参数解释

流量支持的IP地址类型。

取值范围

IPv4,IPv6

protocol

String

参数解释

流量支持的网络协议类型。

取值范围

  • TCP:选择TCP协议,可以自定义源端口范围和目的端口范围。

  • UDP:选择UDP协议,可以自定义源端口范围和目的端口范围。

  • ICMP:“IP类型”选择“IPv4”时,可选择ICMP协议,源端口范围和目的端口范围默认为全部端口。

  • ICMPV6:“IP类型”选择“IPv6”时,可选择ICMPV6协议,源端口范围和目的端口范围默认为全部端口。

  • ALL:表示支持全部网络协议,源端口范围和目的端口范围默认为全部端口。

action

String

参数解释

流量镜像筛选规则的流量采集策略。

取值范围

  • accept:采集。

  • reject:不采集。

priority

Integer

参数解释

流量镜像筛选规则的优先级。

取值范围

1~65535,数字越小,优先级越高。

created_at

String

参数解释

流量镜像筛选规则的创建时间。

取值范围

UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

updated_at

String

参数解释

流量镜像筛选规则的更新时间。

取值范围

UTC时间格式,yyyy-MM-ddTHH:mm:ssZ。

请求示例

更新ID为59d2b2e7-0d35-41f7-a12e-f7699366cd21的流量镜像筛选条件,名称更新为test1

PUT /v3/{project_id}/vpc/traffic-mirror-filters/59d2b2e7-0d35-41f7-a12e-f7699366cd21

{
  "traffic_mirror_filter" : {
    "name" : "test1",
    "description" : "description"
  }
}

响应示例

状态码:200

OK

{
  "traffic_mirror_filter" : {
    "id" : "59d2b2e7-0d35-41f7-a12e-f7699366cd21",
    "project_id" : "49a42f378df747bf8b8f6a70e25b63fb",
    "name" : "test1",
    "description" : "description",
    "ingress_rules" : [ ],
    "egress_rules" : [ ],
    "created_at" : "2022-08-29T06:22:01.000+00:00",
    "updated_at" : "2022-08-29T06:22:01.000+00:00"
  },
  "request_id" : "f05abcd9-fa75-43a5-a795-b3d8e8b7a9e9"
}

SDK代码示例

SDK代码示例如下。

更新ID为59d2b2e7-0d35-41f7-a12e-f7699366cd21的流量镜像筛选条件,名称更新为test1

 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 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.*;


public class UpdateTrafficMirrorFilterSolution {

    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();
        UpdateTrafficMirrorFilterRequest request = new UpdateTrafficMirrorFilterRequest();
        request.withTrafficMirrorFilterId("{traffic_mirror_filter_id}");
        UpdateTrafficMirrorFilterRequestBody body = new UpdateTrafficMirrorFilterRequestBody();
        UpdateTrafficMirrorFilterOption trafficMirrorFilterbody = new UpdateTrafficMirrorFilterOption();
        trafficMirrorFilterbody.withDescription("description")
            .withName("test1");
        body.withTrafficMirrorFilter(trafficMirrorFilterbody);
        request.withBody(body);
        try {
            UpdateTrafficMirrorFilterResponse response = client.updateTrafficMirrorFilter(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为59d2b2e7-0d35-41f7-a12e-f7699366cd21的流量镜像筛选条件,名称更新为test1

 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
# 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 = UpdateTrafficMirrorFilterRequest()
        request.traffic_mirror_filter_id = "{traffic_mirror_filter_id}"
        trafficMirrorFilterbody = UpdateTrafficMirrorFilterOption(
            description="description",
            name="test1"
        )
        request.body = UpdateTrafficMirrorFilterRequestBody(
            traffic_mirror_filter=trafficMirrorFilterbody
        )
        response = client.update_traffic_mirror_filter(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为59d2b2e7-0d35-41f7-a12e-f7699366cd21的流量镜像筛选条件,名称更新为test1

 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
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.UpdateTrafficMirrorFilterRequest{}
	request.TrafficMirrorFilterId = "{traffic_mirror_filter_id}"
	descriptionTrafficMirrorFilter:= "description"
	nameTrafficMirrorFilter:= "test1"
	trafficMirrorFilterbody := &model.UpdateTrafficMirrorFilterOption{
		Description: &descriptionTrafficMirrorFilter,
		Name: &nameTrafficMirrorFilter,
	}
	request.Body = &model.UpdateTrafficMirrorFilterRequestBody{
		TrafficMirrorFilter: trafficMirrorFilterbody,
	}
	response, err := client.UpdateTrafficMirrorFilter(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

错误码

请参见错误码