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