更新时间:2024-07-01 GMT+08:00
分享

创建WAF独享引擎实例

功能介绍

创建WAF独享引擎实例。独享模式支持的局点包括:华东-青岛、中东-利雅得、华北-北京一、华北-北京四、华北-乌兰察布一、华东-上海一、华东-上海二、华南-广州、华南-深圳、中国-香港、西南-贵阳一、亚太-曼谷、 亚太-新加坡、非洲-约翰内斯堡、土耳其-伊斯坦布尔;普通租户类独享支持的局点:华北-北京四、华东-上海一、华南-广州、中国-香港、亚太-曼谷、亚太-新加坡。

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/premium-waf/instance

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,对应控制台用户名->我的凭证->项目列表->项目ID

表2 Query参数

参数

是否必选

参数类型

描述

enterprise_project_id

String

您可以通过调用企业项目管理服务(EPS)的查询企业项目列表接口(ListEnterpriseProject)查询企业项目id

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token,通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

Content-Type

String

内容类型

表4 请求Body参数

参数

是否必选

参数类型

描述

chargemode

Integer

收费模式,当前仅支持按需收费(30)

region

String

需要创建独享引擎的局点,例如:北京四(cn-north-4)

available_zone

String

需要创建独享引擎的可用区,例如:北京四可用区1(cn-north-4a)

arch

String

独享引擎CPU架构,仅支持x86

instancename

String

独享引擎名称前缀

specification

String

独享引擎版本规格

  • waf.instance.enterprise:企业版,对应控制台WI-500规格

  • waf.instance.professional:专业版,对应控制台WI-100规格

cpu_flavor

String

独享引擎ECS规格,实例规格。创建资源租户类独享引擎可不填该参数,创建普通资源租户独享引擎必填该参数。普通租户类独享引擎具体支持的规格以waf控制台上支持的规格为准。

vpc_id

String

独享引擎所在VPC的ID

subnet_id

String

独享引擎所在VPC内的子网ID

security_group

Array of strings

独享引擎需要绑定的安全组ID

count

Integer

申请的独享引擎数量

res_tenant

Boolean

是否为资源租户类,默认值为false。

  • true: 资源租户类

  • false: 普通租户类

anti_affinity

Boolean

是否开启反亲和。仅资源租户独享实例支持该特性。

响应参数

状态码: 200

表5 响应Body参数

参数

参数类型

描述

instances

Array of instanceInfo objects

instances

表6 instanceInfo

参数

参数类型

描述

id

String

引擎实例ID

name

String

引擎实例名称

状态码: 400

表7 响应Body参数

参数

参数类型

描述

error_code

String

错误码

error_msg

String

错误信息

状态码: 401

表8 响应Body参数

参数

参数类型

描述

error_code

String

错误码

error_msg

String

错误信息

状态码: 500

表9 响应Body参数

参数

参数类型

描述

error_code

String

错误码

error_msg

String

错误信息

请求示例

在项目id为project_id的项目中创建WAF独享引擎实例,WAF独享引擎实例的收费模式为按需收费,需要创建独享引擎的局点为“region-01-4”,创建独享引擎的可用区为“region-01-4a”,独享引擎CPU架构为“x86”,独享引擎名称前缀为“demo”,独享引擎版本规格为企业版,独享引擎所在VPC的ID为"d7b6a5ff-6c53-4cd4-9d57-f20ee8753056",独享引擎所在VPC内的子网ID为“e59ccd18-7e15-4588-b689-04b856f4e78b”,独享引擎需要绑定的安全组ID为“09b156a2-f0f0-41fd-9891-60e594601cfd”,数量为一个,是 资源租户类。

POST https://{endpoint}/v1/{project_id}/premium-waf/instance

{
  "chargemode" : 30,
  "region" : "region-01-4",
  "available_zone" : "region-01-4a",
  "arch" : "x86",
  "instancename" : "demo",
  "specification" : "waf.instance.enterprise",
  "vpc_id" : "d7b6a5ff-6c53-4cd4-9d57-f20ee8753056",
  "subnet_id" : "e59ccd18-7e15-4588-b689-04b856f4e78b",
  "security_group" : [ "09b156a2-f0f0-41fd-9891-60e594601cfd" ],
  "count" : 1,
  "res_tenant" : true
}

响应示例

状态码: 200

独享引擎信息

{
  "instances" : [ {
    "id" : "50a6b6c9bdb643f9a8038976fc58ad02",
    "name" : "demo-6wvl"
  } ]
}

SDK代码示例

SDK代码示例如下。

在项目id为project_id的项目中创建WAF独享引擎实例,WAF独享引擎实例的收费模式为按需收费,需要创建独享引擎的局点为“region-01-4”,创建独享引擎的可用区为“region-01-4a”,独享引擎CPU架构为“x86”,独享引擎名称前缀为“demo”,独享引擎版本规格为企业版,独享引擎所在VPC的ID为"d7b6a5ff-6c53-4cd4-9d57-f20ee8753056",独享引擎所在VPC内的子网ID为“e59ccd18-7e15-4588-b689-04b856f4e78b”,独享引擎需要绑定的安全组ID为“09b156a2-f0f0-41fd-9891-60e594601cfd”,数量为一个,是 资源租户类。

 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
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.waf.v1.region.WafRegion;
import com.huaweicloud.sdk.waf.v1.*;
import com.huaweicloud.sdk.waf.v1.model.*;

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

public class CreateInstanceSolution {

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

        WafClient client = WafClient.newBuilder()
                .withCredential(auth)
                .withRegion(WafRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateInstanceRequest request = new CreateInstanceRequest();
        CreateInstanceRequestBody body = new CreateInstanceRequestBody();
        List<String> listbodySecurityGroup = new ArrayList<>();
        listbodySecurityGroup.add("09b156a2-f0f0-41fd-9891-60e594601cfd");
        body.withResTenant(true);
        body.withCount(1);
        body.withSecurityGroup(listbodySecurityGroup);
        body.withSubnetId("e59ccd18-7e15-4588-b689-04b856f4e78b");
        body.withVpcId("d7b6a5ff-6c53-4cd4-9d57-f20ee8753056");
        body.withSpecification("waf.instance.enterprise");
        body.withInstancename("demo");
        body.withArch("x86");
        body.withAvailableZone("region-01-4a");
        body.withRegion("region-01-4");
        body.withChargemode(30);
        request.withBody(body);
        try {
            CreateInstanceResponse response = client.createInstance(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为project_id的项目中创建WAF独享引擎实例,WAF独享引擎实例的收费模式为按需收费,需要创建独享引擎的局点为“region-01-4”,创建独享引擎的可用区为“region-01-4a”,独享引擎CPU架构为“x86”,独享引擎名称前缀为“demo”,独享引擎版本规格为企业版,独享引擎所在VPC的ID为"d7b6a5ff-6c53-4cd4-9d57-f20ee8753056",独享引擎所在VPC内的子网ID为“e59ccd18-7e15-4588-b689-04b856f4e78b”,独享引擎需要绑定的安全组ID为“09b156a2-f0f0-41fd-9891-60e594601cfd”,数量为一个,是 资源租户类。

 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 huaweicloudsdkwaf.v1.region.waf_region import WafRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkwaf.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"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

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

    try:
        request = CreateInstanceRequest()
        listSecurityGroupbody = [
            "09b156a2-f0f0-41fd-9891-60e594601cfd"
        ]
        request.body = CreateInstanceRequestBody(
            res_tenant=True,
            count=1,
            security_group=listSecurityGroupbody,
            subnet_id="e59ccd18-7e15-4588-b689-04b856f4e78b",
            vpc_id="d7b6a5ff-6c53-4cd4-9d57-f20ee8753056",
            specification="waf.instance.enterprise",
            instancename="demo",
            arch="x86",
            available_zone="region-01-4a",
            region="region-01-4",
            chargemode=30
        )
        response = client.create_instance(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为project_id的项目中创建WAF独享引擎实例,WAF独享引擎实例的收费模式为按需收费,需要创建独享引擎的局点为“region-01-4”,创建独享引擎的可用区为“region-01-4a”,独享引擎CPU架构为“x86”,独享引擎名称前缀为“demo”,独享引擎版本规格为企业版,独享引擎所在VPC的ID为"d7b6a5ff-6c53-4cd4-9d57-f20ee8753056",独享引擎所在VPC内的子网ID为“e59ccd18-7e15-4588-b689-04b856f4e78b”,独享引擎需要绑定的安全组ID为“09b156a2-f0f0-41fd-9891-60e594601cfd”,数量为一个,是 资源租户类。

 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    waf "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/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")
    projectId := "{project_id}"

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

    client := waf.NewWafClient(
        waf.WafClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateInstanceRequest{}
	var listSecurityGroupbody = []string{
        "09b156a2-f0f0-41fd-9891-60e594601cfd",
    }
	resTenantCreateInstanceRequestBody:= true
	chargemodeCreateInstanceRequestBody:= int32(30)
	request.Body = &model.CreateInstanceRequestBody{
		ResTenant: &resTenantCreateInstanceRequestBody,
		Count: int32(1),
		SecurityGroup: listSecurityGroupbody,
		SubnetId: "e59ccd18-7e15-4588-b689-04b856f4e78b",
		VpcId: "d7b6a5ff-6c53-4cd4-9d57-f20ee8753056",
		Specification: "waf.instance.enterprise",
		Instancename: "demo",
		Arch: "x86",
		AvailableZone: "region-01-4a",
		Region: "region-01-4",
		Chargemode: &chargemodeCreateInstanceRequestBody,
	}
	response, err := client.CreateInstance(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

独享引擎信息

400

请求失败

401

token权限不足

500

服务器内部错误

错误码

请参见错误码

相关文档