Skip to main content

openstack_sdk_load_balancer/v2/healthmonitor/
list.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//
15// WARNING: This file is automatically generated from OpenAPI schema using
16// `openstack-codegenerator`.
17
18//! Lists all health monitors for the project.
19//!
20//! Use the `fields` query parameter to control which fields are returned in
21//! the response body. Additionally, you can filter results by using query
22//! string parameters. For information, see
23//! [Filtering and column selection](#filtering).
24//!
25//! Administrative users can specify a project ID that is different than their
26//! own to list health monitors for other projects.
27//!
28//! The list might be empty.
29//!
30use derive_builder::Builder;
31use http::{HeaderMap, HeaderName, HeaderValue};
32
33use openstack_sdk_core::api::rest_endpoint_prelude::*;
34
35use std::borrow::Cow;
36
37use openstack_sdk_core::api::Pageable;
38#[derive(Builder, Debug, Clone)]
39#[builder(setter(strip_option))]
40pub struct Request<'a> {
41    /// The type of health monitor.
42    #[builder(default, setter(into))]
43    _type: Option<Cow<'a, str>>,
44
45    /// The administrative state of the resource
46    #[builder(default)]
47    admin_state_up: Option<bool>,
48
49    /// The UTC date and timestamp when the resource was created.
50    #[builder(default, setter(into))]
51    created_at: Option<Cow<'a, str>>,
52
53    /// The time, in seconds, between sending probes to members.
54    #[builder(default)]
55    delay: Option<i32>,
56
57    /// A human-readable description for the resource.
58    #[builder(default, setter(into))]
59    description: Option<Cow<'a, str>>,
60
61    /// The list of HTTP status codes expected in response from the member to
62    /// declare it healthy.
63    #[builder(default, setter(into))]
64    expected_codes: Option<Cow<'a, str>>,
65
66    /// The HTTP method that the health monitor uses for requests.
67    #[builder(default, setter(into))]
68    http_method: Option<Cow<'a, str>>,
69
70    /// The ID of the resource
71    #[builder(default, setter(into))]
72    id: Option<Cow<'a, str>>,
73
74    /// Page size
75    #[builder(default)]
76    limit: Option<i32>,
77
78    /// ID of the last item in the previous list
79    #[builder(default, setter(into))]
80    marker: Option<Cow<'a, str>>,
81
82    /// The number of successful checks before changing the operating status of
83    /// the member to ONLINE. A valid value is from 1 to 10.
84    #[builder(default)]
85    max_retries: Option<i32>,
86
87    /// The number of allowed check failures before changing the operating
88    /// status of the member to ERROR. A valid value is from 1 to 10.
89    #[builder(default)]
90    max_retries_down: Option<i32>,
91
92    /// Human-readable name of the resource.
93    #[builder(default, setter(into))]
94    name: Option<Cow<'a, str>>,
95
96    /// Return the list of entities that do not have one or more of the given
97    /// tags.
98    #[builder(default, setter(into))]
99    not_tags: Option<Cow<'a, str>>,
100
101    /// Return the list of entities that do not have at least one of the given
102    /// tags.
103    #[builder(default, setter(into))]
104    not_tags_any: Option<Cow<'a, str>>,
105
106    /// The operating status of the resource.
107    #[builder(default, setter(into))]
108    operating_status: Option<Cow<'a, str>>,
109
110    /// The page direction.
111    #[builder(default)]
112    page_reverse: Option<bool>,
113
114    /// The ID of the pool.
115    #[builder(default, setter(into))]
116    pool_id: Option<Cow<'a, str>>,
117
118    /// The ID of the project owning this resource.
119    #[builder(default, setter(into))]
120    project_id: Option<Cow<'a, str>>,
121
122    /// The provisioning status of the resource.
123    #[builder(default, setter(into))]
124    provisioning_status: Option<Cow<'a, str>>,
125
126    /// Return the list of entities that have this tag or tags.
127    #[builder(default, setter(into))]
128    tags: Option<Cow<'a, str>>,
129
130    /// Return the list of entities that have one or more of the given tags.
131    #[builder(default, setter(into))]
132    tags_any: Option<Cow<'a, str>>,
133
134    /// The maximum time, in seconds, that a monitor waits to connect before it
135    /// times out.
136    #[builder(default)]
137    timeout: Option<i32>,
138
139    /// The UTC date and timestamp when the resource was last updated.
140    #[builder(default, setter(into))]
141    updated_at: Option<Cow<'a, str>>,
142
143    /// The HTTP URL path of the request sent by the monitor to test the health
144    /// of a backend member. Must be a string that begins with a forward slash
145    /// (/).
146    #[builder(default, setter(into))]
147    url_path: Option<Cow<'a, str>>,
148
149    #[builder(setter(name = "_headers"), default, private)]
150    _headers: Option<HeaderMap>,
151}
152impl<'a> Request<'a> {
153    /// Create a builder for the endpoint.
154    pub fn builder() -> RequestBuilder<'a> {
155        RequestBuilder::default()
156    }
157}
158
159impl<'a> RequestBuilder<'a> {
160    /// Add a single header to the Healthmonitor.
161    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
162    where
163        K: Into<HeaderName>,
164        V: Into<HeaderValue>,
165    {
166        self._headers
167            .get_or_insert(None)
168            .get_or_insert_with(HeaderMap::new)
169            .insert(header_name.into(), header_value.into());
170        self
171    }
172
173    /// Add multiple headers.
174    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
175    where
176        I: Iterator<Item = T>,
177        T: Into<(Option<HeaderName>, HeaderValue)>,
178    {
179        self._headers
180            .get_or_insert(None)
181            .get_or_insert_with(HeaderMap::new)
182            .extend(iter.map(Into::into));
183        self
184    }
185}
186
187impl RestEndpoint for Request<'_> {
188    fn method(&self) -> http::Method {
189        http::Method::GET
190    }
191
192    fn endpoint(&self) -> Cow<'static, str> {
193        "lbaas/healthmonitors".to_string().into()
194    }
195
196    fn parameters(&self) -> QueryParams<'_> {
197        let mut params = QueryParams::default();
198        params.push_opt("admin_state_up", self.admin_state_up);
199        params.push_opt("created_at", self.created_at.as_ref());
200        params.push_opt("delay", self.delay);
201        params.push_opt("description", self.description.as_ref());
202        params.push_opt("expected_codes", self.expected_codes.as_ref());
203        params.push_opt("http_method", self.http_method.as_ref());
204        params.push_opt("id", self.id.as_ref());
205        params.push_opt("limit", self.limit);
206        params.push_opt("marker", self.marker.as_ref());
207        params.push_opt("max_retries", self.max_retries);
208        params.push_opt("max_retries_down", self.max_retries_down);
209        params.push_opt("name", self.name.as_ref());
210        params.push_opt("not-tags", self.not_tags.as_ref());
211        params.push_opt("not-tags-any", self.not_tags_any.as_ref());
212        params.push_opt("operating_status", self.operating_status.as_ref());
213        params.push_opt("page_reverse", self.page_reverse);
214        params.push_opt("pool_id", self.pool_id.as_ref());
215        params.push_opt("project_id", self.project_id.as_ref());
216        params.push_opt("provisioning_status", self.provisioning_status.as_ref());
217        params.push_opt("tags", self.tags.as_ref());
218        params.push_opt("tags-any", self.tags_any.as_ref());
219        params.push_opt("timeout", self.timeout);
220        params.push_opt("type", self._type.as_ref());
221        params.push_opt("updated_at", self.updated_at.as_ref());
222        params.push_opt("url_path", self.url_path.as_ref());
223
224        params
225    }
226
227    fn service_type(&self) -> ServiceType {
228        ServiceType::LoadBalancer
229    }
230
231    fn response_key(&self) -> Option<Cow<'static, str>> {
232        Some("healthmonitors".into())
233    }
234
235    /// Returns headers to be set into the request
236    fn request_headers(&self) -> Option<&HeaderMap> {
237        self._headers.as_ref()
238    }
239
240    /// Returns required API version
241    fn api_version(&self) -> Option<ApiVersion> {
242        Some(ApiVersion::new(2, 0))
243    }
244}
245impl Pageable for Request<'_> {}
246
247#[cfg(test)]
248mod tests {
249    use super::*;
250    use http::{HeaderName, HeaderValue};
251    use httpmock::MockServer;
252    #[cfg(feature = "sync")]
253    use openstack_sdk_core::api::Query;
254    use openstack_sdk_core::test::client::FakeOpenStackClient;
255    use openstack_sdk_core::types::ServiceType;
256    use serde_json::json;
257
258    #[test]
259    fn test_service_type() {
260        assert_eq!(
261            Request::builder().build().unwrap().service_type(),
262            ServiceType::LoadBalancer
263        );
264    }
265
266    #[test]
267    fn test_response_key() {
268        assert_eq!(
269            Request::builder().build().unwrap().response_key().unwrap(),
270            "healthmonitors"
271        );
272    }
273
274    #[cfg(feature = "sync")]
275    #[test]
276    fn endpoint() {
277        let server = MockServer::start();
278        let client = FakeOpenStackClient::new(server.base_url());
279        let mock = server.mock(|when, then| {
280            when.method(httpmock::Method::GET)
281                .path("/lbaas/healthmonitors".to_string());
282
283            then.status(200)
284                .header("content-type", "application/json")
285                .json_body(json!({ "healthmonitors": {} }));
286        });
287
288        let endpoint = Request::builder().build().unwrap();
289        let _: serde_json::Value = endpoint.query(&client).unwrap();
290        mock.assert();
291    }
292
293    #[cfg(feature = "sync")]
294    #[test]
295    fn endpoint_headers() {
296        let server = MockServer::start();
297        let client = FakeOpenStackClient::new(server.base_url());
298        let mock = server.mock(|when, then| {
299            when.method(httpmock::Method::GET)
300                .path("/lbaas/healthmonitors".to_string())
301                .header("foo", "bar")
302                .header("not_foo", "not_bar");
303            then.status(200)
304                .header("content-type", "application/json")
305                .json_body(json!({ "healthmonitors": {} }));
306        });
307
308        let endpoint = Request::builder()
309            .headers(
310                [(
311                    Some(HeaderName::from_static("foo")),
312                    HeaderValue::from_static("bar"),
313                )]
314                .into_iter(),
315            )
316            .header(
317                HeaderName::from_static("not_foo"),
318                HeaderValue::from_static("not_bar"),
319            )
320            .build()
321            .unwrap();
322        let _: serde_json::Value = endpoint.query(&client).unwrap();
323        mock.assert();
324    }
325}