1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use super::super::node::schemas::Node;
#[derive(Debug, Deserialize, Serialize)]
pub struct Nodegroup {
pub id: String,
pub created_at: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
pub cluster_id: String,
pub flavor_id: String,
pub volume_gb: u32,
pub volume_type: String,
pub local_volume: bool,
pub availability_zone: String,
pub nodes: Vec<Node>,
pub labels: HashMap<String, String>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct NodegroupRoot {
pub nodegroup: Nodegroup,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ListRoot {
pub nodegroups: Vec<Nodegroup>,
}
#[derive(Debug, Serialize)]
pub struct CreateOpts {
count: u32,
flavor_id: Option<String>,
cpus: Option<u32>,
ram_mb: Option<u32>,
volume_gb: Option<u32>,
volume_type: Option<String>,
local_volume: bool,
keypair_name: Option<String>,
affinity_policy: Option<String>,
availability_zone: String,
labels: Option<HashMap<String, String>>,
}
impl CreateOpts {
pub fn new(count: u32, local_volume: bool, availability_zone: &str) -> CreateOpts {
CreateOpts {
count,
flavor_id: None,
cpus: None,
ram_mb: None,
volume_gb: None,
volume_type: None,
local_volume,
keypair_name: None,
affinity_policy: None,
availability_zone: String::from(availability_zone),
labels: None,
}
}
pub fn with_flavor_id(mut self, flavor_id: &str) -> CreateOpts {
self.flavor_id = Some(String::from(flavor_id));
self
}
pub fn with_cpus(mut self, cpus: u32) -> CreateOpts {
self.cpus = Some(cpus);
self
}
pub fn with_ram_mb(mut self, ram_mb: u32) -> CreateOpts {
self.ram_mb = Some(ram_mb);
self
}
pub fn with_volume_gb(mut self, volume_gb: u32) -> CreateOpts {
self.volume_gb = Some(volume_gb);
self
}
pub fn with_volume_type(mut self, volume_type: &str) -> CreateOpts {
self.volume_type = Some(String::from(volume_type));
self
}
pub fn with_keypair_name(mut self, keypair_name: &str) -> CreateOpts {
self.keypair_name = Some(String::from(keypair_name));
self
}
pub fn with_affinity_policy(mut self, affinity_policy: &str) -> CreateOpts {
self.affinity_policy = Some(String::from(affinity_policy));
self
}
pub fn with_labels(mut self, labels: HashMap<String, String>) -> CreateOpts {
self.labels = Some(labels);
self
}
}
#[derive(Debug, Serialize)]
pub struct CreateOptsRoot<'a> {
pub nodegroup: &'a CreateOpts,
}
#[derive(Debug, Serialize)]
pub struct ResizeOpts {
desired: u32,
}
impl ResizeOpts {
pub fn new(desired: u32) -> ResizeOpts {
ResizeOpts { desired }
}
}
#[derive(Debug, Serialize)]
pub struct ResizeOptsRoot<'a> {
pub nodegroup: &'a ResizeOpts,
}
#[derive(Debug, Serialize)]
pub struct UpdateOpts {
labels: Option<HashMap<String, String>>,
}
impl UpdateOpts {
pub fn new() -> UpdateOpts {
UpdateOpts { labels: None }
}
pub fn with_labels(mut self, labels: HashMap<String, String>) -> UpdateOpts {
self.labels = Some(labels);
self
}
}
impl Default for UpdateOpts {
fn default() -> Self {
UpdateOpts::new()
}
}
#[derive(Debug, Serialize)]
pub struct UpdateOptsRoot<'a> {
pub nodegroup: &'a UpdateOpts,
}