nomad_client/apis/
evaluations_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 `get_allocations_for_evaluation`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAllocationsForEvaluationError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method `get_evaluation`
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetEvaluationError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method `get_evaluations`
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetEvaluationsError {
36    UnknownValue(serde_json::Value),
37}
38
39
40pub async fn get_allocations_for_evaluation(configuration: &configuration::Configuration, eval_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>) -> Result<Vec<crate::models::AllocationListStub>, Error<GetAllocationsForEvaluationError>> {
41
42    let local_var_client = &configuration.client;
43
44    let local_var_uri_str = format!("{}/evaluation/{eval_id}/allocations", configuration.base_path, eval_id=crate::apis::urlencode(eval_id));
45    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
46
47    if let Some(ref local_var_str) = namespace {
48        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
49    }
50    if let Some(ref local_var_str) = region {
51        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
52    }
53    if let Some(ref local_var_str) = index {
54        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
55    }
56    if let Some(ref local_var_str) = wait {
57        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
58    }
59    if let Some(ref local_var_user_agent) = configuration.user_agent {
60        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
61    }
62
63    let local_var_req = local_var_req_builder.build()?;
64    let local_var_resp = local_var_client.execute(local_var_req).await?;
65
66    let local_var_status = local_var_resp.status();
67    let local_var_content = local_var_resp.text().await?;
68
69    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
70        serde_json::from_str(&local_var_content).map_err(Error::from)
71    } else {
72        let local_var_entity: Option<GetAllocationsForEvaluationError> = serde_json::from_str(&local_var_content).ok();
73        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
74        Err(Error::ResponseError(local_var_error))
75    }
76}
77
78pub async fn get_evaluation(configuration: &configuration::Configuration, eval_id: &str, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>) -> Result<crate::models::Evaluation, Error<GetEvaluationError>> {
79
80    let local_var_client = &configuration.client;
81
82    let local_var_uri_str = format!("{}/evaluation/{eval_id}", configuration.base_path, eval_id=crate::apis::urlencode(eval_id));
83    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
84
85    if let Some(ref local_var_str) = namespace {
86        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
87    }
88    if let Some(ref local_var_str) = region {
89        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
90    }
91    if let Some(ref local_var_str) = index {
92        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
93    }
94    if let Some(ref local_var_str) = wait {
95        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
96    }
97    if let Some(ref local_var_user_agent) = configuration.user_agent {
98        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
99    }
100
101    let local_var_req = local_var_req_builder.build()?;
102    let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104    let local_var_status = local_var_resp.status();
105    let local_var_content = local_var_resp.text().await?;
106
107    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
108        serde_json::from_str(&local_var_content).map_err(Error::from)
109    } else {
110        let local_var_entity: Option<GetEvaluationError> = serde_json::from_str(&local_var_content).ok();
111        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
112        Err(Error::ResponseError(local_var_error))
113    }
114}
115
116pub async fn get_evaluations(configuration: &configuration::Configuration, namespace: Option<&str>, region: Option<&str>, index: Option<i64>, wait: Option<&str>, prefix: Option<&str>) -> Result<Vec<crate::models::Evaluation>, Error<GetEvaluationsError>> {
117
118    let local_var_client = &configuration.client;
119
120    let local_var_uri_str = format!("{}/evaluations", configuration.base_path);
121    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
122
123    if let Some(ref local_var_str) = namespace {
124        local_var_req_builder = local_var_req_builder.query(&[("namespace", &local_var_str.to_string())]);
125    }
126    if let Some(ref local_var_str) = region {
127        local_var_req_builder = local_var_req_builder.query(&[("region", &local_var_str.to_string())]);
128    }
129    if let Some(ref local_var_str) = index {
130        local_var_req_builder = local_var_req_builder.query(&[("index", &local_var_str.to_string())]);
131    }
132    if let Some(ref local_var_str) = wait {
133        local_var_req_builder = local_var_req_builder.query(&[("wait", &local_var_str.to_string())]);
134    }
135    if let Some(ref local_var_str) = prefix {
136        local_var_req_builder = local_var_req_builder.query(&[("prefix", &local_var_str.to_string())]);
137    }
138    if let Some(ref local_var_user_agent) = configuration.user_agent {
139        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
140    }
141
142    let local_var_req = local_var_req_builder.build()?;
143    let local_var_resp = local_var_client.execute(local_var_req).await?;
144
145    let local_var_status = local_var_resp.status();
146    let local_var_content = local_var_resp.text().await?;
147
148    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
149        serde_json::from_str(&local_var_content).map_err(Error::from)
150    } else {
151        let local_var_entity: Option<GetEvaluationsError> = serde_json::from_str(&local_var_content).ok();
152        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
153        Err(Error::ResponseError(local_var_error))
154    }
155}
156