Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
113 changes: 2 additions & 111 deletions agent-types/src/region.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// Copyright 2025 Oxide Computer Company

use std::net::SocketAddr;
use std::path::Path;

use crucible_smf::scf_type_t::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::smf::SmfProperty;

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Serialize, Deserialize, JsonSchema, Debug, PartialEq, Clone)]
#[serde(rename_all = "lowercase")]
Expand All @@ -24,10 +20,12 @@ pub enum State {
fn source_default() -> Option<SocketAddr> {
None
}

// If not provided, select false as the default for read only.
fn read_only_default() -> bool {
false
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Serialize, Deserialize, JsonSchema, Debug, PartialEq, Clone)]
pub struct Region {
Expand Down Expand Up @@ -59,65 +57,6 @@ pub struct Region {
pub read_only: bool,
}

impl Region {
/**
* Given a root directory, return a list of SMF properties to ensure for
* the corresponding running instance.
*/
pub fn get_smf_properties(&self, dir: &Path) -> Vec<SmfProperty<'_>> {
let mut results = vec![
SmfProperty {
name: "directory",
typ: SCF_TYPE_ASTRING,
val: dir.to_str().unwrap().to_string(),
},
SmfProperty {
name: "port",
typ: SCF_TYPE_COUNT,
val: self.port_number.to_string(),
},
];

if self.cert_pem.is_some() {
let mut path = dir.to_path_buf();
path.push("cert.pem");
let path = path.into_os_string().into_string().unwrap();

results.push(SmfProperty {
name: "cert_pem_path",
typ: SCF_TYPE_ASTRING,
val: path,
});
}

if self.key_pem.is_some() {
let mut path = dir.to_path_buf();
path.push("key.pem");
let path = path.into_os_string().into_string().unwrap();

results.push(SmfProperty {
name: "key_pem_path",
typ: SCF_TYPE_ASTRING,
val: path,
});
}

if self.root_pem.is_some() {
let mut path = dir.to_path_buf();
path.push("root.pem");
let path = path.into_os_string().into_string().unwrap();

results.push(SmfProperty {
name: "root_pem_path",
typ: SCF_TYPE_ASTRING,
val: path,
});
}

results
}
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Serialize, Deserialize, JsonSchema, Debug, PartialEq, Clone)]
pub struct CreateRegion {
Expand All @@ -138,54 +77,6 @@ pub struct CreateRegion {
pub source: Option<SocketAddr>,
}

impl CreateRegion {
pub fn mismatch(&self, r: &Region) -> Option<String> {
if self.block_size != r.block_size {
Some(format!(
"block size {} instead of requested {}",
self.block_size, r.block_size
))
} else if self.extent_size != r.extent_size {
Some(format!(
"extent size {} instead of requested {}",
self.extent_size, r.extent_size
))
} else if self.extent_count != r.extent_count {
Some(format!(
"extent count {} instead of requested {}",
self.extent_count, r.extent_count
))
} else if self.encrypted != r.encrypted {
Some(format!(
"encrypted {} instead of requested {}",
self.encrypted, r.encrypted
))
} else if self.cert_pem != r.cert_pem {
Some(format!(
"cert_pem {:?} instead of requested {:?}",
self.cert_pem, r.cert_pem
))
} else if self.key_pem != r.key_pem {
Some(format!(
"key_pem {:?} instead of requested {:?}",
self.key_pem, r.key_pem
))
} else if self.root_pem != r.root_pem {
Some(format!(
"root_pem {:?} instead of requested {:?}",
self.root_pem, r.root_pem
))
} else if self.source != r.source {
Some(format!(
"source {:?} instead of requested {:?}",
self.source, r.source
))
} else {
None
}
}
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Serialize,
Expand Down
81 changes: 1 addition & 80 deletions agent-types/src/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
// Copyright 2025 Oxide Computer Company

use std::path::Path;

use chrono::{DateTime, Utc};
use crucible_smf::scf_type_t::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{
region::{RegionId, State},
smf::SmfProperty,
};
use crate::region::{RegionId, State};

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Serialize, Deserialize, JsonSchema, Debug, PartialEq, Clone)]
Expand All @@ -28,79 +22,6 @@ pub struct RunningSnapshot {
pub state: State,
}

impl RunningSnapshot {
/**
* Given a root directory, return a list of SMF properties to ensure for
* the corresponding running instance.
*/
pub fn get_smf_properties(&self, dir: &Path) -> Vec<SmfProperty<'_>> {
let mut results = vec![
SmfProperty {
name: "directory",
typ: SCF_TYPE_ASTRING,
val: dir.to_str().unwrap().to_string(),
},
SmfProperty {
name: "port",
typ: SCF_TYPE_COUNT,
val: self.port_number.to_string(),
},
SmfProperty {
name: "mode",
typ: SCF_TYPE_ASTRING,
val: "ro".to_string(),
},
];

// Test for X509 files in snapshot - note this means that running
// snapshots will use the X509 information in the snapshot, not a new
// set.
{
let mut path = dir.to_path_buf();
path.push("cert.pem");
let path = path.into_os_string().into_string().unwrap();

if Path::new(&path).exists() {
results.push(SmfProperty {
name: "cert_pem_path",
typ: SCF_TYPE_ASTRING,
val: path,
});
}
}

{
let mut path = dir.to_path_buf();
path.push("key.pem");
let path = path.into_os_string().into_string().unwrap();

if Path::new(&path).exists() {
results.push(SmfProperty {
name: "key_pem_path",
typ: SCF_TYPE_ASTRING,
val: path,
});
}
}

{
let mut path = dir.to_path_buf();
path.push("root.pem");
let path = path.into_os_string().into_string().unwrap();

if Path::new(&path).exists() {
results.push(SmfProperty {
name: "root_pem_path",
typ: SCF_TYPE_ASTRING,
val: path,
});
}
}

results
}
}

pub struct CreateRunningSnapshotRequest {
pub id: RegionId,
pub name: String,
Expand Down
Loading