selectel_mks/nodegroup/
schemas.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5use super::super::node::schemas::Node;
6
7/// Nodegroup represents a deserialized nodegroup body from an API response.
8#[derive(Debug, Deserialize, Serialize)]
9pub struct Nodegroup {
10    /// Nodegroup identifier.
11    pub id: String,
12
13    /// Timestamp in UTC timezone of when the nodegroup has been created.
14    pub created_at: DateTime<Utc>,
15
16    /// Timestamp in UTC timezone of when the nodegroup has been updated.
17    pub updated_at: Option<DateTime<Utc>>,
18
19    /// Cluster identifier.
20    pub cluster_id: String,
21
22    /// OpenStack flavor identifier for all nodes in the nodegroup.
23    pub flavor_id: String,
24
25    /// Initial volume size in GB for each node.
26    pub volume_gb: u32,
27
28    /// Initial blockstorage volume type for each node.
29    pub volume_type: String,
30
31    /// Flag that represents if nodes use local volume.
32    pub local_volume: bool,
33
34    /// OpenStack availability zone for all nodes in the nodegroup.
35    pub availability_zone: String,
36
37    /// All nodes in the nodegroup.
38    pub nodes: Vec<Node>,
39
40    /// A map of user-defined Kubernetes labels for each node in the group.
41    pub labels: HashMap<String, String>,
42}
43
44/// NodegroupRoot represents a root of a deserialized nodegroup.
45#[derive(Debug, Deserialize, Serialize)]
46pub struct NodegroupRoot {
47    pub nodegroup: Nodegroup,
48}
49
50/// ListRoot represents a root of a list with deserialized nodegroups.
51#[derive(Debug, Deserialize, Serialize)]
52pub struct ListRoot {
53    pub nodegroups: Vec<Nodegroup>,
54}
55
56/// Create options for a new nodegroup.
57#[derive(Debug, Serialize)]
58pub struct CreateOpts {
59    count: u32,
60    flavor_id: Option<String>,
61    cpus: Option<u32>,
62    ram_mb: Option<u32>,
63    volume_gb: Option<u32>,
64    volume_type: Option<String>,
65    local_volume: bool,
66    keypair_name: Option<String>,
67    affinity_policy: Option<String>,
68    availability_zone: String,
69    labels: Option<HashMap<String, String>>,
70}
71
72impl CreateOpts {
73    pub fn new(count: u32, local_volume: bool, availability_zone: &str) -> CreateOpts {
74        CreateOpts {
75            count,
76            flavor_id: None,
77            cpus: None,
78            ram_mb: None,
79            volume_gb: None,
80            volume_type: None,
81            local_volume,
82            keypair_name: None,
83            affinity_policy: None,
84            availability_zone: String::from(availability_zone),
85            labels: None,
86        }
87    }
88
89    /// Add a reference to a pre-created flavor.
90    /// It can be omitted in most cases.
91    pub fn with_flavor_id(mut self, flavor_id: &str) -> CreateOpts {
92        self.flavor_id = Some(String::from(flavor_id));
93        self
94    }
95
96    /// Add a CPU count for each node.
97    /// It can be omitted only in cases when flavor_id is set.
98    pub fn with_cpus(mut self, cpus: u32) -> CreateOpts {
99        self.cpus = Some(cpus);
100        self
101    }
102
103    /// Add a RAM count in MB for each node.
104    /// It can be omitted only in cases when flavor_id is set.
105    pub fn with_ram_mb(mut self, ram_mb: u32) -> CreateOpts {
106        self.ram_mb = Some(ram_mb);
107        self
108    }
109
110    /// Add a volume size in GB for each node.
111    /// It can be omitted only in cases when flavor_id is set and volume is local.
112    pub fn with_volume_gb(mut self, volume_gb: u32) -> CreateOpts {
113        self.volume_gb = Some(volume_gb);
114        self
115    }
116
117    /// Add a blockstorage volume type for each node.
118    /// It can be omitted only in cases when flavor_id is set and volume is local.
119    pub fn with_volume_type(mut self, volume_type: &str) -> CreateOpts {
120        self.volume_type = Some(String::from(volume_type));
121        self
122    }
123
124    /// Add a name of the SSH key that will be added to all nodes.
125    pub fn with_keypair_name(mut self, keypair_name: &str) -> CreateOpts {
126        self.keypair_name = Some(String::from(keypair_name));
127        self
128    }
129
130    /// Add an optional parameter to tune nodes affinity.
131    pub fn with_affinity_policy(mut self, affinity_policy: &str) -> CreateOpts {
132        self.affinity_policy = Some(String::from(affinity_policy));
133        self
134    }
135
136    /// Add a map of user-defined Kubernetes labels for each node in the group.
137    pub fn with_labels(mut self, labels: HashMap<String, String>) -> CreateOpts {
138        self.labels = Some(labels);
139        self
140    }
141}
142
143/// CreateOptsRoot represents a root of nodegroup create options.
144#[derive(Debug, Serialize)]
145pub struct CreateOptsRoot<'a> {
146    pub nodegroup: &'a CreateOpts,
147}
148
149/// Options for the nodegroup resize operation.
150#[derive(Debug, Serialize)]
151pub struct ResizeOpts {
152    desired: u32,
153}
154
155impl ResizeOpts {
156    pub fn new(desired: u32) -> ResizeOpts {
157        ResizeOpts { desired }
158    }
159}
160
161/// ResizeOptsRoot represents a root of nodegroup resize options.
162#[derive(Debug, Serialize)]
163pub struct ResizeOptsRoot<'a> {
164    pub nodegroup: &'a ResizeOpts,
165}
166
167/// Options for the nodegroup update operation.
168#[derive(Debug, Serialize)]
169pub struct UpdateOpts {
170    labels: Option<HashMap<String, String>>,
171}
172
173impl UpdateOpts {
174    pub fn new() -> UpdateOpts {
175        UpdateOpts { labels: None }
176    }
177
178    /// Update user-defined Kubernetes labels for each node in the group.
179    pub fn with_labels(mut self, labels: HashMap<String, String>) -> UpdateOpts {
180        self.labels = Some(labels);
181        self
182    }
183}
184
185impl Default for UpdateOpts {
186    fn default() -> Self {
187        UpdateOpts::new()
188    }
189}
190
191/// UpdateOptsRoot represents a root of nodegroup update options.
192#[derive(Debug, Serialize)]
193pub struct UpdateOptsRoot<'a> {
194    pub nodegroup: &'a UpdateOpts,
195}