selectel_mks/nodegroup/
schemas.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5use super::super::node::schemas::Node;
6
7#[derive(Debug, Deserialize, Serialize)]
9pub struct Nodegroup {
10 pub id: String,
12
13 pub created_at: DateTime<Utc>,
15
16 pub updated_at: Option<DateTime<Utc>>,
18
19 pub cluster_id: String,
21
22 pub flavor_id: String,
24
25 pub volume_gb: u32,
27
28 pub volume_type: String,
30
31 pub local_volume: bool,
33
34 pub availability_zone: String,
36
37 pub nodes: Vec<Node>,
39
40 pub labels: HashMap<String, String>,
42}
43
44#[derive(Debug, Deserialize, Serialize)]
46pub struct NodegroupRoot {
47 pub nodegroup: Nodegroup,
48}
49
50#[derive(Debug, Deserialize, Serialize)]
52pub struct ListRoot {
53 pub nodegroups: Vec<Nodegroup>,
54}
55
56#[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 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 pub fn with_cpus(mut self, cpus: u32) -> CreateOpts {
99 self.cpus = Some(cpus);
100 self
101 }
102
103 pub fn with_ram_mb(mut self, ram_mb: u32) -> CreateOpts {
106 self.ram_mb = Some(ram_mb);
107 self
108 }
109
110 pub fn with_volume_gb(mut self, volume_gb: u32) -> CreateOpts {
113 self.volume_gb = Some(volume_gb);
114 self
115 }
116
117 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 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 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 pub fn with_labels(mut self, labels: HashMap<String, String>) -> CreateOpts {
138 self.labels = Some(labels);
139 self
140 }
141}
142
143#[derive(Debug, Serialize)]
145pub struct CreateOptsRoot<'a> {
146 pub nodegroup: &'a CreateOpts,
147}
148
149#[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#[derive(Debug, Serialize)]
163pub struct ResizeOptsRoot<'a> {
164 pub nodegroup: &'a ResizeOpts,
165}
166
167#[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 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#[derive(Debug, Serialize)]
193pub struct UpdateOptsRoot<'a> {
194 pub nodegroup: &'a UpdateOpts,
195}