Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Block Storage API #151

Merged
merged 58 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
755076a
feat(cargo): add block_storage feature
gierens Jan 25, 2024
a17e115
feat(lib): register block_storage module with library
gierens Jan 25, 2024
7ac91a9
feat(block_storage): add empty block_storage module
gierens Jan 25, 2024
ef50c19
feat(block_storage): add VolumeStatus and VolumeSortKey to protocol
gierens Jan 25, 2024
a269a43
feat(block_storage): add minimal Volume, and Volume(s)Root to protocol
gierens Jan 25, 2024
c3f0192
feat(block_storage): add get_volume(_by_id/name) to api
gierens Jan 25, 2024
6e678f4
feat(block_storage): add list_volumes to api
gierens Jan 25, 2024
41d5fcf
feat(block_storage): add volumes submodule with Volume
gierens Jan 25, 2024
1d408bb
feat(block_storage): implement Refresh for volumes::Volume
gierens Jan 25, 2024
56740f4
feat(block_storage): add VolumeQuery to volumes
gierens Jan 25, 2024
8ffa8a0
feat(block_storage): implement ResourceQuery for volumes::VolumeQuery
gierens Jan 25, 2024
390e015
feat(block_storage): update mod to publish volumes and protocol stuff
gierens Jan 25, 2024
fd315aa
style(lib): reorder modules alphabetically
gierens Jan 25, 2024
9ffbd2b
feat(cloud): add find_volumes to Cloud implementation
gierens Jan 25, 2024
1bc77cc
feat(cloud): add list_volumes to Cloud implementation
gierens Jan 25, 2024
2818deb
feat(cloud): add get_volume to Cloud implementation
gierens Jan 25, 2024
3ccfbbd
test(tests): add test_list_volumes to integration-list-resources
gierens Jan 25, 2024
8a97bb9
feat(block_storage): implement Display for Volume to show just Volume…
gierens Jan 31, 2024
f7750a8
feat(block_storage): add delete_volume to api
gierens Mar 9, 2024
914d37b
feat(block_storage): add delete to Volume implementation
gierens Mar 9, 2024
3f4fb35
style(block_storage): removed commented out import in protocol
gierens Mar 9, 2024
cd961df
feat(block_storage): add VolumeAttachment and Link structs to protocol
gierens Mar 11, 2024
940326a
feat(block_storage): add all remaining fields to protocol.Volume
gierens Mar 11, 2024
4618270
style(src): fix formatting issues mostly in block_storage module
gierens Mar 11, 2024
8dfa775
fix(cloud): add missing cfg for block_storage feature to list_volumes
gierens Mar 11, 2024
8ba0332
style(block_storage): remove not needed allow(dead_code) in protocol …
gierens Mar 16, 2024
58966b1
fix(block_storage): revise protocol::Volume fields for create_volume
gierens Mar 16, 2024
a1e3b99
feat(block_storage): add VolumeCreate(Root) struct to protocol module
gierens Mar 16, 2024
11d5872
feat(block_storage): add create_volume call to api module
gierens Mar 16, 2024
b44a35d
feat(block_storage): add NewVolume and impl to volumes module
gierens Mar 16, 2024
d672b51
feat(block_storage): expose volumes::NewVolume in mod
gierens Mar 16, 2024
40aa943
feat(cloud): add new_volume to Cloud impl
gierens Mar 16, 2024
ffda1a4
style(src): apply rustfmt
gierens Mar 16, 2024
d3a8e0a
refactor(block_storage): rename field protocol::Volume.multi_attachable
gierens Mar 16, 2024
fcf7eee
feat(block_storage): add transparent_property for all volumes::Volume…
gierens Mar 16, 2024
15da645
test(block_storage): add integration test_volume_create_get_delete_si…
gierens Mar 16, 2024
2a4595a
test(block_storage): add more asserts to test_volume_create_get_delet…
gierens Mar 16, 2024
9b7b123
test(block_storage): add test_volume_create_with_fields
gierens Mar 16, 2024
4bef619
test(block_storage): remove status asserts from integration tests
gierens Mar 16, 2024
c2be624
refactor(block_storage): make VolumeCreate.name a String with default ""
gierens Mar 17, 2024
a70d9ae
test(block_storage): fix test_volume_create_with_fields, name is String
gierens Mar 17, 2024
21b348a
test(block_storage): fix test_volume_create_get_delete_simple, name b…
gierens Mar 17, 2024
61fa269
test(block_storage): remove unused import VolumeStatus
gierens Mar 17, 2024
9aeece2
test(block_storage): fix test_volume_create_get_delete_simple, name i…
gierens Mar 17, 2024
6d34c50
test(block_storage): add sleeps to test_router_create_delete_simple
gierens Mar 17, 2024
c17a9fb
refactor(block_storage): rename Volume.service_uuid to service_id
gierens Mar 18, 2024
6e57ee9
refactor(block_storage): remove unneeded refs in Volume transparent p…
gierens Mar 18, 2024
ca13264
refactor(block_storage): remove unneeded allow for snake case in prot…
gierens Mar 18, 2024
9ca4aa4
feat(block_storage): expose VolumeAttachment
gierens Mar 18, 2024
830cbae
test(block_storage): remove unneeded dereferenciation of volume.size()
gierens Mar 18, 2024
6daf488
refactor(block_storage): make Volume.links/volume_links non-transparent
gierens Mar 18, 2024
a3108a5
fix(block_storage): make VolumeAttachment.host_name an Option<String>
gierens Mar 18, 2024
5932e92
refactor(block_storage): comment out Volume.migstat for now
gierens Mar 18, 2024
e9a3ad8
feat(block_storage): add bool_from_bootable_string to protocol
gierens Mar 22, 2024
f9250da
refactor(block_storage): make protocol::Volume.bootable a boolean field
gierens Mar 22, 2024
0b50523
feat(block_storage): add non_exhaustive to VolumeAttachment
gierens Mar 23, 2024
92b456b
feat(block_storage): add wrapper enum for chrono DateTime and NaiveDa…
gierens Mar 23, 2024
4fe60cf
refactor(block_storage): make Volume.created_at/updated_at a DateTime
gierens Mar 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ edition = "2021"
rust-version = "1.65"

[features]
default = ["compute", "image", "network", "native-tls", "object-storage"]
default = ["block-storage", "compute", "image", "network", "native-tls", "object-storage"]
block-storage = []
compute = []
image = []
network = []
Expand Down
105 changes: 105 additions & 0 deletions src/block_storage/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2024 Sandro-Alessio Gierens <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Foundation bits exposing the Block Storage API.

use std::fmt::Debug;

use osauth::services::BLOCK_STORAGE;
use osauth::ErrorKind;
use serde::Serialize;

use super::super::session::Session;
use super::super::utils;
use super::super::Result;
use super::protocol::*;

/// Delete a volume.
pub async fn delete_volume<S: AsRef<str>>(session: &Session, id: S) -> Result<()> {
trace!("Deleting volume {}", id.as_ref());
let _ = session
.delete(BLOCK_STORAGE, &["volumes", id.as_ref()])
.send()
.await?;
debug!("Successfully requested deletion of volume {}", id.as_ref());
Ok(())
}

/// Get an volume.
pub async fn get_volume<S: AsRef<str>>(session: &Session, id_or_name: S) -> Result<Volume> {
let s = id_or_name.as_ref();
match get_volume_by_id(session, s).await {
Ok(value) => Ok(value),
Err(err) if err.kind() == ErrorKind::ResourceNotFound => {
get_volume_by_name(session, s).await
}
Err(err) => Err(err),
}
}

/// Get an volume by its ID.
pub async fn get_volume_by_id<S: AsRef<str>>(session: &Session, id: S) -> Result<Volume> {
trace!("Fetching volume {}", id.as_ref());
let root: VolumeRoot = session
.get(BLOCK_STORAGE, &["volumes", id.as_ref()])
.fetch()
.await?;
trace!("Received {:?}", root.volume);
Ok(root.volume)
}

/// Get an volume by its name.
pub async fn get_volume_by_name<S: AsRef<str>>(session: &Session, name: S) -> Result<Volume> {
trace!("Get volume by name {}", name.as_ref());
let root: VolumesRoot = session
.get(BLOCK_STORAGE, &["volumes"])
.query(&[("name", name.as_ref())])
.fetch()
.await?;
let result = utils::one(
root.volumes,
"Volume with given name or ID not found",
"Too many volumes found with given name",
)?;
trace!("Received {:?}", result);
Ok(result)
}

/// List volumes.
pub async fn list_volumes<Q: Serialize + Sync + Debug>(
session: &Session,
query: &Q,
) -> Result<Vec<Volume>> {
trace!("Listing volumes with {:?}", query);
let root: VolumesRoot = session
.get(BLOCK_STORAGE, &["volumes", "detail"])
.query(query)
.fetch()
.await?;
trace!("Received volumes: {:?}", root.volumes);
Ok(root.volumes)
}

/// Create a volume.
pub async fn create_volume(session: &Session, request: VolumeCreate) -> Result<Volume> {
debug!("Creating a volume with {:?}", request);
let body = VolumeCreateRoot { volume: request };
let root: VolumeRoot = session
.post(BLOCK_STORAGE, &["volumes"])
.json(&body)
.fetch()
.await?;
trace!("Requested creation of volume {:?}", root.volume);
Ok(root.volume)
}
22 changes: 22 additions & 0 deletions src/block_storage/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 Sandro-Alessio Gierens <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Block Storage API implementation bits.

mod api;
mod protocol;
mod volumes;

pub use self::protocol::{VolumeAttachment, VolumeSortKey, VolumeStatus};
pub use self::volumes::{NewVolume, Volume, VolumeQuery};
Loading
Loading