Skip to main content

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