oxide_api/
instances.rs

1use anyhow::Result;
2
3use crate::Client;
4
5pub struct Instances {
6    pub client: Client,
7}
8
9impl Instances {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Instances { client }
13    }
14
15    /**
16     * Fetch an instance by id.
17     *
18     * This function performs a `GET` to the `/by-id/instances/{id}` endpoint.
19     *
20     * **Parameters:**
21     *
22     * * `id: &str`
23     */
24    pub async fn view(&self, id: &str) -> Result<crate::types::Instance> {
25        let url = format!(
26            "/by-id/instances/{}",
27            crate::progenitor_support::encode_path(id),
28        );
29
30        self.client.get(&url, None).await
31    }
32
33    /**
34     * Fetch a network interface by id.
35     *
36     * This function performs a `GET` to the `/by-id/network-interfaces/{id}` endpoint.
37     *
38     * **Parameters:**
39     *
40     * * `id: &str`
41     */
42    pub async fn network_interface_view(&self, id: &str) -> Result<crate::types::NetworkInterface> {
43        let url = format!(
44            "/by-id/network-interfaces/{}",
45            crate::progenitor_support::encode_path(id),
46        );
47
48        self.client.get(&url, None).await
49    }
50
51    /**
52     * List instances.
53     *
54     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances` endpoint.
55     *
56     * **Parameters:**
57     *
58     * * `limit: u32` -- Maximum number of items returned by a single call.
59     * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
60     * * `sort_by: crate::types::NameSortMode` -- Supported set of sort modes for scanning by name only
61     *  
62     *  Currently, we only support scanning in ascending order.
63     * * `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.
64     * * `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.
65     */
66    pub async fn get_page(
67        &self,
68        limit: u32,
69        organization_name: &str,
70        page_token: &str,
71        project_name: &str,
72        sort_by: crate::types::NameSortMode,
73    ) -> Result<Vec<crate::types::Instance>> {
74        let mut query_args: Vec<(String, String)> = Default::default();
75        if !limit.to_string().is_empty() {
76            query_args.push(("limit".to_string(), limit.to_string()));
77        }
78        if !page_token.is_empty() {
79            query_args.push(("page_token".to_string(), page_token.to_string()));
80        }
81        if !sort_by.to_string().is_empty() {
82            query_args.push(("sort_by".to_string(), sort_by.to_string()));
83        }
84        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
85        let url = format!(
86            "/organizations/{}/projects/{}/instances?{}",
87            crate::progenitor_support::encode_path(organization_name),
88            crate::progenitor_support::encode_path(project_name),
89            query_
90        );
91
92        let resp: crate::types::InstanceResultsPage = self.client.get(&url, None).await?;
93
94        // Return our response data.
95        Ok(resp.items)
96    }
97
98    /**
99     * List instances.
100     *
101     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances` endpoint.
102     *
103     * As opposed to `get`, this function returns all the pages of the request at once.
104     */
105    pub async fn get_all(
106        &self,
107        organization_name: &str,
108        project_name: &str,
109        sort_by: crate::types::NameSortMode,
110    ) -> Result<Vec<crate::types::Instance>> {
111        let mut query_args: Vec<(String, String)> = Default::default();
112        if !sort_by.to_string().is_empty() {
113            query_args.push(("sort_by".to_string(), sort_by.to_string()));
114        }
115        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
116        let url = format!(
117            "/organizations/{}/projects/{}/instances?{}",
118            crate::progenitor_support::encode_path(organization_name),
119            crate::progenitor_support::encode_path(project_name),
120            query_
121        );
122
123        let mut resp: crate::types::InstanceResultsPage = self.client.get(&url, None).await?;
124
125        let mut items = resp.items;
126        let mut page = resp.next_page;
127
128        // Paginate if we should.
129        while !page.is_empty() {
130            if !url.contains('?') {
131                resp = self
132                    .client
133                    .get(&format!("{}?page={}", url, page), None)
134                    .await?;
135            } else {
136                resp = self
137                    .client
138                    .get(&format!("{}&page={}", url, page), None)
139                    .await?;
140            }
141
142            items.append(&mut resp.items);
143
144            if !resp.next_page.is_empty() && resp.next_page != page {
145                page = resp.next_page.to_string();
146            } else {
147                page = "".to_string();
148            }
149        }
150
151        // Return our response data.
152        Ok(items)
153    }
154
155    /**
156     * Create an instance.
157     *
158     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances` endpoint.
159     *
160     * **Parameters:**
161     *
162     * * `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.
163     * * `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.
164     */
165    pub async fn post(
166        &self,
167        organization_name: &str,
168        project_name: &str,
169        body: &crate::types::InstanceCreate,
170    ) -> Result<crate::types::Instance> {
171        let url = format!(
172            "/organizations/{}/projects/{}/instances",
173            crate::progenitor_support::encode_path(organization_name),
174            crate::progenitor_support::encode_path(project_name),
175        );
176
177        self.client
178            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
179            .await
180    }
181
182    /**
183     * Fetch an instance.
184     *
185     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}` endpoint.
186     *
187     * **Parameters:**
188     *
189     * * `instance_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.
190     * * `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.
191     * * `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.
192     */
193    pub async fn get(
194        &self,
195        instance_name: &str,
196        organization_name: &str,
197        project_name: &str,
198    ) -> Result<crate::types::Instance> {
199        let url = format!(
200            "/organizations/{}/projects/{}/instances/{}",
201            crate::progenitor_support::encode_path(organization_name),
202            crate::progenitor_support::encode_path(project_name),
203            crate::progenitor_support::encode_path(instance_name),
204        );
205
206        self.client.get(&url, None).await
207    }
208
209    /**
210     * Delete an instance.
211     *
212     * This function performs a `DELETE` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}` endpoint.
213     *
214     * **Parameters:**
215     *
216     * * `instance_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.
217     * * `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.
218     * * `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.
219     */
220    pub async fn delete(
221        &self,
222        instance_name: &str,
223        organization_name: &str,
224        project_name: &str,
225    ) -> Result<()> {
226        let url = format!(
227            "/organizations/{}/projects/{}/instances/{}",
228            crate::progenitor_support::encode_path(organization_name),
229            crate::progenitor_support::encode_path(project_name),
230            crate::progenitor_support::encode_path(instance_name),
231        );
232
233        self.client.delete(&url, None).await
234    }
235
236    /**
237     * List an instance's disks.
238     *
239     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/disks` endpoint.
240     *
241     * **Parameters:**
242     *
243     * * `limit: u32` -- Maximum number of items returned by a single call.
244     * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
245     * * `sort_by: crate::types::NameSortMode` -- Supported set of sort modes for scanning by name only
246     *  
247     *  Currently, we only support scanning in ascending order.
248     * * `instance_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.
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     */
252    pub async fn disks_get(
253        &self,
254        instance_name: &str,
255        limit: u32,
256        organization_name: &str,
257        page_token: &str,
258        project_name: &str,
259        sort_by: crate::types::NameSortMode,
260    ) -> Result<Vec<crate::types::Disk>> {
261        let mut query_args: Vec<(String, String)> = Default::default();
262        if !limit.to_string().is_empty() {
263            query_args.push(("limit".to_string(), limit.to_string()));
264        }
265        if !page_token.is_empty() {
266            query_args.push(("page_token".to_string(), page_token.to_string()));
267        }
268        if !sort_by.to_string().is_empty() {
269            query_args.push(("sort_by".to_string(), sort_by.to_string()));
270        }
271        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
272        let url = format!(
273            "/organizations/{}/projects/{}/instances/{}/disks?{}",
274            crate::progenitor_support::encode_path(organization_name),
275            crate::progenitor_support::encode_path(project_name),
276            crate::progenitor_support::encode_path(instance_name),
277            query_
278        );
279
280        let resp: crate::types::DiskResultsPage = self.client.get(&url, None).await?;
281
282        // Return our response data.
283        Ok(resp.items)
284    }
285
286    /**
287     * List an instance's disks.
288     *
289     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/disks` endpoint.
290     *
291     * As opposed to `disks_get`, this function returns all the pages of the request at once.
292     */
293    pub async fn disks_get_all(
294        &self,
295        instance_name: &str,
296        organization_name: &str,
297        project_name: &str,
298        sort_by: crate::types::NameSortMode,
299    ) -> Result<Vec<crate::types::Disk>> {
300        let mut query_args: Vec<(String, String)> = Default::default();
301        if !sort_by.to_string().is_empty() {
302            query_args.push(("sort_by".to_string(), sort_by.to_string()));
303        }
304        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
305        let url = format!(
306            "/organizations/{}/projects/{}/instances/{}/disks?{}",
307            crate::progenitor_support::encode_path(organization_name),
308            crate::progenitor_support::encode_path(project_name),
309            crate::progenitor_support::encode_path(instance_name),
310            query_
311        );
312
313        let mut resp: crate::types::DiskResultsPage = self.client.get(&url, None).await?;
314
315        let mut items = resp.items;
316        let mut page = resp.next_page;
317
318        // Paginate if we should.
319        while !page.is_empty() {
320            if !url.contains('?') {
321                resp = self
322                    .client
323                    .get(&format!("{}?page={}", url, page), None)
324                    .await?;
325            } else {
326                resp = self
327                    .client
328                    .get(&format!("{}&page={}", url, page), None)
329                    .await?;
330            }
331
332            items.append(&mut resp.items);
333
334            if !resp.next_page.is_empty() && resp.next_page != page {
335                page = resp.next_page.to_string();
336            } else {
337                page = "".to_string();
338            }
339        }
340
341        // Return our response data.
342        Ok(items)
343    }
344
345    /**
346     * Attach a disk to an instance.
347     *
348     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/disks/attach` endpoint.
349     *
350     * **Parameters:**
351     *
352     * * `instance_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.
353     * * `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.
354     * * `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.
355     */
356    pub async fn disks_attach(
357        &self,
358        instance_name: &str,
359        organization_name: &str,
360        project_name: &str,
361        body: &crate::types::DiskIdentifier,
362    ) -> Result<crate::types::Disk> {
363        let url = format!(
364            "/organizations/{}/projects/{}/instances/{}/disks/attach",
365            crate::progenitor_support::encode_path(organization_name),
366            crate::progenitor_support::encode_path(project_name),
367            crate::progenitor_support::encode_path(instance_name),
368        );
369
370        self.client
371            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
372            .await
373    }
374
375    /**
376     * Detach a disk from an instance.
377     *
378     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/disks/detach` endpoint.
379     *
380     * **Parameters:**
381     *
382     * * `instance_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.
383     * * `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.
384     * * `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.
385     */
386    pub async fn disks_detach(
387        &self,
388        instance_name: &str,
389        organization_name: &str,
390        project_name: &str,
391        body: &crate::types::DiskIdentifier,
392    ) -> Result<crate::types::Disk> {
393        let url = format!(
394            "/organizations/{}/projects/{}/instances/{}/disks/detach",
395            crate::progenitor_support::encode_path(organization_name),
396            crate::progenitor_support::encode_path(project_name),
397            crate::progenitor_support::encode_path(instance_name),
398        );
399
400        self.client
401            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
402            .await
403    }
404
405    /**
406     * List external IP addresses.
407     *
408     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/external-ips` endpoint.
409     *
410     * **Parameters:**
411     *
412     * * `instance_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.
413     * * `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.
414     * * `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.
415     */
416    pub async fn external_ip_list(
417        &self,
418        instance_name: &str,
419        organization_name: &str,
420        project_name: &str,
421    ) -> Result<Vec<crate::types::ExternalIp>> {
422        let url = format!(
423            "/organizations/{}/projects/{}/instances/{}/external-ips",
424            crate::progenitor_support::encode_path(organization_name),
425            crate::progenitor_support::encode_path(project_name),
426            crate::progenitor_support::encode_path(instance_name),
427        );
428
429        let resp: crate::types::ExternalIpResultsPage = self.client.get(&url, None).await?;
430
431        // Return our response data.
432        Ok(resp.items)
433    }
434
435    /**
436     * List external IP addresses.
437     *
438     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/external-ips` endpoint.
439     *
440     * As opposed to `external_ip_list`, this function returns all the pages of the request at once.
441     */
442    pub async fn external_ip_list_all(
443        &self,
444        instance_name: &str,
445        organization_name: &str,
446        project_name: &str,
447    ) -> Result<Vec<crate::types::ExternalIp>> {
448        let url = format!(
449            "/organizations/{}/projects/{}/instances/{}/external-ips",
450            crate::progenitor_support::encode_path(organization_name),
451            crate::progenitor_support::encode_path(project_name),
452            crate::progenitor_support::encode_path(instance_name),
453        );
454
455        let mut resp: crate::types::ExternalIpResultsPage = self.client.get(&url, None).await?;
456
457        let mut items = resp.items;
458        let mut page = resp.next_page;
459
460        // Paginate if we should.
461        while !page.is_empty() {
462            if !url.contains('?') {
463                resp = self
464                    .client
465                    .get(&format!("{}?page={}", url, page), None)
466                    .await?;
467            } else {
468                resp = self
469                    .client
470                    .get(&format!("{}&page={}", url, page), None)
471                    .await?;
472            }
473
474            items.append(&mut resp.items);
475
476            if !resp.next_page.is_empty() && resp.next_page != page {
477                page = resp.next_page.to_string();
478            } else {
479                page = "".to_string();
480            }
481        }
482
483        // Return our response data.
484        Ok(items)
485    }
486
487    /**
488     * Migrate an instance.
489     *
490     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/migrate` endpoint.
491     *
492     * **Parameters:**
493     *
494     * * `instance_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.
495     * * `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.
496     * * `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.
497     */
498    pub async fn migrate(
499        &self,
500        instance_name: &str,
501        organization_name: &str,
502        project_name: &str,
503        body: &crate::types::InstanceMigrate,
504    ) -> Result<crate::types::Instance> {
505        let url = format!(
506            "/organizations/{}/projects/{}/instances/{}/migrate",
507            crate::progenitor_support::encode_path(organization_name),
508            crate::progenitor_support::encode_path(project_name),
509            crate::progenitor_support::encode_path(instance_name),
510        );
511
512        self.client
513            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
514            .await
515    }
516
517    /**
518     * List network interfaces.
519     *
520     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/network-interfaces` endpoint.
521     *
522     * **Parameters:**
523     *
524     * * `limit: u32` -- Maximum number of items returned by a single call.
525     * * `page_token: &str` -- Token returned by previous call to retrieve the subsequent page.
526     * * `sort_by: crate::types::NameSortMode` -- Supported set of sort modes for scanning by name only
527     *  
528     *  Currently, we only support scanning in ascending order.
529     * * `instance_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.
530     * * `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.
531     * * `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.
532     */
533    pub async fn network_interfaces_get(
534        &self,
535        instance_name: &str,
536        limit: u32,
537        organization_name: &str,
538        page_token: &str,
539        project_name: &str,
540        sort_by: crate::types::NameSortMode,
541    ) -> Result<Vec<crate::types::NetworkInterface>> {
542        let mut query_args: Vec<(String, String)> = Default::default();
543        if !limit.to_string().is_empty() {
544            query_args.push(("limit".to_string(), limit.to_string()));
545        }
546        if !page_token.is_empty() {
547            query_args.push(("page_token".to_string(), page_token.to_string()));
548        }
549        if !sort_by.to_string().is_empty() {
550            query_args.push(("sort_by".to_string(), sort_by.to_string()));
551        }
552        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
553        let url = format!(
554            "/organizations/{}/projects/{}/instances/{}/network-interfaces?{}",
555            crate::progenitor_support::encode_path(organization_name),
556            crate::progenitor_support::encode_path(project_name),
557            crate::progenitor_support::encode_path(instance_name),
558            query_
559        );
560
561        let resp: crate::types::NetworkInterfaceResultsPage = self.client.get(&url, None).await?;
562
563        // Return our response data.
564        Ok(resp.items)
565    }
566
567    /**
568     * List network interfaces.
569     *
570     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/network-interfaces` endpoint.
571     *
572     * As opposed to `network_interfaces_get`, this function returns all the pages of the request at once.
573     */
574    pub async fn network_interfaces_get_all(
575        &self,
576        instance_name: &str,
577        organization_name: &str,
578        project_name: &str,
579        sort_by: crate::types::NameSortMode,
580    ) -> Result<Vec<crate::types::NetworkInterface>> {
581        let mut query_args: Vec<(String, String)> = Default::default();
582        if !sort_by.to_string().is_empty() {
583            query_args.push(("sort_by".to_string(), sort_by.to_string()));
584        }
585        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
586        let url = format!(
587            "/organizations/{}/projects/{}/instances/{}/network-interfaces?{}",
588            crate::progenitor_support::encode_path(organization_name),
589            crate::progenitor_support::encode_path(project_name),
590            crate::progenitor_support::encode_path(instance_name),
591            query_
592        );
593
594        let mut resp: crate::types::NetworkInterfaceResultsPage =
595            self.client.get(&url, None).await?;
596
597        let mut items = resp.items;
598        let mut page = resp.next_page;
599
600        // Paginate if we should.
601        while !page.is_empty() {
602            if !url.contains('?') {
603                resp = self
604                    .client
605                    .get(&format!("{}?page={}", url, page), None)
606                    .await?;
607            } else {
608                resp = self
609                    .client
610                    .get(&format!("{}&page={}", url, page), None)
611                    .await?;
612            }
613
614            items.append(&mut resp.items);
615
616            if !resp.next_page.is_empty() && resp.next_page != page {
617                page = resp.next_page.to_string();
618            } else {
619                page = "".to_string();
620            }
621        }
622
623        // Return our response data.
624        Ok(items)
625    }
626
627    /**
628     * Create a network interface.
629     *
630     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/network-interfaces` endpoint.
631     *
632     * **Parameters:**
633     *
634     * * `instance_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.
635     * * `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.
636     * * `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.
637     */
638    pub async fn network_interfaces_post(
639        &self,
640        instance_name: &str,
641        organization_name: &str,
642        project_name: &str,
643        body: &crate::types::NetworkInterfaceCreate,
644    ) -> Result<crate::types::NetworkInterface> {
645        let url = format!(
646            "/organizations/{}/projects/{}/instances/{}/network-interfaces",
647            crate::progenitor_support::encode_path(organization_name),
648            crate::progenitor_support::encode_path(project_name),
649            crate::progenitor_support::encode_path(instance_name),
650        );
651
652        self.client
653            .post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
654            .await
655    }
656
657    /**
658     * Fetch a network interface.
659     *
660     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/network-interfaces/{interface_name}` endpoint.
661     *
662     * **Parameters:**
663     *
664     * * `instance_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.
665     * * `interface_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.
666     * * `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.
667     * * `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.
668     */
669    pub async fn network_interfaces_get_interface(
670        &self,
671        instance_name: &str,
672        interface_name: &str,
673        organization_name: &str,
674        project_name: &str,
675    ) -> Result<crate::types::NetworkInterface> {
676        let url = format!(
677            "/organizations/{}/projects/{}/instances/{}/network-interfaces/{}",
678            crate::progenitor_support::encode_path(organization_name),
679            crate::progenitor_support::encode_path(project_name),
680            crate::progenitor_support::encode_path(instance_name),
681            crate::progenitor_support::encode_path(interface_name),
682        );
683
684        self.client.get(&url, None).await
685    }
686
687    /**
688     * Update a network interface.
689     *
690     * This function performs a `PUT` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/network-interfaces/{interface_name}` endpoint.
691     *
692     * **Parameters:**
693     *
694     * * `instance_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.
695     * * `interface_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.
696     * * `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.
697     * * `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.
698     */
699    pub async fn network_interfaces_put_interface(
700        &self,
701        instance_name: &str,
702        interface_name: &str,
703        organization_name: &str,
704        project_name: &str,
705        body: &crate::types::NetworkInterfaceUpdate,
706    ) -> Result<crate::types::NetworkInterface> {
707        let url = format!(
708            "/organizations/{}/projects/{}/instances/{}/network-interfaces/{}",
709            crate::progenitor_support::encode_path(organization_name),
710            crate::progenitor_support::encode_path(project_name),
711            crate::progenitor_support::encode_path(instance_name),
712            crate::progenitor_support::encode_path(interface_name),
713        );
714
715        self.client
716            .put(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
717            .await
718    }
719
720    /**
721     * Delete a network interface.
722     *
723     * This function performs a `DELETE` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/network-interfaces/{interface_name}` endpoint.
724     *
725     * Note that the primary interface for an instance cannot be deleted if there are any secondary interfaces. A new primary interface must be designated first. The primary interface can be deleted if there are no secondary interfaces.
726     *
727     * **Parameters:**
728     *
729     * * `instance_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.
730     * * `interface_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.
731     * * `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.
732     * * `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.
733     */
734    pub async fn network_interfaces_delete_interface(
735        &self,
736        instance_name: &str,
737        interface_name: &str,
738        organization_name: &str,
739        project_name: &str,
740    ) -> Result<()> {
741        let url = format!(
742            "/organizations/{}/projects/{}/instances/{}/network-interfaces/{}",
743            crate::progenitor_support::encode_path(organization_name),
744            crate::progenitor_support::encode_path(project_name),
745            crate::progenitor_support::encode_path(instance_name),
746            crate::progenitor_support::encode_path(interface_name),
747        );
748
749        self.client.delete(&url, None).await
750    }
751
752    /**
753     * Reboot an instance.
754     *
755     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/reboot` endpoint.
756     *
757     * **Parameters:**
758     *
759     * * `instance_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.
760     * * `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.
761     * * `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.
762     */
763    pub async fn reboot(
764        &self,
765        instance_name: &str,
766        organization_name: &str,
767        project_name: &str,
768    ) -> Result<crate::types::Instance> {
769        let url = format!(
770            "/organizations/{}/projects/{}/instances/{}/reboot",
771            crate::progenitor_support::encode_path(organization_name),
772            crate::progenitor_support::encode_path(project_name),
773            crate::progenitor_support::encode_path(instance_name),
774        );
775
776        self.client.post(&url, None).await
777    }
778
779    /**
780     * Fetch an instance's serial console.
781     *
782     * This function performs a `GET` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/serial-console` endpoint.
783     *
784     * **Parameters:**
785     *
786     * * `instance_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.
787     * * `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.
788     * * `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.
789     * * `from_start: u64` -- Character index in the serial buffer from which to read, counting the bytes output since instance start. If this is not provided, `most_recent` must be provided, and if this \*is\* provided, `most_recent` must \*not\* be provided.
790     * * `max_bytes: u64` -- Maximum number of bytes of buffered serial console contents to return. If the requested range runs to the end of the available buffer, the data returned will be shorter than `max_bytes`.
791     * * `most_recent: u64` -- Character index in the serial buffer from which to read, counting \*backward\* from the most recently buffered data retrieved from the instance. (See note on `from_start` about mutual exclusivity).
792     */
793    pub async fn serial_get(
794        &self,
795        from_start: Option<u64>,
796        instance_name: &str,
797        max_bytes: Option<u64>,
798        most_recent: Option<u64>,
799        organization_name: &str,
800        project_name: &str,
801    ) -> Result<crate::types::InstanceSerialConsoleData> {
802        let mut query_args: Vec<(String, String)> = Default::default();
803        if let Some(u) = from_start {
804            query_args.push(("from_start".to_string(), u.to_string()));
805        }
806        if let Some(u) = max_bytes {
807            query_args.push(("max_bytes".to_string(), u.to_string()));
808        }
809        if let Some(u) = most_recent {
810            query_args.push(("most_recent".to_string(), u.to_string()));
811        }
812        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
813        let url = format!(
814            "/organizations/{}/projects/{}/instances/{}/serial-console?{}",
815            crate::progenitor_support::encode_path(organization_name),
816            crate::progenitor_support::encode_path(project_name),
817            crate::progenitor_support::encode_path(instance_name),
818            query_
819        );
820
821        self.client.get(&url, None).await
822    }
823
824    /**
825     * Boot an instance.
826     *
827     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/start` endpoint.
828     *
829     * **Parameters:**
830     *
831     * * `instance_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.
832     * * `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.
833     * * `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.
834     */
835    pub async fn start(
836        &self,
837        instance_name: &str,
838        organization_name: &str,
839        project_name: &str,
840    ) -> Result<crate::types::Instance> {
841        let url = format!(
842            "/organizations/{}/projects/{}/instances/{}/start",
843            crate::progenitor_support::encode_path(organization_name),
844            crate::progenitor_support::encode_path(project_name),
845            crate::progenitor_support::encode_path(instance_name),
846        );
847
848        self.client.post(&url, None).await
849    }
850
851    /**
852     * Halt an instance.
853     *
854     * This function performs a `POST` to the `/organizations/{organization_name}/projects/{project_name}/instances/{instance_name}/stop` endpoint.
855     *
856     * **Parameters:**
857     *
858     * * `instance_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.
859     * * `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.
860     * * `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.
861     */
862    pub async fn stop(
863        &self,
864        instance_name: &str,
865        organization_name: &str,
866        project_name: &str,
867    ) -> Result<crate::types::Instance> {
868        let url = format!(
869            "/organizations/{}/projects/{}/instances/{}/stop",
870            crate::progenitor_support::encode_path(organization_name),
871            crate::progenitor_support::encode_path(project_name),
872            crate::progenitor_support::encode_path(instance_name),
873        );
874
875        self.client.post(&url, None).await
876    }
877}