cloudflare/endpoints/load_balancing/
create_pool.rs

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