Skip to main content

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