Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating a Backend Server Group

Function

This API is used to create a backend server group.

Constraints

Note the following when you create a backend server group:

  • If session-persistence is specified, cookie_name is available only when type is set to APP_COOKIE.

  • If listener_id is specified, the listener must have no backend server group associated.

Calling Method

For details, see Calling APIs.

URI

POST /v3/{project_id}/elb/pools

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the token used for IAM authentication.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

pool

Yes

CreatePoolOption object

Specifies the request body for creating a backend server group.

Table 4 CreatePoolOption

Parameter

Mandatory

Type

Description

admin_state_up

No

Boolean

Specifies the administrative status of the backend server group. The value can only be true.

description

No

String

Provides supplementary information about the backend server group.

lb_algorithm

Yes

String

Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group.

Value options:

  • ROUND_ROBIN: weighted round robin

  • LEAST_CONNECTIONS: weighted least connections

  • SOURCE_IP: source IP hash

  • QUIC_CID: connection ID

listener_id

No

String

Specifies the ID of the listener with which the backend server group is associated.

Note:

  • At least one of listener_id, loadbalancer_id, or type must be specified.

  • Either listener_id or loadbalancer_id must be specified for shared load balancers. listener_id and loadbalancer_id are not required for dedicated load balancers.

loadbalancer_id

No

String

Specifies the ID of the load balancer with which the backend server group is associated.

Note:

  • Specify one of listener_id, loadbalancer_id, or type, or all of them.

  • Specify either listener_id or loadbalancer_id for backend server groups of shared load balancers. listener_id and loadbalancer_id are not required for backend server groups of dedicated load balancers.

name

No

String

Specifies the backend server group name.

project_id

No

String

Specifies the project ID of the backend server group.

protocol

Yes

String

Specifies the protocol used by the backend server group to receive requests.

The value can be TCP, UDP, TLS, HTTP, HTTPS, GRPC, or QUIC.

Note:

  • If the listener's protocol is UDP, the protocol of the backend server group must be UDP or QUIC.

  • If the listener's protocol is TCP, the protocol of the backend server group must be TCP.

  • If the listener's protocol is HTTP, the protocol of the backend server group must be HTTP.

  • If the listener's protocol is HTTPS, the protocol of the backend server group can be HTTP, HTTPS, or GRPC.

  • If the listener's protocol is TERMINATED_HTTPS, the protocol of the backend server group must be HTTP.

  • If the listener's protocol is QUIC, the protocol of the backend server group can be HTTP, HTTPS, or GRPC.

  • If the listener's protocol is TLS, the protocol of the backend server group can be TLS or TCP. If protocol of the backend server group is TCP, the ip_version must be set to v4.

Note:

  • If protocol of the backend server group is QUIC, session_persistence must be set to true, with type set to SOURCE_IP.

  • If protocol of the backend server group is GRPC, http2_enable of the listener must be set to true.

session_persistence

No

CreatePoolSessionPersistenceOption object

Specifies the sticky session.

slow_start

No

CreatePoolSlowStartOption object

Specifies slow start details. After you enable slow start, new backend servers added to the backend server group are warmed up, and the number of requests they can receive increases linearly during the configured slow start duration.

Note: This parameter can be used when the protocol of the backend server group is HTTP or HTTPS.

member_deletion_protection_enable

No

Boolean

Specifies whether to enable deletion protection.

Value options:

  • true: Enable deletion protection.

  • false (default): Disable deletion protection.

NOTE:

Disable deletion protection for all your resources before deleting your account.

vpc_id

No

String

Specifies the ID of the VPC where the backend server group works.

Note:

  • The backend server group must be associated with the VPC.

  • Only backend servers in the VPC or IP as backend servers can be added.

  • type must be set to instance.

  • If vpc_id is not specified, vpc_id is determined by the VPC where the backend server works.

type

No

String

Specifies the type of the backend server group.

Value options:

  • instance: Any type of backend servers can be added. vpc_id is mandatory.

  • ip: Only IP as backend servers can be added. vpc_id cannot be specified.

Note:

  • If this parameter is not passed, any type of backend servers can be added. type will be returned as an empty string.

  • Specify one of listener_id, loadbalancer_id, or type. For backend server groups of shared load balancers, specify loadbalancer_id or listener_id.

ip_version

No

String

Specifies the IP address version supported by the backend server group.

  • Shared load balancers: The value is fixed at v4.

  • Dedicated load balancers: The value can be dualstack or v4. If the protocol of the backend server group is TCP or UDP, the value is dualstack. If the protocol of the backend server group is HTTP, the value is v4.

protection_status

No

String

Specifies the protection status.

Value options:

  • nonProtection (default): The load balancer is not protected.

  • consoleProtection: Modification Protection is enabled on the console.

protection_reason

No

String

Specifies why the modification protection is enabled.

Note: This parameter is valid only when protection_status is set to consoleProtection. The value can contain a maximum of 255 Unicode characters, excluding angle brackets (<>).

any_port_enable

No

Boolean

Specifies whether to enable any_port_enable for a backend server group. If this option is enabled, the listener routes the requests to the backend server over the same port as the frontend port. If this option is disabled, the listener routes the requests over the port specified by protocol_port.

Value options:

  • false: Disable this option.

  • true: Enable this option.

Note: This option is available only for TCP, UDP, or QUIC backend server groups.

connection_drain

No

ConnectionDrain object

Specifies the configurations of deregistration delay. This parameter is only available for TCP, UDP, and QUIC backend server groups and TCP and UDP listeners.

This parameter takes effect when:

  • A backend server is removed from a backend server group.

  • A backend server is detected unhealthy or health checks fail.

  • The weight of a backend server is 0.

pool_health

No

PoolHealth object

Specifies the configurations of the pool health feature.

public_border_group

No

String

Specifies the public border group, for example, center.

quic_cid_hash_strategy

No

QuicCidHashStrategy object

Specifies multi-path forwarding configuration based on destination connection IDs.

Table 5 CreatePoolSessionPersistenceOption

Parameter

Mandatory

Type

Description

cookie_name

No

String

Specifies the cookie name.

Note:

  • This parameter will take effect only when type is set to APP_COOKIE. Otherwise, an error will be returned.

Value ranges:

  • For shared load balancers, the name can contain a maximum of 64 characters, including letters, digits, underscores (_), and hyphens (-).

  • For dedicated load balancers, the name can contain a maximum of 255 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).

type

Yes

String

Specifies the sticky session type.

The value can be SOURCE_IP, HTTP_COOKIE, or APP_COOKIE.

Note:

  • If the protocol of the backend server group is TCP or UDP, only SOURCE_IP takes effect.

  • If the protocol of the backend server group is HTTP or HTTPS, the value can be HTTP_COOKIE or APP_COOKIE.

  • If the backend server group protocol is QUIC, sticky session must be enabled with type set to SOURCE_IP.

persistence_timeout

No

Integer

Specifies the stickiness duration, in minutes. This parameter will not take effect when type is set to APP_COOKIE.

Value ranges:

  • If the protocol of the backend server group is TCP or UDP, the value ranges from 1 to 60, and the default value is 1.

  • If the protocol of the backend server group is HTTP or HTTPS, the value ranges from 1 to 1440, and the default value is 1440.

Table 6 CreatePoolSlowStartOption

Parameter

Mandatory

Type

Description

enable

No

Boolean

Specifies whether to enable slow start.

  • true: Enable slow start.

  • false (default): Disable slow start.

duration

No

Integer

Specifies the slow start duration, in seconds.

The value ranges from 30 to 1200, and the default value is 30.

Table 7 ConnectionDrain

Parameter

Mandatory

Type

Description

enable

No

Boolean

Specifies whether to enable connection_drain.

Value options:

  • true: Enable this option.

  • false: Disable this option.

    Default value: true

timeout

No

Integer

Specifies the deregistration delay timeout, in seconds. The value ranges from 10 to 4000.

Table 8 PoolHealth

Parameter

Mandatory

Type

Description

minimum_healthy_member_count

No

Integer

If the number of healthy backend servers is less than the value specified for this parameter, the backend server group is considered as unhealthy.

The value can be 0 (disabled) or 1 (enabled).

Table 9 QuicCidHashStrategy

Parameter

Mandatory

Type

Description

len

Yes

Integer

Specifies the length of the hash factor in the connection ID, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 1 to 20

Default value: 3

offset

Yes

Integer

Specifies the start position in the connection ID as the hash factor, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 0 to 19

Default value: 1

Response Parameters

Status code: 201

Table 10 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID.

Note: The value is automatically generated.

pool

Pool object

Specifies the backend server group.

Table 11 Pool

Parameter

Type

Description

admin_state_up

Boolean

Specifies the administrative status of the backend server group.

description

String

Provides supplementary information about the backend server group.

healthmonitor_id

String

Specifies the ID of the health check configured for the backend server group.

id

String

Specifies the backend server group ID.

lb_algorithm

String

Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group.

Value options:

  • ROUND_ROBIN: weighted round robin

  • LEAST_CONNECTIONS: weighted least connections

  • SOURCE_IP: source IP hash

  • QUIC_CID: connection ID

listeners

Array of ListenerRef objects

Specifies the IDs of the listeners with which the backend server group is associated.

loadbalancers

Array of LoadBalancerRef objects

Specifies the IDs of the load balancers with which the backend server group is associated.

members

Array of MemberRef objects

Specifies the IDs of the backend servers in the backend server group.

name

String

Specifies the backend server group name.

project_id

String

Specifies the project ID.

protocol

String

Specifies the protocol used by the backend server group to receive requests.

The value can be TCP, UDP, TLS, HTTP, HTTPS, GRPC, or QUIC.

Note:

  • If the listener's protocol is UDP, the protocol of the backend server group must be UDP or QUIC.

  • If the listener's protocol is TCP, the protocol of the backend server group must be TCP.

  • If the listener's protocol is HTTP, the protocol of the backend server group must be HTTP.

  • If the listener's protocol is HTTPS, the protocol of the backend server group can be HTTP, HTTPS, or GRPC.

  • If the listener's protocol is TERMINATED_HTTPS, the protocol of the backend server group must be HTTP.

  • If the listener's protocol is QUIC, the protocol of the backend server group can be HTTP, HTTPS, or GRPC.

  • If the listener's protocol is TLS, the protocol of the backend server group can be TLS or TCP. If protocol of the backend server group is TCP, the ip_version must be set to v4.

Note:

  • If protocol of the backend server group is QUIC, session_persistence must be set to true, with type set to SOURCE_IP.

  • If protocol of the backend server group is GRPC, http2_enable of the listener must be set to true.

session_persistence

SessionPersistence object

Specifies the sticky session.

ip_version

String

Specifies the IP address version supported by the backend server group.

Value range:

  • Shared load balancers: The value is fixed at v4.

  • Dedicated load balancers: The value can be dualstack or v4. If the protocol of the backend server group is TCP or UDP, the value is dualstack. If the protocol of the backend server group is HTTP, the value is v4.

slow_start

SlowStart object

Specifies slow start details. After you enable slow start, new backend servers added to the backend server group are warmed up, and the number of requests they can receive increases linearly during the configured slow start duration.

This parameter can be used when the protocol of the backend server group is HTTP or HTTPS. An error will be returned if the protocol is not HTTP or HTTPS.

member_deletion_protection_enable

Boolean

Specifies whether to enable deletion protection.

Value options:

  • true: Enable deletion protection.

  • false: Disable deletion protection.

NOTE:

Disable deletion protection for all your resources before deleting your account.

created_at

String

Specifies the time when the backend server group was created. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time).

This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

updated_at

String

Specifies the time when the backend server group was updated. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time).

This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

vpc_id

String

Specifies the ID of the VPC where the backend server group works.

type

String

Specifies the type of the backend server group.

Value options:

  • instance: Any type of backend servers can be added. vpc_id is mandatory.

  • ip: Only IP as backend servers can be added. vpc_id cannot be specified.

  • "": Any type of backend servers can be added.

protection_status

String

Specifies the protection status.

Value options:

  • nonProtection (default): The load balancer is not protected.

  • consoleProtection: Modification Protection is enabled on the console.

protection_reason

String

Specifies why the modification protection is enabled.

Note: This parameter is valid only when protection_status is set to consoleProtection. The value can contain a maximum of 255 Unicode characters, excluding angle brackets (<>).

any_port_enable

Boolean

Specifies whether to enable any_port_enable for a backend server group. If this option is enabled, the listener routes the requests to the backend server over the same port as the frontend port. If this option is disabled, the listener routes the requests over the port specified by protocol_port.

Value options:

  • false: Disable this option.

  • true: Enable this option.

Note: This option is available only for TCP, UDP, or QUIC backend server groups.

connection_drain

ConnectionDrain object

Specifies the configurations of deregistration delay. This parameter is only available for TCP, UDP, and QUIC backend server groups and TCP and UDP listeners.

This parameter takes effect when:

  • A backend server is removed from a backend server group.

  • A backend server is detected unhealthy or health checks fail.

  • The weight of a backend server is 0.

enterprise_project_id

String

Specifies the ID of the enterprise project that the IP address group belongs to.

pool_health

PoolHealth object

Specifies the configurations of the pool health feature.

public_border_group

String

Specifies the public border group, for example, center.

quic_cid_hash_strategy

QuicCidHashStrategy object

Specifies multi-path forwarding policy based on destination connection IDs.

Table 12 ListenerRef

Parameter

Type

Description

id

String

Specifies the listener ID.

Table 13 LoadBalancerRef

Parameter

Type

Description

id

String

Specifies the load balancer ID.

Table 14 MemberRef

Parameter

Type

Description

id

String

Specifies the backend server ID.

Table 15 SessionPersistence

Parameter

Type

Description

cookie_name

String

Specifies the cookie name.

Note:

  • This parameter will take effect only when type is set to APP_COOKIE. Otherwise, an error will be returned.

Value ranges:

  • For shared load balancers, the name can contain a maximum of 64 characters, including letters, digits, underscores (_), and hyphens (-).

  • For dedicated load balancers, the name can contain a maximum of 255 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).

type

String

Specifies the sticky session type.

The value can be SOURCE_IP, HTTP_COOKIE, or APP_COOKIE.

Note:

  • If the protocol of the backend server group is TCP or UDP, only SOURCE_IP takes effect.

  • If the protocol of the backend server group is HTTP or HTTPS, the value can be HTTP_COOKIE or APP_COOKIE.

  • If the backend server group protocol is QUIC, sticky session must be enabled with type set to SOURCE_IP.

persistence_timeout

Integer

Specifies the stickiness duration, in minutes. This parameter will not take effect when type is set to APP_COOKIE.

  • If the protocol of the backend server group is TCP, UDP, or QUIC, the value ranges from 1 to 60, and the default value is 1.

  • If the protocol of the backend server group is HTTP or HTTPS, the value ranges from 1 to 1440, and the default value is 1440.

Table 16 SlowStart

Parameter

Type

Description

enable

Boolean

Specifies whether to enable slow start.

  • true: Enable slow start.

  • false (default): Disable slow start.

duration

Integer

Specifies the slow start duration, in seconds.

The value ranges from 30 to 1200, and the default value is 30.

Table 17 ConnectionDrain

Parameter

Type

Description

enable

Boolean

Specifies whether to enable connection_drain.

Value options:

  • true: Enable this option.

  • false: Disable this option.

    Default value: true

timeout

Integer

Specifies the deregistration delay timeout, in seconds. The value ranges from 10 to 4000.

Table 18 PoolHealth

Parameter

Type

Description

minimum_healthy_member_count

Integer

If the number of healthy backend servers is less than the value specified for this parameter, the backend server group is considered as unhealthy.

The value can be 0 (disabled) or 1 (enabled).

Table 19 QuicCidHashStrategy

Parameter

Type

Description

len

Integer

Specifies the length of the hash factor in the connection ID, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 1 to 20

Default value: 3

offset

Integer

Specifies the start position in the connection ID as the hash factor, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 0 to 19

Default value: 1

Example Requests

  • Creating a backend server group and setting its backend protocol to TCP

    POST https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/pools
    
    {
      "pool" : {
        "name" : "My pool",
        "lb_algorithm" : "LEAST_CONNECTIONS",
        "listener_id" : "0b11747a-b139-492f-9692-2df0b1c87193",
        "protocol" : "TCP",
        "member_deletion_protection_enable" : false
      }
    }
  • Creating a backend server group and setting its backend protocol to HTTP

    POST https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/pools
    
    {
      "pool" : {
        "name" : "My pool",
        "lb_algorithm" : "LEAST_CONNECTIONS",
        "listener_id" : "0b11747a-b139-492f-9692-2df0b1c87193",
        "protocol" : "HTTP",
        "slow_start" : {
          "enable" : true,
          "duration" : 50
        },
        "member_deletion_protection_enable" : false
      }
    }

Example Responses

Status code: 201

Normal response to POST requests.

{
  "pool" : {
    "type" : "",
    "vpc_id" : "",
    "lb_algorithm" : "LEAST_CONNECTIONS",
    "protocol" : "TCP",
    "description" : "",
    "admin_state_up" : true,
    "member_deletion_protection_enable" : false,
    "loadbalancers" : [ {
      "id" : "098b2f68-af1c-41a9-8efd-69958722af62"
    } ],
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "session_persistence" : null,
    "healthmonitor_id" : null,
    "listeners" : [ {
      "id" : "0b11747a-b139-492f-9692-2df0b1c87193"
    } ],
    "members" : [ ],
    "id" : "36ce7086-a496-4666-9064-5ba0e6840c75",
    "name" : "My pool",
    "ip_version" : "v4",
    "slow_start" : null
  },
  "request_id" : "2d974978-0733-404d-a21a-b29204f4803a"
}

SDK Sample Code

The SDK sample code is as follows.

  • Creating a backend server group and setting its backend protocol to TCP

     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
    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.elb.v3.region.ElbRegion;
    import com.huaweicloud.sdk.elb.v3.*;
    import com.huaweicloud.sdk.elb.v3.model.*;
    
    
    public class CreatePoolSolution {
    
        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);
    
            ElbClient client = ElbClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreatePoolRequest request = new CreatePoolRequest();
            CreatePoolRequestBody body = new CreatePoolRequestBody();
            CreatePoolOption poolbody = new CreatePoolOption();
            poolbody.withLbAlgorithm("LEAST_CONNECTIONS")
                .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193")
                .withName("My pool")
                .withProtocol("TCP")
                .withMemberDeletionProtectionEnable(false);
            body.withPool(poolbody);
            request.withBody(body);
            try {
                CreatePoolResponse response = client.createPool(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());
            }
        }
    }
    
  • Creating a backend server group and setting its backend protocol to HTTP

     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
    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.elb.v3.region.ElbRegion;
    import com.huaweicloud.sdk.elb.v3.*;
    import com.huaweicloud.sdk.elb.v3.model.*;
    
    
    public class CreatePoolSolution {
    
        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);
    
            ElbClient client = ElbClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreatePoolRequest request = new CreatePoolRequest();
            CreatePoolRequestBody body = new CreatePoolRequestBody();
            CreatePoolSlowStartOption slowStartPool = new CreatePoolSlowStartOption();
            slowStartPool.withEnable(true)
                .withDuration(50);
            CreatePoolOption poolbody = new CreatePoolOption();
            poolbody.withLbAlgorithm("LEAST_CONNECTIONS")
                .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193")
                .withName("My pool")
                .withProtocol("HTTP")
                .withSlowStart(slowStartPool)
                .withMemberDeletionProtectionEnable(false);
            body.withPool(poolbody);
            request.withBody(body);
            try {
                CreatePoolResponse response = client.createPool(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());
            }
        }
    }
    
  • Creating a backend server group and setting its backend protocol to TCP

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkelb.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 = ElbClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ElbRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreatePoolRequest()
            poolbody = CreatePoolOption(
                lb_algorithm="LEAST_CONNECTIONS",
                listener_id="0b11747a-b139-492f-9692-2df0b1c87193",
                name="My pool",
                protocol="TCP",
                member_deletion_protection_enable=False
            )
            request.body = CreatePoolRequestBody(
                pool=poolbody
            )
            response = client.create_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Creating a backend server group and setting its backend protocol to HTTP

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkelb.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 = ElbClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ElbRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreatePoolRequest()
            slowStartPool = CreatePoolSlowStartOption(
                enable=True,
                duration=50
            )
            poolbody = CreatePoolOption(
                lb_algorithm="LEAST_CONNECTIONS",
                listener_id="0b11747a-b139-492f-9692-2df0b1c87193",
                name="My pool",
                protocol="HTTP",
                slow_start=slowStartPool,
                member_deletion_protection_enable=False
            )
            request.body = CreatePoolRequestBody(
                pool=poolbody
            )
            response = client.create_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Creating a backend server group and setting its backend protocol to TCP

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/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 := elb.NewElbClient(
            elb.ElbClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreatePoolRequest{}
    	listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193"
    	namePool:= "My pool"
    	memberDeletionProtectionEnablePool:= false
    	poolbody := &model.CreatePoolOption{
    		LbAlgorithm: "LEAST_CONNECTIONS",
    		ListenerId: &listenerIdPool,
    		Name: &namePool,
    		Protocol: "TCP",
    		MemberDeletionProtectionEnable: &memberDeletionProtectionEnablePool,
    	}
    	request.Body = &model.CreatePoolRequestBody{
    		Pool: poolbody,
    	}
    	response, err := client.CreatePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Creating a backend server group and setting its backend protocol to HTTP

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/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 := elb.NewElbClient(
            elb.ElbClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreatePoolRequest{}
    	enableSlowStart:= true
    	durationSlowStart:= int32(50)
    	slowStartPool := &model.CreatePoolSlowStartOption{
    		Enable: &enableSlowStart,
    		Duration: &durationSlowStart,
    	}
    	listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193"
    	namePool:= "My pool"
    	memberDeletionProtectionEnablePool:= false
    	poolbody := &model.CreatePoolOption{
    		LbAlgorithm: "LEAST_CONNECTIONS",
    		ListenerId: &listenerIdPool,
    		Name: &namePool,
    		Protocol: "HTTP",
    		SlowStart: slowStartPool,
    		MemberDeletionProtectionEnable: &memberDeletionProtectionEnablePool,
    	}
    	request.Body = &model.CreatePoolRequestBody{
    		Pool: poolbody,
    	}
    	response, err := client.CreatePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

  • Creating a backend server group and setting its backend protocol to TCP

     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
    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.elb.v3.region.ElbRegion;
    import com.huaweicloud.sdk.elb.v3.*;
    import com.huaweicloud.sdk.elb.v3.model.*;
    
    
    public class CreatePoolSolution {
    
        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);
    
            ElbClient client = ElbClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreatePoolRequest request = new CreatePoolRequest();
            CreatePoolRequestBody body = new CreatePoolRequestBody();
            CreatePoolOption poolbody = new CreatePoolOption();
            poolbody.withLbAlgorithm("LEAST_CONNECTIONS")
                .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193")
                .withName("My pool")
                .withProtocol("TCP")
                .withMemberDeletionProtectionEnable(false);
            body.withPool(poolbody);
            request.withBody(body);
            try {
                CreatePoolResponse response = client.createPool(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());
            }
        }
    }
    
  • Creating a backend server group and setting its backend protocol to HTTP

     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
    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.elb.v3.region.ElbRegion;
    import com.huaweicloud.sdk.elb.v3.*;
    import com.huaweicloud.sdk.elb.v3.model.*;
    
    
    public class CreatePoolSolution {
    
        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);
    
            ElbClient client = ElbClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreatePoolRequest request = new CreatePoolRequest();
            CreatePoolRequestBody body = new CreatePoolRequestBody();
            CreatePoolSlowStartOption slowStartPool = new CreatePoolSlowStartOption();
            slowStartPool.withEnable(true)
                .withDuration(50);
            CreatePoolOption poolbody = new CreatePoolOption();
            poolbody.withLbAlgorithm("LEAST_CONNECTIONS")
                .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193")
                .withName("My pool")
                .withProtocol("HTTP")
                .withSlowStart(slowStartPool)
                .withMemberDeletionProtectionEnable(false);
            body.withPool(poolbody);
            request.withBody(body);
            try {
                CreatePoolResponse response = client.createPool(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());
            }
        }
    }
    
  • Creating a backend server group and setting its backend protocol to TCP

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkelb.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 = ElbClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ElbRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreatePoolRequest()
            poolbody = CreatePoolOption(
                lb_algorithm="LEAST_CONNECTIONS",
                listener_id="0b11747a-b139-492f-9692-2df0b1c87193",
                name="My pool",
                protocol="TCP",
                member_deletion_protection_enable=False
            )
            request.body = CreatePoolRequestBody(
                pool=poolbody
            )
            response = client.create_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Creating a backend server group and setting its backend protocol to HTTP

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkelb.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 = ElbClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ElbRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreatePoolRequest()
            slowStartPool = CreatePoolSlowStartOption(
                enable=True,
                duration=50
            )
            poolbody = CreatePoolOption(
                lb_algorithm="LEAST_CONNECTIONS",
                listener_id="0b11747a-b139-492f-9692-2df0b1c87193",
                name="My pool",
                protocol="HTTP",
                slow_start=slowStartPool,
                member_deletion_protection_enable=False
            )
            request.body = CreatePoolRequestBody(
                pool=poolbody
            )
            response = client.create_pool(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Creating a backend server group and setting its backend protocol to TCP

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/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 := elb.NewElbClient(
            elb.ElbClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreatePoolRequest{}
    	listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193"
    	namePool:= "My pool"
    	memberDeletionProtectionEnablePool:= false
    	poolbody := &model.CreatePoolOption{
    		LbAlgorithm: "LEAST_CONNECTIONS",
    		ListenerId: &listenerIdPool,
    		Name: &namePool,
    		Protocol: "TCP",
    		MemberDeletionProtectionEnable: &memberDeletionProtectionEnablePool,
    	}
    	request.Body = &model.CreatePoolRequestBody{
    		Pool: poolbody,
    	}
    	response, err := client.CreatePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Creating a backend server group and setting its backend protocol to HTTP

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/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 := elb.NewElbClient(
            elb.ElbClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreatePoolRequest{}
    	enableSlowStart:= true
    	durationSlowStart:= int32(50)
    	slowStartPool := &model.CreatePoolSlowStartOption{
    		Enable: &enableSlowStart,
    		Duration: &durationSlowStart,
    	}
    	listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193"
    	namePool:= "My pool"
    	memberDeletionProtectionEnablePool:= false
    	poolbody := &model.CreatePoolOption{
    		LbAlgorithm: "LEAST_CONNECTIONS",
    		ListenerId: &listenerIdPool,
    		Name: &namePool,
    		Protocol: "HTTP",
    		SlowStart: slowStartPool,
    		MemberDeletionProtectionEnable: &memberDeletionProtectionEnablePool,
    	}
    	request.Body = &model.CreatePoolRequestBody{
    		Pool: poolbody,
    	}
    	response, err := client.CreatePool(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

201

Normal response to POST requests.

Error Codes

See Error Codes.

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback