nomad_client/apis/
deployments_api.rs

1/*
2 * Nomad
3 *
4 * Nomad OpenApi specification
5 *
6 * The version of the OpenAPI document: 0.11.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `fail_deployment`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum FailDeploymentError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method `get_allocations_for_deployment`
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetAllocationsForDeploymentError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method `get_deployment`
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetDeploymentError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method `get_deployments`
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetDeploymentsError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method `pause_deployment`
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PauseDeploymentError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method `promote_deployment`
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PromoteDeploymentError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method `set_allocation_health_in_deployment`
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum SetAllocationHealthInDeploymentError {
64    UnknownValue(serde_json::Value),
65}
66
67
68pub async fn fail_deployment(configuration: &configuration::Configuration, deployment_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>) -> Result<crate::models::DeploymentUpdateResponse, Error<FailDeploymentError>> {
69
70    let local_var_client = &configuration.client;
71
72    let local_var_uri_str = format!("{}/deployment/fail/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
73    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
74
75    if let Some(ref local_var_str) = namespace {
76        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
77    }
78    if let Some(ref local_var_str) = region {
79        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
80    }
81    if let Some(ref local_var_str) = index {
82        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
83    }
84    if let Some(ref local_var_str) = wait {
85        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
86    }
87    if let Some(ref local_var_user_agent) = configuration.user_agent {
88        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
89    }
90
91    let local_var_req = local_var_req_builder.build()?;
92    let local_var_resp = local_var_client.execute(local_var_req).await?;
93
94    let local_var_status = local_var_resp.status();
95    let local_var_content = local_var_resp.text().await?;
96
97    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
98        serde_json::from_str(&local_var_content).map_err(Error::from)
99    } else {
100        let local_var_entity: Option<FailDeploymentError> = serde_json::from_str(&local_var_content).ok();
101        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
102        Err(Error::ResponseError(local_var_error))
103    }
104}
105
106pub async fn get_allocations_for_deployment(configuration: &configuration::Configuration, deployment_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>) -> Result<Vec<crate::models::AllocationListStub>, Error<GetAllocationsForDeploymentError>> {
107
108    let local_var_client = &configuration.client;
109
110    let local_var_uri_str = format!("{}/deployment/allocations/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
111    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
112
113    if let Some(ref local_var_str) = namespace {
114        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
115    }
116    if let Some(ref local_var_str) = region {
117        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
118    }
119    if let Some(ref local_var_str) = index {
120        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
121    }
122    if let Some(ref local_var_str) = wait {
123        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
124    }
125    if let Some(ref local_var_user_agent) = configuration.user_agent {
126        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
127    }
128
129    let local_var_req = local_var_req_builder.build()?;
130    let local_var_resp = local_var_client.execute(local_var_req).await?;
131
132    let local_var_status = local_var_resp.status();
133    let local_var_content = local_var_resp.text().await?;
134
135    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
136        serde_json::from_str(&local_var_content).map_err(Error::from)
137    } else {
138        let local_var_entity: Option<GetAllocationsForDeploymentError> = serde_json::from_str(&local_var_content).ok();
139        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
140        Err(Error::ResponseError(local_var_error))
141    }
142}
143
144pub async fn get_deployment(configuration: &configuration::Configuration, deployment_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>) -> Result<crate::models::Deployment, Error<GetDeploymentError>> {
145
146    let local_var_client = &configuration.client;
147
148    let local_var_uri_str = format!("{}/deployment/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
149    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
150
151    if let Some(ref local_var_str) = namespace {
152        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
153    }
154    if let Some(ref local_var_str) = region {
155        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
156    }
157    if let Some(ref local_var_str) = index {
158        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
159    }
160    if let Some(ref local_var_str) = wait {
161        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
162    }
163    if let Some(ref local_var_user_agent) = configuration.user_agent {
164        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
165    }
166
167    let local_var_req = local_var_req_builder.build()?;
168    let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170    let local_var_status = local_var_resp.status();
171    let local_var_content = local_var_resp.text().await?;
172
173    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174        serde_json::from_str(&local_var_content).map_err(Error::from)
175    } else {
176        let local_var_entity: Option<GetDeploymentError> = serde_json::from_str(&local_var_content).ok();
177        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
178        Err(Error::ResponseError(local_var_error))
179    }
180}
181
182pub async fn get_deployments(configuration: &configuration::Configuration, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>, prefix: Option<&str>) -> Result<Vec<crate::models::Deployment>, Error<GetDeploymentsError>> {
183
184    let local_var_client = &configuration.client;
185
186    let local_var_uri_str = format!("{}/deployments", configuration.base_path);
187    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
188
189    if let Some(ref local_var_str) = namespace {
190        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
191    }
192    if let Some(ref local_var_str) = region {
193        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
194    }
195    if let Some(ref local_var_str) = index {
196        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
197    }
198    if let Some(ref local_var_str) = wait {
199        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
200    }
201    if let Some(ref local_var_str) = prefix {
202        local_var_req_builder = local_var_req_builder.query(&[("prefix", &local_var_str.to_string())]);
203    }
204    if let Some(ref local_var_user_agent) = configuration.user_agent {
205        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
206    }
207
208    let local_var_req = local_var_req_builder.build()?;
209    let local_var_resp = local_var_client.execute(local_var_req).await?;
210
211    let local_var_status = local_var_resp.status();
212    let local_var_content = local_var_resp.text().await?;
213
214    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
215        serde_json::from_str(&local_var_content).map_err(Error::from)
216    } else {
217        let local_var_entity: Option<GetDeploymentsError> = serde_json::from_str(&local_var_content).ok();
218        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
219        Err(Error::ResponseError(local_var_error))
220    }
221}
222
223pub async fn pause_deployment(configuration: &configuration::Configuration, deployment_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>, deployment_pause_request: Option<crate::models::DeploymentPauseRequest>) -> Result<crate::models::DeploymentUpdateResponse, Error<PauseDeploymentError>> {
224
225    let local_var_client = &configuration.client;
226
227    let local_var_uri_str = format!("{}/deployment/pause/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
228    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
229
230    if let Some(ref local_var_str) = namespace {
231        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
232    }
233    if let Some(ref local_var_str) = region {
234        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
235    }
236    if let Some(ref local_var_str) = index {
237        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
238    }
239    if let Some(ref local_var_str) = wait {
240        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
241    }
242    if let Some(ref local_var_user_agent) = configuration.user_agent {
243        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244    }
245    local_var_req_builder = local_var_req_builder.json(&deployment_pause_request);
246
247    let local_var_req = local_var_req_builder.build()?;
248    let local_var_resp = local_var_client.execute(local_var_req).await?;
249
250    let local_var_status = local_var_resp.status();
251    let local_var_content = local_var_resp.text().await?;
252
253    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
254        serde_json::from_str(&local_var_content).map_err(Error::from)
255    } else {
256        let local_var_entity: Option<PauseDeploymentError> = serde_json::from_str(&local_var_content).ok();
257        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
258        Err(Error::ResponseError(local_var_error))
259    }
260}
261
262pub async fn promote_deployment(configuration: &configuration::Configuration, deployment_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>, deployment_promote_request: Option<crate::models::DeploymentPromoteRequest>) -> Result<crate::models::DeploymentUpdateResponse, Error<PromoteDeploymentError>> {
263
264    let local_var_client = &configuration.client;
265
266    let local_var_uri_str = format!("{}/deployment/promote/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
267    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
268
269    if let Some(ref local_var_str) = namespace {
270        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
271    }
272    if let Some(ref local_var_str) = region {
273        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
274    }
275    if let Some(ref local_var_str) = index {
276        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
277    }
278    if let Some(ref local_var_str) = wait {
279        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
280    }
281    if let Some(ref local_var_user_agent) = configuration.user_agent {
282        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
283    }
284    local_var_req_builder = local_var_req_builder.json(&deployment_promote_request);
285
286    let local_var_req = local_var_req_builder.build()?;
287    let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289    let local_var_status = local_var_resp.status();
290    let local_var_content = local_var_resp.text().await?;
291
292    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
293        serde_json::from_str(&local_var_content).map_err(Error::from)
294    } else {
295        let local_var_entity: Option<PromoteDeploymentError> = serde_json::from_str(&local_var_content).ok();
296        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
297        Err(Error::ResponseError(local_var_error))
298    }
299}
300
301/// In some use cases, automatic detection of allocation health may not be desired. As such those task groups can be marked with an upgrade policy that uses health_check = \"manual\". Those allocations must have their health marked manually using this endpoint. Marking an allocation as healthy will allow the rolling upgrade to proceed. Marking it as failed will cause the deployment to fail. This endpoint only triggers a rollback if the most recent stable version of the job has a different specification than the job being reverted
302pub async fn set_allocation_health_in_deployment(configuration: &configuration::Configuration, deployment_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>, deployment_alloc_health_request: Option<crate::models::DeploymentAllocHealthRequest>) -> Result<crate::models::DeploymentUpdateResponse, Error<SetAllocationHealthInDeploymentError>> {
303
304    let local_var_client = &configuration.client;
305
306    let local_var_uri_str = format!("{}/deployment/allocation-health/{deployment_id}", configuration.base_path, deployment_id=crate::apis::urlencode(deployment_id));
307    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
308
309    if let Some(ref local_var_str) = namespace {
310        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
311    }
312    if let Some(ref local_var_str) = region {
313        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
314    }
315    if let Some(ref local_var_str) = index {
316        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
317    }
318    if let Some(ref local_var_str) = wait {
319        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
320    }
321    if let Some(ref local_var_user_agent) = configuration.user_agent {
322        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
323    }
324    local_var_req_builder = local_var_req_builder.json(&deployment_alloc_health_request);
325
326    let local_var_req = local_var_req_builder.build()?;
327    let local_var_resp = local_var_client.execute(local_var_req).await?;
328
329    let local_var_status = local_var_resp.status();
330    let local_var_content = local_var_resp.text().await?;
331
332    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
333        serde_json::from_str(&local_var_content).map_err(Error::from)
334    } else {
335        let local_var_entity: Option<SetAllocationHealthInDeploymentError> = serde_json::from_str(&local_var_content).ok();
336        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
337        Err(Error::ResponseError(local_var_error))
338    }
339}
340