Updated on 2024-08-12 GMT+08:00

Create Firewall

Function

This API is used to create firewall.

Calling Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/firewall

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is a token.

X-Client-Token

No

String

An identity that guarantees the idempotency of client requests. The identifier is in 32-bit UUID format, generated by the client, and must be unique between requests.

X-Trace-Id

No

String

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Firewall Name

enterprise_project_id

No

String

Enterprise project id, the id generated by the enterprise project after the user supports the enterprise project.

Default: 0

tags

No

Array of tags objects

Resource Tag

flavor

Yes

flavor object

flavor

charge_info

Yes

charge_info object

Billing type information, prepaid and postpaid, the default is postpaid.

Table 4 tags

Parameter

Mandatory

Type

Description

key

No

String

Tag Key

value

No

String

Tag Value

Table 5 flavor

Parameter

Mandatory

Type

Description

version

Yes

String

Firewall version: If charge_mode is set to prePaid, only the Professional Edition is supported, and when charge_mode is set to postPaid, the Standard and Professional Editions are supported.

Enumeration values:

  • Standard

  • Professional

extend_eip_count

No

Integer

Expand the number of EIPs and take effect only in the prepaid mode.

Minimum: 0

Maximum: 2000

Default: 0

extend_bandwidth

No

Integer

Expand band width and take effect only in the prepaid mode.

Minimum: 0

Maximum: 5000

extend_vpc_count

No

Integer

Expand the number of VPCs and take effect only in the prepaid mode.

Minimum: 0

Maximum: 100

Table 6 charge_info

Parameter

Mandatory

Type

Description

charge_mode

Yes

String

The billing mode can be prepaid, i.e., yearly/monthly, and postPaid: postpaid, i.e., pay-per-use.

period_type

No

String

The value range of the subscription cycle,include monthly and yearly. Note: This parameter takes effect when charge_mode is set to prePaid, and the value is required.

period_num

No

Integer

the time of the subscription, take effect when charge_mode is prePaid and it is required, value range: 1~9 when period_type is set to month, and 1~3 when period_type is set to year.

is_auto_renew

Yes

Boolean

whether the firewall instance is auto renewed

Default: false

is_auto_pay

Yes

Boolean

whether the firewall instance is auto paid

Default: false

Response Parameters

Status code: 200

Table 7 Response body parameters

Parameter

Type

Description

job_id

String

The job id, created when the firewall instance is created, which is returned only when the billing mode is postpaid.

order_id

String

Order id,which is returned when the firewall instance is created.

data

CreateFirewallReq object

Create Firewall Request

Table 8 CreateFirewallReq

Parameter

Type

Description

name

String

Firewall Name

enterprise_project_id

String

Enterprise project id, the id generated by the enterprise project after the user supports the enterprise project.

Default: 0

tags

Array of tags objects

Resource Tag

flavor

flavor object

flavor

charge_info

charge_info object

Billing type information, prepaid and postpaid, the default is postpaid.

Table 9 tags

Parameter

Type

Description

key

String

Tag Key

value

String

Tag Value

Table 10 flavor

Parameter

Type

Description

version

String

Firewall version: If charge_mode is set to prePaid, only the Professional Edition is supported, and when charge_mode is set to postPaid, the Standard and Professional Editions are supported.

Enumeration values:

  • Standard

  • Professional

extend_eip_count

Integer

Expand the number of EIPs and take effect only in the prepaid mode.

Minimum: 0

Maximum: 2000

Default: 0

extend_bandwidth

Integer

Expand band width and take effect only in the prepaid mode.

Minimum: 0

Maximum: 5000

extend_vpc_count

Integer

Expand the number of VPCs and take effect only in the prepaid mode.

Minimum: 0

Maximum: 100

Table 11 charge_info

Parameter

Type

Description

charge_mode

String

The billing mode can be prepaid, i.e., yearly/monthly, and postPaid: postpaid, i.e., pay-per-use.

period_type

String

The value range of the subscription cycle,include monthly and yearly. Note: This parameter takes effect when charge_mode is set to prePaid, and the value is required.

period_num

Integer

the time of the subscription, take effect when charge_mode is prePaid and it is required, value range: 1~9 when period_type is set to month, and 1~3 when period_type is set to year.

is_auto_renew

Boolean

whether the firewall instance is auto renewed

Default: false

is_auto_pay

Boolean

whether the firewall instance is auto paid

Default: false

Status code: 400

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code

Minimum: 8

Maximum: 36

error_msg

String

Description

Minimum: 2

Maximum: 512

Example Requests

Enable a standard firewall with 2000 extended EIP, 5,000 Mbps extended protection bandwidth, 100 extended protection VCPs under a monthly billing auto-renewal model.

https://{Endpoint}/v2/124147da-5b08-471a-93d2-bc82acc290c6/firewall

{
  "name" : "CFW-TEST",
  "enterprise_project_id" : "0",
  "tags" : [ {
    "key" : "TagKey",
    "value" : "TagVal"
  } ],
  "flavor" : {
    "version" : "standard",
    "extend_eip_count" : 2000,
    "extend_bandwidth" : 5000,
    "extend_vpc_count" : 100
  },
  "charge_info" : {
    "charge_mode" : "prePaid",
    "period_type" : "month",
    "period_num" : 1,
    "is_auto_renew" : true,
    "is_auto_pay" : true
  }
}

Example Responses

Status code: 200

Create Firewall Response

{
  "data" : {
    "charge_info" : {
      "charge_mode" : "prePaid",
      "is_auto_pay" : true,
      "is_auto_renew" : true,
      "period_num" : 1,
      "period_type" : "month"
    },
    "enterprise_project_id" : "0",
    "flavor" : {
      "extend_bandwidth" : 5000,
      "extend_eip_count" : 2000,
      "extend_vpc_count" : 100,
      "version" : "Standard"
    },
    "name" : "CFW-TEST",
    "tags" : [ {
      "key" : "TagKey",
      "value" : "TagVal"
    } ]
  },
  "order_id" : "CS2403271050ZEM0L"
}

Status code: 400

Bad Request

{
  "error_code" : "CFW.00100001",
  "error_msg" : "The system is busy. Please try again later."
}

SDK Sample Code

The SDK sample code is as follows.

Java

Enable a standard firewall with 2000 extended EIP, 5,000 Mbps extended protection bandwidth, 100 extended protection VCPs under a monthly billing auto-renewal model.

 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
64
65
66
67
68
69
70
71
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.cfw.v1.region.CfwRegion;
import com.huaweicloud.sdk.cfw.v1.*;
import com.huaweicloud.sdk.cfw.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateFirewallSolution {

    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");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        CfwClient client = CfwClient.newBuilder()
                .withCredential(auth)
                .withRegion(CfwRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateFirewallRequest request = new CreateFirewallRequest();
        CreateFirewallReq body = new CreateFirewallReq();
        CreateFirewallReqChargeInfo chargeInfobody = new CreateFirewallReqChargeInfo();
        chargeInfobody.withChargeMode("prePaid")
            .withPeriodType("month")
            .withPeriodNum(1)
            .withIsAutoRenew(true)
            .withIsAutoPay(true);
        CreateFirewallReqFlavor flavorbody = new CreateFirewallReqFlavor();
        flavorbody.withVersion(CreateFirewallReqFlavor.VersionEnum.fromValue("standard"))
            .withExtendEipCount(2000)
            .withExtendBandwidth(5000)
            .withExtendVpcCount(100);
        List<CreateFirewallReqTags> listbodyTags = new ArrayList<>();
        listbodyTags.add(
            new CreateFirewallReqTags()
                .withKey("TagKey")
                .withValue("TagVal")
        );
        body.withChargeInfo(chargeInfobody);
        body.withFlavor(flavorbody);
        body.withTags(listbodyTags);
        body.withEnterpriseProjectId("0");
        body.withName("CFW-TEST");
        request.withBody(body);
        try {
            CreateFirewallResponse response = client.createFirewall(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());
        }
    }
}

Python

Enable a standard firewall with 2000 extended EIP, 5,000 Mbps extended protection bandwidth, 100 extended protection VCPs under a monthly billing auto-renewal model.

 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
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcfw.v1.region.cfw_region import CfwRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcfw.v1 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"]

    credentials = BasicCredentials(ak, sk)

    client = CfwClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CfwRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateFirewallRequest()
        chargeInfobody = CreateFirewallReqChargeInfo(
            charge_mode="prePaid",
            period_type="month",
            period_num=1,
            is_auto_renew=True,
            is_auto_pay=True
        )
        flavorbody = CreateFirewallReqFlavor(
            version="standard",
            extend_eip_count=2000,
            extend_bandwidth=5000,
            extend_vpc_count=100
        )
        listTagsbody = [
            CreateFirewallReqTags(
                key="TagKey",
                value="TagVal"
            )
        ]
        request.body = CreateFirewallReq(
            charge_info=chargeInfobody,
            flavor=flavorbody,
            tags=listTagsbody,
            enterprise_project_id="0",
            name="CFW-TEST"
        )
        response = client.create_firewall(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

Enable a standard firewall with 2000 extended EIP, 5,000 Mbps extended protection bandwidth, 100 extended protection VCPs under a monthly billing auto-renewal model.

 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
64
65
66
67
68
69
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    cfw "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := cfw.NewCfwClient(
        cfw.CfwClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateFirewallRequest{}
	periodTypeChargeInfo:= "month"
	periodNumChargeInfo:= int32(1)
	chargeInfobody := &model.CreateFirewallReqChargeInfo{
		ChargeMode: "prePaid",
		PeriodType: &periodTypeChargeInfo,
		PeriodNum: &periodNumChargeInfo,
		IsAutoRenew: true,
		IsAutoPay: true,
	}
	extendEipCountFlavor:= int32(2000)
	extendBandwidthFlavor:= int32(5000)
	extendVpcCountFlavor:= int32(100)
	flavorbody := &model.CreateFirewallReqFlavor{
		Version: model.GetCreateFirewallReqFlavorVersionEnum().STANDARD,
		ExtendEipCount: &extendEipCountFlavor,
		ExtendBandwidth: &extendBandwidthFlavor,
		ExtendVpcCount: &extendVpcCountFlavor,
	}
	keyTags:= "TagKey"
	valueTags:= "TagVal"
	var listTagsbody = []model.CreateFirewallReqTags{
        {
            Key: &keyTags,
            Value: &valueTags,
        },
    }
	enterpriseProjectIdCreateFirewallReq:= "0"
	request.Body = &model.CreateFirewallReq{
		ChargeInfo: chargeInfobody,
		Flavor: flavorbody,
		Tags: &listTagsbody,
		EnterpriseProjectId: &enterpriseProjectIdCreateFirewallReq,
		Name: "CFW-TEST",
	}
	response, err := client.CreateFirewall(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

More

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

200

Create Firewall Response

400

Bad Request

Error Codes

See Error Codes.