oxide_api/subnets.rs
1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Subnets {
6 pub client: Client,
7}
8
9impl Subnets {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Subnets { client }
13 }
14
15 /**
16 * List subnets.
17 *
18 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets` endpoint.
19 *
20 * **Parameters:**
21 *
22 * * `limit: u32` -- Maximum number of items returned by a single call.
23 * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
24 * * `sort_by: crate::types::NameSortMode` -- Supported set of sort modes for scanning by name only
25 *
26 * Currently, we only support scanning in ascending order.
27 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
28 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
29 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
30 */
31 pub async fn get_page(
32 &self,
33 limit: u32,
34 organization_name: &str,
35 page_token: &str,
36 project_name: &str,
37 sort_by: crate::types::NameSortMode,
38 vpc_name: &str,
39 ) -> Result<Vec<crate::types::VpcSubnet>> {
40 let mut query_args: Vec<(String, String)> = Default::default();
41 if !limit.to_string().is_empty() {
42 query_args.push(("limit".to_string(), limit.to_string()));
43 }
44 if !page_token.is_empty() {
45 query_args.push(("page_token".to_string(), page_token.to_string()));
46 }
47 if !sort_by.to_string().is_empty() {
48 query_args.push(("sort_by".to_string(), sort_by.to_string()));
49 }
50 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
51 let url = format!(
52 "/organizations/{}/projects/{}/vpcs/{}/subnets?{}",
53 crate::progenitor_support::encode_path(organization_name),
54 crate::progenitor_support::encode_path(project_name),
55 crate::progenitor_support::encode_path(vpc_name),
56 query_
57 );
58
59 let resp: crate::types::VpcSubnetResultsPage = self.client.get(&url, None).await?;
60
61 // Return our response data.
62 Ok(resp.items)
63 }
64
65 /**
66 * List subnets.
67 *
68 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets` endpoint.
69 *
70 * As opposed to `get`, this function returns all the pages of the request at once.
71 */
72 pub async fn get_all(
73 &self,
74 organization_name: &str,
75 project_name: &str,
76 sort_by: crate::types::NameSortMode,
77 vpc_name: &str,
78 ) -> Result<Vec<crate::types::VpcSubnet>> {
79 let mut query_args: Vec<(String, String)> = Default::default();
80 if !sort_by.to_string().is_empty() {
81 query_args.push(("sort_by".to_string(), sort_by.to_string()));
82 }
83 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
84 let url = format!(
85 "/organizations/{}/projects/{}/vpcs/{}/subnets?{}",
86 crate::progenitor_support::encode_path(organization_name),
87 crate::progenitor_support::encode_path(project_name),
88 crate::progenitor_support::encode_path(vpc_name),
89 query_
90 );
91
92 let mut resp: crate::types::VpcSubnetResultsPage = self.client.get(&url, None).await?;
93
94 let mut items = resp.items;
95 let mut page = resp.next_page;
96
97 // Paginate if we should.
98 while !page.is_empty() {
99 if !url.contains('?') {
100 resp = self
101 .client
102 .get(&format!("{}?page={}", url, page), None)
103 .await?;
104 } else {
105 resp = self
106 .client
107 .get(&format!("{}&page={}", url, page), None)
108 .await?;
109 }
110
111 items.append(&mut resp.items);
112
113 if !resp.next_page.is_empty() && resp.next_page != page {
114 page = resp.next_page.to_string();
115 } else {
116 page = "".to_string();
117 }
118 }
119
120 // Return our response data.
121 Ok(items)
122 }
123
124 /**
125 * Create a subnet.
126 *
127 * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets` endpoint.
128 *
129 * **Parameters:**
130 *
131 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
132 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
133 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
134 */
135 pub async fn post(
136 &self,
137 organization_name: &str,
138 project_name: &str,
139 vpc_name: &str,
140 body: &crate::types::VpcSubnetCreate,
141 ) -> Result<crate::types::VpcSubnet> {
142 let url = format!(
143 "/organizations/{}/projects/{}/vpcs/{}/subnets",
144 crate::progenitor_support::encode_path(organization_name),
145 crate::progenitor_support::encode_path(project_name),
146 crate::progenitor_support::encode_path(vpc_name),
147 );
148
149 self.client
150 .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
151 .await
152 }
153
154 /**
155 * Fetch a subnet.
156 *
157 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets/{subnet_name}` endpoint.
158 *
159 * **Parameters:**
160 *
161 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
162 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
163 * * `subnet_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
164 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
165 */
166 pub async fn get(
167 &self,
168 organization_name: &str,
169 project_name: &str,
170 subnet_name: &str,
171 vpc_name: &str,
172 ) -> Result<crate::types::VpcSubnet> {
173 let url = format!(
174 "/organizations/{}/projects/{}/vpcs/{}/subnets/{}",
175 crate::progenitor_support::encode_path(organization_name),
176 crate::progenitor_support::encode_path(project_name),
177 crate::progenitor_support::encode_path(vpc_name),
178 crate::progenitor_support::encode_path(subnet_name),
179 );
180
181 self.client.get(&url, None).await
182 }
183
184 /**
185 * Update a subnet.
186 *
187 * This function performs a `PUT` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets/{subnet_name}` endpoint.
188 *
189 * **Parameters:**
190 *
191 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
192 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
193 * * `subnet_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
194 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
195 */
196 pub async fn put(
197 &self,
198 organization_name: &str,
199 project_name: &str,
200 subnet_name: &str,
201 vpc_name: &str,
202 body: &crate::types::VpcSubnetUpdate,
203 ) -> Result<crate::types::VpcSubnet> {
204 let url = format!(
205 "/organizations/{}/projects/{}/vpcs/{}/subnets/{}",
206 crate::progenitor_support::encode_path(organization_name),
207 crate::progenitor_support::encode_path(project_name),
208 crate::progenitor_support::encode_path(vpc_name),
209 crate::progenitor_support::encode_path(subnet_name),
210 );
211
212 self.client
213 .put(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
214 .await
215 }
216
217 /**
218 * Delete a subnet.
219 *
220 * This function performs a `DELETE` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets/{subnet_name}` endpoint.
221 *
222 * **Parameters:**
223 *
224 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
225 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
226 * * `subnet_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
227 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
228 */
229 pub async fn delete(
230 &self,
231 organization_name: &str,
232 project_name: &str,
233 subnet_name: &str,
234 vpc_name: &str,
235 ) -> Result<()> {
236 let url = format!(
237 "/organizations/{}/projects/{}/vpcs/{}/subnets/{}",
238 crate::progenitor_support::encode_path(organization_name),
239 crate::progenitor_support::encode_path(project_name),
240 crate::progenitor_support::encode_path(vpc_name),
241 crate::progenitor_support::encode_path(subnet_name),
242 );
243
244 self.client.delete(&url, None).await
245 }
246
247 /**
248 * List network interfaces.
249 *
250 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets/{subnet_name}/network-interfaces` endpoint.
251 *
252 * **Parameters:**
253 *
254 * * `limit: u32` -- Maximum number of items returned by a single call.
255 * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
256 * * `sort_by: crate::types::NameSortMode` -- Supported set of sort modes for scanning by name only
257 *
258 * Currently, we only support scanning in ascending order.
259 * * `organization_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
260 * * `project_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
261 * * `subnet_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
262 * * `vpc_name: &str` -- Names must begin with a lower case ASCII letter, be composed exclusively of lowercase ASCII, uppercase ASCII, numbers, and '-', and may not end with a '-'. Names cannot be a UUID though they may contain a UUID.
263 */
264 pub async fn network_interfaces_get(
265 &self,
266 limit: u32,
267 organization_name: &str,
268 page_token: &str,
269 project_name: &str,
270 sort_by: crate::types::NameSortMode,
271 subnet_name: &str,
272 vpc_name: &str,
273 ) -> Result<Vec<crate::types::NetworkInterface>> {
274 let mut query_args: Vec<(String, String)> = Default::default();
275 if !limit.to_string().is_empty() {
276 query_args.push(("limit".to_string(), limit.to_string()));
277 }
278 if !page_token.is_empty() {
279 query_args.push(("page_token".to_string(), page_token.to_string()));
280 }
281 if !sort_by.to_string().is_empty() {
282 query_args.push(("sort_by".to_string(), sort_by.to_string()));
283 }
284 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
285 let url = format!(
286 "/organizations/{}/projects/{}/vpcs/{}/subnets/{}/network-interfaces?{}",
287 crate::progenitor_support::encode_path(organization_name),
288 crate::progenitor_support::encode_path(project_name),
289 crate::progenitor_support::encode_path(vpc_name),
290 crate::progenitor_support::encode_path(subnet_name),
291 query_
292 );
293
294 let resp: crate::types::NetworkInterfaceResultsPage = self.client.get(&url, None).await?;
295
296 // Return our response data.
297 Ok(resp.items)
298 }
299
300 /**
301 * List network interfaces.
302 *
303 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/subnets/{subnet_name}/network-interfaces` endpoint.
304 *
305 * As opposed to `network_interfaces_get`, this function returns all the pages of the request at once.
306 */
307 pub async fn network_interfaces_get_all(
308 &self,
309 organization_name: &str,
310 project_name: &str,
311 sort_by: crate::types::NameSortMode,
312 subnet_name: &str,
313 vpc_name: &str,
314 ) -> Result<Vec<crate::types::NetworkInterface>> {
315 let mut query_args: Vec<(String, String)> = Default::default();
316 if !sort_by.to_string().is_empty() {
317 query_args.push(("sort_by".to_string(), sort_by.to_string()));
318 }
319 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
320 let url = format!(
321 "/organizations/{}/projects/{}/vpcs/{}/subnets/{}/network-interfaces?{}",
322 crate::progenitor_support::encode_path(organization_name),
323 crate::progenitor_support::encode_path(project_name),
324 crate::progenitor_support::encode_path(vpc_name),
325 crate::progenitor_support::encode_path(subnet_name),
326 query_
327 );
328
329 let mut resp: crate::types::NetworkInterfaceResultsPage =
330 self.client.get(&url, None).await?;
331
332 let mut items = resp.items;
333 let mut page = resp.next_page;
334
335 // Paginate if we should.
336 while !page.is_empty() {
337 if !url.contains('?') {
338 resp = self
339 .client
340 .get(&format!("{}?page={}", url, page), None)
341 .await?;
342 } else {
343 resp = self
344 .client
345 .get(&format!("{}&page={}", url, page), None)
346 .await?;
347 }
348
349 items.append(&mut resp.items);
350
351 if !resp.next_page.is_empty() && resp.next_page != page {
352 page = resp.next_page.to_string();
353 } else {
354 page = "".to_string();
355 }
356 }
357
358 // Return our response data.
359 Ok(items)
360 }
361}