podman_rest_client/v4/apis/
exec.rs

1use crate::api_common::config::HasConfig;
2use crate::api_common::request;
3use crate::api_common::Error;
4use http::request::Builder;
5use std::future::Future;
6use std::pin::Pin;
7pub trait Exec: HasConfig + Send + Sync {
8    /// POST /libpod/containers/{name}/exec
9    ///
10    /// Create an exec instance
11    ///
12    /// Create an exec session to run a command inside a running container. Exec sessions will be automatically removed 5 minutes after they exit.
13    fn container_exec_libpod<'a>(
14        &'a self,
15        name: &'a str,
16        control: crate::v4::models::ContainerExecLibpodBody,
17    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
18        Box::pin(request::execute_request_unit(
19            self.get_config(),
20            move |mut req_builder: Builder| {
21                req_builder = req_builder.method("POST");
22                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
23                let mut request_path = request_url.path().to_owned();
24                if request_path.ends_with('/') {
25                    request_path.pop();
26                }
27                request_path.push_str("/libpod/containers/{name}/exec");
28                request_path = request_path.replace("{name}", name);
29                request_url.set_path(&request_path);
30                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
31                req_builder = req_builder.uri(hyper_uri);
32                let body = serde_json::to_string(&control)?;
33                req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
34                req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
35                Ok(req_builder.body(body)?)
36            },
37        ))
38    }
39    /// GET /libpod/exec/{id}/json
40    ///
41    /// Inspect an exec instance
42    ///
43    /// Return low-level information about an exec instance.
44    fn exec_inspect_libpod<'a>(
45        &'a self,
46        id: &'a str,
47    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
48        Box::pin(request::execute_request_unit(
49            self.get_config(),
50            move |mut req_builder: Builder| {
51                req_builder = req_builder.method("GET");
52                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
53                let mut request_path = request_url.path().to_owned();
54                if request_path.ends_with('/') {
55                    request_path.pop();
56                }
57                request_path.push_str("/libpod/exec/{id}/json");
58                request_path = request_path.replace("{id}", id);
59                request_url.set_path(&request_path);
60                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
61                req_builder = req_builder.uri(hyper_uri);
62                Ok(req_builder.body(String::new())?)
63            },
64        ))
65    }
66    /// POST /libpod/exec/{id}/resize
67    ///
68    /// Resize an exec instance
69    ///
70    /// Resize the TTY session used by an exec instance. This endpoint only works if tty was specified as part of creating and starting the exec instance.
71    fn exec_resize_libpod<'a>(
72        &'a self,
73        id: &'a str,
74        params: Option<crate::v4::params::ExecResizeLibpod>,
75    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
76        Box::pin(request::execute_request_unit(
77            self.get_config(),
78            move |mut req_builder: Builder| {
79                req_builder = req_builder.method("POST");
80                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
81                let mut request_path = request_url.path().to_owned();
82                if request_path.ends_with('/') {
83                    request_path.pop();
84                }
85                request_path.push_str("/libpod/exec/{id}/resize");
86                request_path = request_path.replace("{id}", id);
87                request_url.set_path(&request_path);
88                if let Some(params) = &params {
89                    let mut query_pairs = request_url.query_pairs_mut();
90                    if let Some(h) = params.h {
91                        query_pairs.append_pair("h", &h.to_string());
92                    }
93                    if let Some(w) = params.w {
94                        query_pairs.append_pair("w", &w.to_string());
95                    }
96                }
97                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
98                req_builder = req_builder.uri(hyper_uri);
99                Ok(req_builder.body(String::new())?)
100            },
101        ))
102    }
103    /// POST /libpod/exec/{id}/start
104    ///
105    /// Start an exec instance
106    ///
107    /// Starts a previously set up exec instance. If detach is true, this endpoint returns immediately after starting the command.
108    /// Otherwise, it sets up an interactive session with the command. The stream format is the same as the attach endpoint.
109    fn exec_start_libpod<'a>(
110        &'a self,
111        id: &'a str,
112        control: crate::v4::models::ExecStartLibpodBody,
113    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>> {
114        Box::pin(request::execute_request_unit(
115            self.get_config(),
116            move |mut req_builder: Builder| {
117                req_builder = req_builder.method("POST");
118                let mut request_url = url::Url::parse(self.get_config().get_base_path())?;
119                let mut request_path = request_url.path().to_owned();
120                if request_path.ends_with('/') {
121                    request_path.pop();
122                }
123                request_path.push_str("/libpod/exec/{id}/start");
124                request_path = request_path.replace("{id}", id);
125                request_url.set_path(&request_path);
126                let hyper_uri: hyper::Uri = request_url.as_str().parse()?;
127                req_builder = req_builder.uri(hyper_uri);
128                let body = serde_json::to_string(&control)?;
129                req_builder = req_builder.header(hyper::header::CONTENT_TYPE, "application/json");
130                req_builder = req_builder.header(hyper::header::CONTENT_LENGTH, body.len());
131                Ok(req_builder.body(body)?)
132            },
133        ))
134    }
135}