cloudflare/endpoints/load_balancing/create_pool.rs
1use surf::http::Method;
2
3use crate::endpoints::load_balancing::{Origin, Pool};
4use crate::framework::endpoint::Endpoint;
5
6/// Create Pool
7/// https://api.cloudflare.com/#account-load-balancer-pools-create-pool
8#[derive(Debug)]
9pub struct CreatePool<'a> {
10 /// The Cloudflare account to create this Pool under.
11 pub account_identifier: &'a str,
12 /// Optional parameters for the API call
13 pub params: Params<'a>,
14}
15
16/// Mandatory parameters for creating a Load Balancer Pool.
17#[serde_with::skip_serializing_none]
18#[derive(Serialize, Clone, Debug)]
19pub struct Params<'a> {
20 /// A short name (tag) for the pool.
21 /// Only alphanumeric characters, hyphens and underscores are allowed.
22 /// E.g. "primary-dc-1"
23 pub name: &'a str,
24 /// The list of origins within this pool.
25 /// Traffic directed at this pool is balanced across all currently healthy origins, provided
26 /// the pool itself is healthy.
27 pub origins: &'a [Origin],
28 #[serde(flatten)]
29 pub optional_params: Option<OptionalParams<'a>>,
30}
31
32/// Optional parameters for creating a Load Balancer Pool.
33#[serde_with::skip_serializing_none]
34#[derive(Serialize, Clone, Debug, Default)]
35pub struct OptionalParams<'a> {
36 /// A human-readable description of the pool.
37 /// e.g. "Primary data center - Provider XYZ"
38 pub description: Option<&'a str>,
39 /// Whether to enable (the default) this pool. Disabled pools will not receive traffic and are
40 /// excluded from health checks. Disabling a pool will cause any load balancers using it to
41 /// failover to the next pool (if any).
42 pub enabled: Option<bool>,
43 /// The minimum number of origins that must be healthy for this pool to serve traffic. If the
44 /// number of healthy origins falls below this number, the pool will be marked unhealthy and we
45 /// will failover to the next available pool.
46 pub minimum_origins: Option<u8>,
47 /// The ID of the Monitor to use for health checking origins within this pool.
48 pub monitor: Option<&'a str>,
49 /// The email address to send health status notifications to. This can be an individual mailbox
50 /// or a mailing list.
51 pub notification_email: Option<&'a str>,
52}
53
54impl<'a> Endpoint<Pool, (), Params<'a>> for CreatePool<'a> {
55 fn method(&self) -> Method {
56 Method::Post
57 }
58 fn path(&self) -> String {
59 format!("accounts/{}/load_balancers/pools", self.account_identifier)
60 }
61 fn body(&self) -> Option<Params<'a>> {
62 Some(self.params.clone())
63 }
64}