openstack_sdk/api/block_storage/v3/manageable_volume/
get.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//! Returns a summary list of volumes available to manage.
19//!
20use derive_builder::Builder;
21use http::{HeaderMap, HeaderName, HeaderValue};
22
23use crate::api::rest_endpoint_prelude::*;
24
25use std::borrow::Cow;
26
27use crate::api::Pageable;
28#[derive(Builder, Debug, Clone)]
29#[builder(setter(strip_option))]
30pub struct Request<'a> {
31    /// Requests a page size of items. Returns a number of items up to a limit
32    /// value. Use the limit parameter to make an initial limited request and
33    /// use the ID of the last-seen item from the response as the marker
34    /// parameter value in a subsequent limited request.
35    #[builder(default)]
36    limit: Option<i32>,
37
38    /// The ID of the last-seen item. Use the limit parameter to make an
39    /// initial limited request and use the ID of the last-seen item from the
40    /// response as the marker parameter value in a subsequent limited request.
41    #[builder(default, setter(into))]
42    marker: Option<Cow<'a, str>>,
43
44    /// Used in conjunction with limit to return a slice of items. offset is
45    /// where to start in the list.
46    #[builder(default)]
47    offset: Option<i32>,
48
49    /// Comma-separated list of sort keys and optional sort directions in the
50    /// form of < key > [: < direction > ]. A valid direction is asc
51    /// (ascending) or desc (descending).
52    #[builder(default, setter(into))]
53    sort: Option<Cow<'a, str>>,
54
55    /// Sorts by one or more sets of attribute and sort direction combinations.
56    /// If you omit the sort direction in a set, default is desc. Deprecated in
57    /// favour of the combined sort parameter.
58    #[builder(default, setter(into))]
59    sort_dir: Option<Cow<'a, str>>,
60
61    /// Sorts by an attribute. A valid value is name, status, container_format,
62    /// disk_format, size, id, created_at, or updated_at. Default is
63    /// created_at. The API uses the natural sorting direction of the sort_key
64    /// attribute value. Deprecated in favour of the combined sort parameter.
65    #[builder(default, setter(into))]
66    sort_key: Option<Cow<'a, str>>,
67
68    #[builder(setter(name = "_headers"), default, private)]
69    _headers: Option<HeaderMap>,
70}
71impl<'a> Request<'a> {
72    /// Create a builder for the endpoint.
73    pub fn builder() -> RequestBuilder<'a> {
74        RequestBuilder::default()
75    }
76}
77
78impl<'a> RequestBuilder<'a> {
79    /// Add a single header to the Manageable_Volume.
80    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
81    where
82        K: Into<HeaderName>,
83        V: Into<HeaderValue>,
84    {
85        self._headers
86            .get_or_insert(None)
87            .get_or_insert_with(HeaderMap::new)
88            .insert(header_name.into(), header_value.into());
89        self
90    }
91
92    /// Add multiple headers.
93    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
94    where
95        I: Iterator<Item = T>,
96        T: Into<(Option<HeaderName>, HeaderValue)>,
97    {
98        self._headers
99            .get_or_insert(None)
100            .get_or_insert_with(HeaderMap::new)
101            .extend(iter.map(Into::into));
102        self
103    }
104}
105
106impl RestEndpoint for Request<'_> {
107    fn method(&self) -> http::Method {
108        http::Method::GET
109    }
110
111    fn endpoint(&self) -> Cow<'static, str> {
112        "manageable_volumes".to_string().into()
113    }
114
115    fn parameters(&self) -> QueryParams<'_> {
116        let mut params = QueryParams::default();
117        params.push_opt("limit", self.limit);
118        params.push_opt("marker", self.marker.as_ref());
119        params.push_opt("offset", self.offset);
120        params.push_opt("sort", self.sort.as_ref());
121        params.push_opt("sort_dir", self.sort_dir.as_ref());
122        params.push_opt("sort_key", self.sort_key.as_ref());
123
124        params
125    }
126
127    fn service_type(&self) -> ServiceType {
128        ServiceType::BlockStorage
129    }
130
131    fn response_key(&self) -> Option<Cow<'static, str>> {
132        None
133    }
134
135    /// Returns headers to be set into the request
136    fn request_headers(&self) -> Option<&HeaderMap> {
137        self._headers.as_ref()
138    }
139
140    /// Returns required API version
141    fn api_version(&self) -> Option<ApiVersion> {
142        Some(ApiVersion::new(3, 0))
143    }
144}
145impl Pageable for Request<'_> {}
146
147#[cfg(test)]
148mod tests {
149    use super::*;
150    #[cfg(feature = "sync")]
151    use crate::api::Query;
152    use crate::test::client::FakeOpenStackClient;
153    use crate::types::ServiceType;
154    use http::{HeaderName, HeaderValue};
155    use httpmock::MockServer;
156    use serde_json::json;
157
158    #[test]
159    fn test_service_type() {
160        assert_eq!(
161            Request::builder().build().unwrap().service_type(),
162            ServiceType::BlockStorage
163        );
164    }
165
166    #[test]
167    fn test_response_key() {
168        assert!(Request::builder().build().unwrap().response_key().is_none())
169    }
170
171    #[cfg(feature = "sync")]
172    #[test]
173    fn endpoint() {
174        let server = MockServer::start();
175        let client = FakeOpenStackClient::new(server.base_url());
176        let mock = server.mock(|when, then| {
177            when.method(httpmock::Method::GET)
178                .path("/manageable_volumes".to_string());
179
180            then.status(200)
181                .header("content-type", "application/json")
182                .json_body(json!({ "dummy": {} }));
183        });
184
185        let endpoint = Request::builder().build().unwrap();
186        let _: serde_json::Value = endpoint.query(&client).unwrap();
187        mock.assert();
188    }
189
190    #[cfg(feature = "sync")]
191    #[test]
192    fn endpoint_headers() {
193        let server = MockServer::start();
194        let client = FakeOpenStackClient::new(server.base_url());
195        let mock = server.mock(|when, then| {
196            when.method(httpmock::Method::GET)
197                .path("/manageable_volumes".to_string())
198                .header("foo", "bar")
199                .header("not_foo", "not_bar");
200            then.status(200)
201                .header("content-type", "application/json")
202                .json_body(json!({ "dummy": {} }));
203        });
204
205        let endpoint = Request::builder()
206            .headers(
207                [(
208                    Some(HeaderName::from_static("foo")),
209                    HeaderValue::from_static("bar"),
210                )]
211                .into_iter(),
212            )
213            .header(
214                HeaderName::from_static("not_foo"),
215                HeaderValue::from_static("not_bar"),
216            )
217            .build()
218            .unwrap();
219        let _: serde_json::Value = endpoint.query(&client).unwrap();
220        mock.assert();
221    }
222}