Skip to main content

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