Skip to main content

openstack_sdk_load_balancer/v2/availability_zone_profile/
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 Availability Zone Profiles.
19//!
20use derive_builder::Builder;
21use http::{HeaderMap, HeaderName, HeaderValue};
22
23use openstack_sdk_core::api::rest_endpoint_prelude::*;
24
25use std::borrow::Cow;
26
27use openstack_sdk_core::api::Pageable;
28#[derive(Builder, Debug, Clone)]
29#[builder(setter(strip_option))]
30pub struct Request<'a> {
31    #[builder(default, setter(into))]
32    availability_zone_data: Option<Cow<'a, str>>,
33
34    #[builder(default, setter(into))]
35    id: Option<Cow<'a, str>>,
36
37    /// Page size
38    #[builder(default)]
39    limit: Option<i32>,
40
41    /// ID of the last item in the previous list
42    #[builder(default, setter(into))]
43    marker: Option<Cow<'a, str>>,
44
45    #[builder(default, setter(into))]
46    name: Option<Cow<'a, str>>,
47
48    /// The page direction.
49    #[builder(default)]
50    page_reverse: Option<bool>,
51
52    #[builder(default, setter(into))]
53    provider_name: Option<Cow<'a, str>>,
54
55    #[builder(setter(name = "_headers"), default, private)]
56    _headers: Option<HeaderMap>,
57}
58impl<'a> Request<'a> {
59    /// Create a builder for the endpoint.
60    pub fn builder() -> RequestBuilder<'a> {
61        RequestBuilder::default()
62    }
63}
64
65impl<'a> RequestBuilder<'a> {
66    /// Add a single header to the Availability_Zone_Profile.
67    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
68    where
69        K: Into<HeaderName>,
70        V: Into<HeaderValue>,
71    {
72        self._headers
73            .get_or_insert(None)
74            .get_or_insert_with(HeaderMap::new)
75            .insert(header_name.into(), header_value.into());
76        self
77    }
78
79    /// Add multiple headers.
80    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
81    where
82        I: Iterator<Item = T>,
83        T: Into<(Option<HeaderName>, HeaderValue)>,
84    {
85        self._headers
86            .get_or_insert(None)
87            .get_or_insert_with(HeaderMap::new)
88            .extend(iter.map(Into::into));
89        self
90    }
91}
92
93impl RestEndpoint for Request<'_> {
94    fn method(&self) -> http::Method {
95        http::Method::GET
96    }
97
98    fn endpoint(&self) -> Cow<'static, str> {
99        "lbaas/availabilityzoneprofiles".to_string().into()
100    }
101
102    fn parameters(&self) -> QueryParams<'_> {
103        let mut params = QueryParams::default();
104        params.push_opt(
105            "availability_zone_data",
106            self.availability_zone_data.as_ref(),
107        );
108        params.push_opt("id", self.id.as_ref());
109        params.push_opt("limit", self.limit);
110        params.push_opt("marker", self.marker.as_ref());
111        params.push_opt("name", self.name.as_ref());
112        params.push_opt("page_reverse", self.page_reverse);
113        params.push_opt("provider_name", self.provider_name.as_ref());
114
115        params
116    }
117
118    fn service_type(&self) -> ServiceType {
119        ServiceType::LoadBalancer
120    }
121
122    fn response_key(&self) -> Option<Cow<'static, str>> {
123        Some("availability_zone_profiles".into())
124    }
125
126    /// Returns headers to be set into the request
127    fn request_headers(&self) -> Option<&HeaderMap> {
128        self._headers.as_ref()
129    }
130
131    /// Returns required API version
132    fn api_version(&self) -> Option<ApiVersion> {
133        Some(ApiVersion::new(2, 0))
134    }
135}
136impl Pageable for Request<'_> {}
137
138#[cfg(test)]
139mod tests {
140    use super::*;
141    use http::{HeaderName, HeaderValue};
142    use httpmock::MockServer;
143    #[cfg(feature = "sync")]
144    use openstack_sdk_core::api::Query;
145    use openstack_sdk_core::test::client::FakeOpenStackClient;
146    use openstack_sdk_core::types::ServiceType;
147    use serde_json::json;
148
149    #[test]
150    fn test_service_type() {
151        assert_eq!(
152            Request::builder().build().unwrap().service_type(),
153            ServiceType::LoadBalancer
154        );
155    }
156
157    #[test]
158    fn test_response_key() {
159        assert_eq!(
160            Request::builder().build().unwrap().response_key().unwrap(),
161            "availability_zone_profiles"
162        );
163    }
164
165    #[cfg(feature = "sync")]
166    #[test]
167    fn endpoint() {
168        let server = MockServer::start();
169        let client = FakeOpenStackClient::new(server.base_url());
170        let mock = server.mock(|when, then| {
171            when.method(httpmock::Method::GET)
172                .path("/lbaas/availabilityzoneprofiles".to_string());
173
174            then.status(200)
175                .header("content-type", "application/json")
176                .json_body(json!({ "availability_zone_profiles": {} }));
177        });
178
179        let endpoint = Request::builder().build().unwrap();
180        let _: serde_json::Value = endpoint.query(&client).unwrap();
181        mock.assert();
182    }
183
184    #[cfg(feature = "sync")]
185    #[test]
186    fn endpoint_headers() {
187        let server = MockServer::start();
188        let client = FakeOpenStackClient::new(server.base_url());
189        let mock = server.mock(|when, then| {
190            when.method(httpmock::Method::GET)
191                .path("/lbaas/availabilityzoneprofiles".to_string())
192                .header("foo", "bar")
193                .header("not_foo", "not_bar");
194            then.status(200)
195                .header("content-type", "application/json")
196                .json_body(json!({ "availability_zone_profiles": {} }));
197        });
198
199        let endpoint = Request::builder()
200            .headers(
201                [(
202                    Some(HeaderName::from_static("foo")),
203                    HeaderValue::from_static("bar"),
204                )]
205                .into_iter(),
206            )
207            .header(
208                HeaderName::from_static("not_foo"),
209                HeaderValue::from_static("not_bar"),
210            )
211            .build()
212            .unwrap();
213        let _: serde_json::Value = endpoint.query(&client).unwrap();
214        mock.assert();
215    }
216}