openstack_sdk/api/compute/v2/assisted_volume_snapshot/
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//! Deletes an assisted volume snapshot.
19//!
20//! To make this request, add the `delete_info` query parameter to the URI, as
21//! follows:
22//!
23//! DELETE
24//! /os-assisted-volume-snapshots/421752a6-acf6-4b2d-bc7a-119f9148cd8c?delete_info=’{“volume_id”:
25//! “521752a6-acf6-4b2d-bc7a-119f9148cd8c”}’
26//!
27//! Normal response codes: 204
28//!
29//! Error response codes: badRequest(400), unauthorized(401), forbidden(403),
30//! itemNotFound(404)
31//!
32use derive_builder::Builder;
33use http::{HeaderMap, HeaderName, HeaderValue};
34
35use crate::api::rest_endpoint_prelude::*;
36
37use std::borrow::Cow;
38
39#[derive(Builder, Debug, Clone)]
40#[builder(setter(strip_option))]
41pub struct Request<'a> {
42    #[builder(default, setter(into))]
43    delete_info: Option<Cow<'a, str>>,
44
45    /// id parameter for /v2.1/os-assisted-volume-snapshots/{id} API
46    #[builder(default, setter(into))]
47    id: Cow<'a, str>,
48
49    #[builder(setter(name = "_headers"), default, private)]
50    _headers: Option<HeaderMap>,
51}
52impl<'a> Request<'a> {
53    /// Create a builder for the endpoint.
54    pub fn builder() -> RequestBuilder<'a> {
55        RequestBuilder::default()
56    }
57}
58
59impl<'a> RequestBuilder<'a> {
60    /// Add a single header to the Assisted_Volume_Snapshot.
61    pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
62    where
63        K: Into<HeaderName>,
64        V: Into<HeaderValue>,
65    {
66        self._headers
67            .get_or_insert(None)
68            .get_or_insert_with(HeaderMap::new)
69            .insert(header_name.into(), header_value.into());
70        self
71    }
72
73    /// Add multiple headers.
74    pub fn headers<I, T>(&mut self, iter: I) -> &mut Self
75    where
76        I: Iterator<Item = T>,
77        T: Into<(Option<HeaderName>, HeaderValue)>,
78    {
79        self._headers
80            .get_or_insert(None)
81            .get_or_insert_with(HeaderMap::new)
82            .extend(iter.map(Into::into));
83        self
84    }
85}
86
87impl RestEndpoint for Request<'_> {
88    fn method(&self) -> http::Method {
89        http::Method::DELETE
90    }
91
92    fn endpoint(&self) -> Cow<'static, str> {
93        format!("os-assisted-volume-snapshots/{id}", id = self.id.as_ref(),).into()
94    }
95
96    fn parameters(&self) -> QueryParams<'_> {
97        let mut params = QueryParams::default();
98        params.push_opt("delete_info", self.delete_info.as_ref());
99
100        params
101    }
102
103    fn service_type(&self) -> ServiceType {
104        ServiceType::Compute
105    }
106
107    fn response_key(&self) -> Option<Cow<'static, str>> {
108        None
109    }
110
111    /// Returns headers to be set into the request
112    fn request_headers(&self) -> Option<&HeaderMap> {
113        self._headers.as_ref()
114    }
115
116    /// Returns required API version
117    fn api_version(&self) -> Option<ApiVersion> {
118        Some(ApiVersion::new(2, 1))
119    }
120}
121
122#[cfg(test)]
123mod tests {
124    use super::*;
125    #[cfg(feature = "sync")]
126    use crate::api::Query;
127    use crate::test::client::FakeOpenStackClient;
128    use crate::types::ServiceType;
129    use http::{HeaderName, HeaderValue};
130    use httpmock::MockServer;
131    use serde_json::json;
132
133    #[test]
134    fn test_service_type() {
135        assert_eq!(
136            Request::builder().build().unwrap().service_type(),
137            ServiceType::Compute
138        );
139    }
140
141    #[test]
142    fn test_response_key() {
143        assert!(Request::builder().build().unwrap().response_key().is_none())
144    }
145
146    #[cfg(feature = "sync")]
147    #[test]
148    fn endpoint() {
149        let server = MockServer::start();
150        let client = FakeOpenStackClient::new(server.base_url());
151        let mock = server.mock(|when, then| {
152            when.method(httpmock::Method::DELETE)
153                .path(format!("/os-assisted-volume-snapshots/{id}", id = "id",));
154
155            then.status(200)
156                .header("content-type", "application/json")
157                .json_body(json!({ "dummy": {} }));
158        });
159
160        let endpoint = Request::builder().id("id").build().unwrap();
161        let _: serde_json::Value = endpoint.query(&client).unwrap();
162        mock.assert();
163    }
164
165    #[cfg(feature = "sync")]
166    #[test]
167    fn endpoint_headers() {
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::DELETE)
172                .path(format!("/os-assisted-volume-snapshots/{id}", id = "id",))
173                .header("foo", "bar")
174                .header("not_foo", "not_bar");
175            then.status(200)
176                .header("content-type", "application/json")
177                .json_body(json!({ "dummy": {} }));
178        });
179
180        let endpoint = Request::builder()
181            .id("id")
182            .headers(
183                [(
184                    Some(HeaderName::from_static("foo")),
185                    HeaderValue::from_static("bar"),
186                )]
187                .into_iter(),
188            )
189            .header(
190                HeaderName::from_static("not_foo"),
191                HeaderValue::from_static("not_bar"),
192            )
193            .build()
194            .unwrap();
195        let _: serde_json::Value = endpoint.query(&client).unwrap();
196        mock.assert();
197    }
198}