oxide_api/routers.rs
1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Routers {
6 pub client: Client,
7}
8
9impl Routers {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Routers { client }
13 }
14
15 /**
16 * List routers.
17 *
18 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers` 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::VpcRouter>> {
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/{}/routers?{}",
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::VpcRouterResultsPage = self.client.get(&url, None).await?;
60
61 // Return our response data.
62 Ok(resp.items)
63 }
64
65 /**
66 * List routers.
67 *
68 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers` 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::VpcRouter>> {
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/{}/routers?{}",
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::VpcRouterResultsPage = 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 router.
126 *
127 * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers` 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::VpcRouterCreate,
141 ) -> Result<crate::types::VpcRouter> {
142 let url = format!(
143 "/organizations/{}/projects/{}/vpcs/{}/routers",
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 * Get a router.
156 *
157 * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_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 * * `router_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 router_name: &str,
171 vpc_name: &str,
172 ) -> Result<crate::types::VpcRouter> {
173 let url = format!(
174 "/organizations/{}/projects/{}/vpcs/{}/routers/{}",
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(router_name),
179 );
180
181 self.client.get(&url, None).await
182 }
183
184 /**
185 * Update a router.
186 *
187 * This function performs a `PUT` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_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 * * `router_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 router_name: &str,
201 vpc_name: &str,
202 body: &crate::types::VpcRouterUpdate,
203 ) -> Result<crate::types::VpcRouter> {
204 let url = format!(
205 "/organizations/{}/projects/{}/vpcs/{}/routers/{}",
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(router_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 router.
219 *
220 * This function performs a `DELETE` to the `/organizations/{organization_name}/projects/{project_name}/vpcs/{vpc_name}/routers/{router_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 * * `router_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 router_name: &str,
234 vpc_name: &str,
235 ) -> Result<()> {
236 let url = format!(
237 "/organizations/{}/projects/{}/vpcs/{}/routers/{}",
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(router_name),
242 );
243
244 self.client.delete(&url, None).await
245 }
246}