Skip to main content

openstack_sdk_load_balancer/v2/amphorae/
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 amphora for the project.
19//!
20//! If you are not an administrative user, the service returns the HTTP
21//! `Forbidden (403)` response code.
22//!
23//! Use the `fields` query parameter to control which fields are returned in
24//! the response body. Additionally, you can filter results by using query
25//! string parameters. For information, see
26//! [Filtering and column selection](#filtering).
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    #[builder(default, setter(into))]
42    cached_zone: Option<Cow<'a, str>>,
43
44    #[builder(default, setter(into))]
45    cert_busy: Option<Cow<'a, str>>,
46
47    #[builder(default, setter(into))]
48    cert_expiration: Option<Cow<'a, str>>,
49
50    #[builder(default, setter(into))]
51    compute_flavor: Option<Cow<'a, str>>,
52
53    #[builder(default, setter(into))]
54    compute_id: Option<Cow<'a, str>>,
55
56    #[builder(default, setter(into))]
57    created_at: Option<Cow<'a, str>>,
58
59    #[builder(default, setter(into))]
60    ha_ip: Option<Cow<'a, str>>,
61
62    #[builder(default, setter(into))]
63    ha_port_id: Option<Cow<'a, str>>,
64
65    #[builder(default, setter(into))]
66    id: Option<Cow<'a, str>>,
67
68    #[builder(default, setter(into))]
69    image_id: Option<Cow<'a, str>>,
70
71    #[builder(default, setter(into))]
72    lb_network_ip: Option<Cow<'a, str>>,
73
74    /// Page size
75    #[builder(default)]
76    limit: Option<i32>,
77
78    #[builder(default, setter(into))]
79    loadbalancer_id: Option<Cow<'a, str>>,
80
81    /// ID of the last item in the previous list
82    #[builder(default, setter(into))]
83    marker: Option<Cow<'a, str>>,
84
85    /// The page direction.
86    #[builder(default)]
87    page_reverse: Option<bool>,
88
89    #[builder(default, setter(into))]
90    role: Option<Cow<'a, str>>,
91
92    #[builder(default, setter(into))]
93    status: Option<Cow<'a, str>>,
94
95    #[builder(default, setter(into))]
96    updated_at: Option<Cow<'a, str>>,
97
98    #[builder(default, setter(into))]
99    vrrp_id: Option<Cow<'a, str>>,
100
101    #[builder(default, setter(into))]
102    vrrp_interface: Option<Cow<'a, str>>,
103
104    #[builder(default, setter(into))]
105    vrrp_ip: Option<Cow<'a, str>>,
106
107    #[builder(default, setter(into))]
108    vrrp_port_id: Option<Cow<'a, str>>,
109
110    #[builder(default, setter(into))]
111    vrrp_priority: Option<Cow<'a, str>>,
112
113    #[builder(setter(name = "_headers"), default, private)]
114    _headers: Option<HeaderMap>,
115}
116impl<'a> Request<'a> {
117    /// Create a builder for the endpoint.
118    pub fn builder() -> RequestBuilder<'a> {
119        RequestBuilder::default()
120    }
121}
122
123impl<'a> RequestBuilder<'a> {
124    /// Add a single header to the Amphorae.
125    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
126    where
127        K: Into<HeaderName>,
128        V: Into<HeaderValue>,
129    {
130        self._headers
131            .get_or_insert(None)
132            .get_or_insert_with(HeaderMap::new)
133            .insert(header_name.into(), header_value.into());
134        self
135    }
136
137    /// Add multiple headers.
138    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
139    where
140        I: Iterator<Item = T>,
141        T: Into<(Option<HeaderName>, HeaderValue)>,
142    {
143        self._headers
144            .get_or_insert(None)
145            .get_or_insert_with(HeaderMap::new)
146            .extend(iter.map(Into::into));
147        self
148    }
149}
150
151impl RestEndpoint for Request<'_> {
152    fn method(&self) -> http::Method {
153        http::Method::GET
154    }
155
156    fn endpoint(&self) -> Cow<'static, str> {
157        "octavia/amphorae".to_string().into()
158    }
159
160    fn parameters(&self) -> QueryParams<'_> {
161        let mut params = QueryParams::default();
162        params.push_opt("cached_zone", self.cached_zone.as_ref());
163        params.push_opt("cert_busy", self.cert_busy.as_ref());
164        params.push_opt("cert_expiration", self.cert_expiration.as_ref());
165        params.push_opt("compute_flavor", self.compute_flavor.as_ref());
166        params.push_opt("compute_id", self.compute_id.as_ref());
167        params.push_opt("created_at", self.created_at.as_ref());
168        params.push_opt("ha_ip", self.ha_ip.as_ref());
169        params.push_opt("ha_port_id", self.ha_port_id.as_ref());
170        params.push_opt("id", self.id.as_ref());
171        params.push_opt("image_id", self.image_id.as_ref());
172        params.push_opt("lb_network_ip", self.lb_network_ip.as_ref());
173        params.push_opt("limit", self.limit);
174        params.push_opt("loadbalancer_id", self.loadbalancer_id.as_ref());
175        params.push_opt("marker", self.marker.as_ref());
176        params.push_opt("page_reverse", self.page_reverse);
177        params.push_opt("role", self.role.as_ref());
178        params.push_opt("status", self.status.as_ref());
179        params.push_opt("updated_at", self.updated_at.as_ref());
180        params.push_opt("vrrp_id", self.vrrp_id.as_ref());
181        params.push_opt("vrrp_interface", self.vrrp_interface.as_ref());
182        params.push_opt("vrrp_ip", self.vrrp_ip.as_ref());
183        params.push_opt("vrrp_port_id", self.vrrp_port_id.as_ref());
184        params.push_opt("vrrp_priority", self.vrrp_priority.as_ref());
185
186        params
187    }
188
189    fn service_type(&self) -> ServiceType {
190        ServiceType::LoadBalancer
191    }
192
193    fn response_key(&self) -> Option<Cow<'static, str>> {
194        Some("amphorae".into())
195    }
196
197    /// Returns headers to be set into the request
198    fn request_headers(&self) -> Option<&HeaderMap> {
199        self._headers.as_ref()
200    }
201
202    /// Returns required API version
203    fn api_version(&self) -> Option<ApiVersion> {
204        Some(ApiVersion::new(2, 0))
205    }
206}
207impl Pageable for Request<'_> {}
208
209#[cfg(test)]
210mod tests {
211    use super::*;
212    use http::{HeaderName, HeaderValue};
213    use httpmock::MockServer;
214    #[cfg(feature = "sync")]
215    use openstack_sdk_core::api::Query;
216    use openstack_sdk_core::test::client::FakeOpenStackClient;
217    use openstack_sdk_core::types::ServiceType;
218    use serde_json::json;
219
220    #[test]
221    fn test_service_type() {
222        assert_eq!(
223            Request::builder().build().unwrap().service_type(),
224            ServiceType::LoadBalancer
225        );
226    }
227
228    #[test]
229    fn test_response_key() {
230        assert_eq!(
231            Request::builder().build().unwrap().response_key().unwrap(),
232            "amphorae"
233        );
234    }
235
236    #[cfg(feature = "sync")]
237    #[test]
238    fn endpoint() {
239        let server = MockServer::start();
240        let client = FakeOpenStackClient::new(server.base_url());
241        let mock = server.mock(|when, then| {
242            when.method(httpmock::Method::GET)
243                .path("/octavia/amphorae".to_string());
244
245            then.status(200)
246                .header("content-type", "application/json")
247                .json_body(json!({ "amphorae": {} }));
248        });
249
250        let endpoint = Request::builder().build().unwrap();
251        let _: serde_json::Value = endpoint.query(&client).unwrap();
252        mock.assert();
253    }
254
255    #[cfg(feature = "sync")]
256    #[test]
257    fn endpoint_headers() {
258        let server = MockServer::start();
259        let client = FakeOpenStackClient::new(server.base_url());
260        let mock = server.mock(|when, then| {
261            when.method(httpmock::Method::GET)
262                .path("/octavia/amphorae".to_string())
263                .header("foo", "bar")
264                .header("not_foo", "not_bar");
265            then.status(200)
266                .header("content-type", "application/json")
267                .json_body(json!({ "amphorae": {} }));
268        });
269
270        let endpoint = Request::builder()
271            .headers(
272                [(
273                    Some(HeaderName::from_static("foo")),
274                    HeaderValue::from_static("bar"),
275                )]
276                .into_iter(),
277            )
278            .header(
279                HeaderName::from_static("not_foo"),
280                HeaderValue::from_static("not_bar"),
281            )
282            .build()
283            .unwrap();
284        let _: serde_json::Value = endpoint.query(&client).unwrap();
285        mock.assert();
286    }
287}