nomad_rs_api/
node_pool.rs1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3
4use crate::option::{QueryOptions, WriteOptions};
5use crate::{ClientError, Nomad};
6
7#[derive(Debug, Serialize, Deserialize)]
8#[serde(rename_all = "PascalCase")]
9pub struct NodePool {
10 pub name: String,
11 pub description: Option<String>,
12 pub meta: Option<std::collections::HashMap<String, String>>,
13 pub scheduler_configuration: Option<NodePoolSchedulerConfiguration>,
14 pub create_index: Option<u64>,
15 pub modify_index: Option<u64>,
16}
17
18impl NodePool {
19 pub fn new(name: String) -> Self {
20 NodePool {
21 name,
22 description: None,
23 meta: None,
24 scheduler_configuration: None,
25 create_index: None,
26 modify_index: None,
27 }
28 }
29}
30
31#[derive(Debug, Serialize, Deserialize)]
32#[serde(rename_all = "PascalCase")]
33pub struct NodePoolSchedulerConfiguration {
34 pub scheduler_algorithm: Option<String>,
35 pub memory_oversubscription_enabled: Option<bool>,
36}
37
38pub struct Endpoint<'a> {
39 client: &'a Nomad,
40}
41
42impl<'a> Endpoint<'a> {
43 pub fn new(client: &'a Nomad) -> Self {
46 Self { client }
47 }
48
49 pub async fn create(
50 &self,
51 node_pool: &NodePool,
52 opts: Option<WriteOptions>,
53 ) -> Result<(), ClientError> {
54 let req = self
55 .client
56 .set_request_write_options(
57 self.client.build_request(Method::PUT, "/v1/node/pool"),
58 &opts.unwrap_or_default(),
59 )
60 .json(node_pool);
61 self.client.send_without_response(req).await
62 }
63
64 pub async fn delete(&self, name: &str, opts: Option<WriteOptions>) -> Result<(), ClientError> {
65 let req = self.client.set_request_write_options(
66 self.client
67 .build_request(Method::DELETE, &format!("/v1/node/pool/{}", name)),
68 &opts.unwrap_or_default(),
69 );
70 self.client.send_without_response(req).await
71 }
72
73 pub async fn get(
74 &self,
75 name: &str,
76 opts: Option<QueryOptions>,
77 ) -> Result<NodePool, ClientError> {
78 let req = self.client.set_request_query_options(
79 self.client
80 .build_request(Method::GET, &format!("/v1/node/pool/{}", name)),
81 &opts.unwrap_or_default(),
82 );
83 self.client.send_with_response::<NodePool>(req).await
84 }
85
86 pub async fn list(&self, opts: Option<QueryOptions>) -> Result<Vec<NodePool>, ClientError> {
87 let req = self.client.set_request_query_options(
88 self.client.build_request(Method::GET, "/v1/node/pools"),
89 &opts.unwrap_or_default(),
90 );
91 self.client.send_with_response::<Vec<NodePool>>(req).await
92 }
93}