Skip to content

Commit f63b7f2

Browse files
committed
add storage URI type, make them transparent
1 parent 4b281bd commit f63b7f2

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ odorobo-manager = { path = "odorobo-manager" }
3434
dotenvy = "0.15"
3535
clap = { version = "4", features = ["derive", "env"] }
3636
ipnet = {version = "2.12.0", features = ["serde", "schemars08"]}
37+
url = { version = "2.3", features = ["serde"] }
3738
# these are for performance optimizations, based on https://nnethercote.github.io/perf-book/build-configuration.html#optimization-level
3839
# these options can take a while to compile (up to 5-10 minutes), so its really only necessary for production binaries.
3940
# also look in .cargo/config.toml for info on microarchitecture optimizations.

odorobo-manager/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ulid = { workspace = true }
3333
libp2p = { version = "0.56.0", features = ["yamux", "serde", "mdns"] }
3434
reqwest = { version = "0.13", features = ["json"] }
3535
ahash = { version = "0.8.12", features = ["serde"] }
36+
url = { workspace = true }
3637
# utoipa = { version = "5.4.0", features = ["uuid"] }
3738
odorobo-shared = { workspace = true }
3839
stable-eyre = { workspace = true }

odorobo-manager/src/api/types.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,31 @@ mod opt_bytesize_as_u64 {
3636

3737
// Newtype so aide can generate a path parameter schema for Ulid.
3838
/// VM ID, in the format of ULID
39+
#[repr(transparent)]
3940
#[derive(Serialize, Deserialize, Debug, JsonSchema, OperationIo, Default, Clone)]
4041
pub struct VmId(#[schemars(with = "String")] pub Ulid);
4142

4243
/// Volume ID, in the format of ULID
44+
#[repr(transparent)]
4345
#[derive(Serialize, Deserialize, Debug, JsonSchema, OperationIo, Default, Clone)]
4446
pub struct VolumeId(#[schemars(with = "String")] pub Ulid);
4547

48+
/// A URI pointing to the volume's location, e.g an iSCSI URL in `iscsi-inq` format, a local file, or an RBD image.
49+
///
50+
/// examples:
51+
/// - `iscsi://[<username>[%<password>]@]<host>[:<port>]/<target-iqn-name>/<lun>`
52+
/// - `file:///path/to/volume.img`
53+
/// - `rbd://<pool>/<image>`
54+
#[repr(transparent)]
55+
#[derive(Serialize, Deserialize, Debug, JsonSchema, OperationIo, Clone)]
56+
pub struct StorageUri(#[schemars(with = "String")] pub url::Url);
57+
58+
impl Default for StorageUri {
59+
fn default() -> Self {
60+
StorageUri(url::Url::parse("file:///tmp").unwrap())
61+
}
62+
}
63+
4664
#[derive(Serialize, Deserialize, Debug, JsonSchema, Default, Clone)]
4765
pub struct CreateVMRequest {
4866
/// Data of the VM to create
@@ -51,6 +69,7 @@ pub struct CreateVMRequest {
5169
pub boot: bool,
5270
}
5371

72+
5473
/// An internal, debug-only request for creating a VM.
5574
///
5675
/// please don't use this in production, this is for debugging
@@ -148,8 +167,16 @@ pub struct Volume {
148167
#[schemars(with = "u64")]
149168
#[serde(with = "bytesize_as_u64")]
150169
pub size: ByteSize,
170+
171+
/// A URI pointing to the volume's location, e.g an iSCSI URL in `iscsi-inq` format, a local file, or an RBD image.
172+
///
173+
/// examples:
174+
/// - `iscsi://[<username>[%<password>]@]<host>[:<port>]/<target-iqn-name>/<lun>`
175+
/// - `file:///path/to/volume.img`
176+
/// - `rbd://<pool>/<image>`
177+
///
178+
pub uri: StorageUri,
151179
}
152-
153180
// for now
154181
pub type CreateVolumeRequest = Volume;
155182

0 commit comments

Comments
 (0)