Skip to main content

openstack_sdk_load_balancer/v2/pool/
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 pools 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 pools 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 administrative state of the resource
42    #[builder(default)]
43    admin_state_up: Option<bool>,
44
45    /// A list of ALPN protocols. Available protocols: http/1.0, http/1.1, h2
46    #[builder(default, setter(into))]
47    alpn_protocols: Option<Cow<'a, str>>,
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    /// A human-readable description for the resource.
54    #[builder(default, setter(into))]
55    description: Option<Cow<'a, str>>,
56
57    /// The ID of the resource
58    #[builder(default, setter(into))]
59    id: Option<Cow<'a, str>>,
60
61    /// Page size
62    #[builder(default)]
63    limit: Option<i32>,
64
65    /// The ID of the load balancer for the pool.
66    #[builder(default, setter(into))]
67    loadbalancer_id: Option<Cow<'a, str>>,
68
69    /// ID of the last item in the previous list
70    #[builder(default, setter(into))]
71    marker: Option<Cow<'a, str>>,
72
73    /// Human-readable name of the resource.
74    #[builder(default, setter(into))]
75    name: Option<Cow<'a, str>>,
76
77    /// Return the list of entities that do not have one or more of the given
78    /// tags.
79    #[builder(default, setter(into))]
80    not_tags: Option<Cow<'a, str>>,
81
82    /// Return the list of entities that do not have at least one of the given
83    /// tags.
84    #[builder(default, setter(into))]
85    not_tags_any: Option<Cow<'a, str>>,
86
87    /// The operating status of the resource.
88    #[builder(default, setter(into))]
89    operating_status: Option<Cow<'a, str>>,
90
91    /// The page direction.
92    #[builder(default)]
93    page_reverse: Option<bool>,
94
95    /// The ID of the project owning this resource.
96    #[builder(default, setter(into))]
97    project_id: Option<Cow<'a, str>>,
98
99    /// The provisioning status of the resource.
100    #[builder(default, setter(into))]
101    provisioning_status: Option<Cow<'a, str>>,
102
103    /// Return the list of entities that have this tag or tags.
104    #[builder(default, setter(into))]
105    tags: Option<Cow<'a, str>>,
106
107    /// Return the list of entities that have one or more of the given tags.
108    #[builder(default, setter(into))]
109    tags_any: Option<Cow<'a, str>>,
110
111    /// List of ciphers in OpenSSL format
112    #[builder(default, setter(into))]
113    tls_ciphers: Option<Cow<'a, str>>,
114
115    #[builder(default)]
116    tls_enabled: Option<bool>,
117
118    /// A list of TLS protocol versions.
119    #[builder(default, setter(into))]
120    tls_versions: Option<Cow<'a, str>>,
121
122    /// The UTC date and timestamp when the resource was last updated.
123    #[builder(default, setter(into))]
124    updated_at: Option<Cow<'a, str>>,
125
126    #[builder(setter(name = "_headers"), default, private)]
127    _headers: Option<HeaderMap>,
128}
129impl<'a> Request<'a> {
130    /// Create a builder for the endpoint.
131    pub fn builder() -> RequestBuilder<'a> {
132        RequestBuilder::default()
133    }
134}
135
136impl<'a> RequestBuilder<'a> {
137    /// Add a single header to the Pool.
138    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
139    where
140        K: Into<HeaderName>,
141        V: Into<HeaderValue>,
142    {
143        self._headers
144            .get_or_insert(None)
145            .get_or_insert_with(HeaderMap::new)
146            .insert(header_name.into(), header_value.into());
147        self
148    }
149
150    /// Add multiple headers.
151    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
152    where
153        I: Iterator<Item = T>,
154        T: Into<(Option<HeaderName>, HeaderValue)>,
155    {
156        self._headers
157            .get_or_insert(None)
158            .get_or_insert_with(HeaderMap::new)
159            .extend(iter.map(Into::into));
160        self
161    }
162}
163
164impl RestEndpoint for Request<'_> {
165    fn method(&self) -> http::Method {
166        http::Method::GET
167    }
168
169    fn endpoint(&self) -> Cow<'static, str> {
170        "lbaas/pools".to_string().into()
171    }
172
173    fn parameters(&self) -> QueryParams<'_> {
174        let mut params = QueryParams::default();
175        params.push_opt("admin_state_up", self.admin_state_up);
176        params.push_opt("alpn_protocols", self.alpn_protocols.as_ref());
177        params.push_opt("created_at", self.created_at.as_ref());
178        params.push_opt("description", self.description.as_ref());
179        params.push_opt("id", self.id.as_ref());
180        params.push_opt("limit", self.limit);
181        params.push_opt("loadbalancer_id", self.loadbalancer_id.as_ref());
182        params.push_opt("marker", self.marker.as_ref());
183        params.push_opt("name", self.name.as_ref());
184        params.push_opt("not-tags", self.not_tags.as_ref());
185        params.push_opt("not-tags-any", self.not_tags_any.as_ref());
186        params.push_opt("operating_status", self.operating_status.as_ref());
187        params.push_opt("page_reverse", self.page_reverse);
188        params.push_opt("project_id", self.project_id.as_ref());
189        params.push_opt("provisioning_status", self.provisioning_status.as_ref());
190        params.push_opt("tags", self.tags.as_ref());
191        params.push_opt("tags-any", self.tags_any.as_ref());
192        params.push_opt("tls_ciphers", self.tls_ciphers.as_ref());
193        params.push_opt("tls_enabled", self.tls_enabled);
194        params.push_opt("tls_versions", self.tls_versions.as_ref());
195        params.push_opt("updated_at", self.updated_at.as_ref());
196
197        params
198    }
199
200    fn service_type(&self) -> ServiceType {
201        ServiceType::LoadBalancer
202    }
203
204    fn response_key(&self) -> Option<Cow<'static, str>> {
205        Some("pools".into())
206    }
207
208    /// Returns headers to be set into the request
209    fn request_headers(&self) -> Option<&HeaderMap> {
210        self._headers.as_ref()
211    }
212
213    /// Returns required API version
214    fn api_version(&self) -> Option<ApiVersion> {
215        Some(ApiVersion::new(2, 0))
216    }
217}
218impl Pageable for Request<'_> {}
219
220#[cfg(test)]
221mod tests {
222    use super::*;
223    use http::{HeaderName, HeaderValue};
224    use httpmock::MockServer;
225    #[cfg(feature = "sync")]
226    use openstack_sdk_core::api::Query;
227    use openstack_sdk_core::test::client::FakeOpenStackClient;
228    use openstack_sdk_core::types::ServiceType;
229    use serde_json::json;
230
231    #[test]
232    fn test_service_type() {
233        assert_eq!(
234            Request::builder().build().unwrap().service_type(),
235            ServiceType::LoadBalancer
236        );
237    }
238
239    #[test]
240    fn test_response_key() {
241        assert_eq!(
242            Request::builder().build().unwrap().response_key().unwrap(),
243            "pools"
244        );
245    }
246
247    #[cfg(feature = "sync")]
248    #[test]
249    fn endpoint() {
250        let server = MockServer::start();
251        let client = FakeOpenStackClient::new(server.base_url());
252        let mock = server.mock(|when, then| {
253            when.method(httpmock::Method::GET)
254                .path("/lbaas/pools".to_string());
255
256            then.status(200)
257                .header("content-type", "application/json")
258                .json_body(json!({ "pools": {} }));
259        });
260
261        let endpoint = Request::builder().build().unwrap();
262        let _: serde_json::Value = endpoint.query(&client).unwrap();
263        mock.assert();
264    }
265
266    #[cfg(feature = "sync")]
267    #[test]
268    fn endpoint_headers() {
269        let server = MockServer::start();
270        let client = FakeOpenStackClient::new(server.base_url());
271        let mock = server.mock(|when, then| {
272            when.method(httpmock::Method::GET)
273                .path("/lbaas/pools".to_string())
274                .header("foo", "bar")
275                .header("not_foo", "not_bar");
276            then.status(200)
277                .header("content-type", "application/json")
278                .json_body(json!({ "pools": {} }));
279        });
280
281        let endpoint = Request::builder()
282            .headers(
283                [(
284                    Some(HeaderName::from_static("foo")),
285                    HeaderValue::from_static("bar"),
286                )]
287                .into_iter(),
288            )
289            .header(
290                HeaderName::from_static("not_foo"),
291                HeaderValue::from_static("not_bar"),
292            )
293            .build()
294            .unwrap();
295        let _: serde_json::Value = endpoint.query(&client).unwrap();
296        mock.assert();
297    }
298}