Main changes: * Use diesel instead of sled * Split libvirt components into new crate, nzr-virt * Start moving toward network-based cloud-init To facilitate the latter, nzrdhcp is an added unicast-only DHCP server, intended to be used behind a DHCP relay.
66 lines
1.6 KiB
Rust
66 lines
1.6 KiB
Rust
use std::mem::discriminant;
|
|
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum PoolError {
|
|
#[error("libvirt error: {0}")]
|
|
VirtError(virt::error::Error),
|
|
#[error("error reading XML: {0}")]
|
|
XmlError(quick_xml::de::DeError),
|
|
#[error("Error getting source image: {0}")]
|
|
NoPath(virt::error::Error),
|
|
#[error("{0}")]
|
|
FileError(std::io::Error),
|
|
#[error("Unable to start upload: {0}")]
|
|
CantUpload(virt::error::Error),
|
|
#[error("Upload failed: {0}")]
|
|
UploadError(virt::error::Error),
|
|
#[error("{0}")]
|
|
QemuError(ImgError),
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct ImgError {
|
|
pub(crate) message: String,
|
|
pub(crate) command_output: Option<String>,
|
|
}
|
|
|
|
impl std::fmt::Display for ImgError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
if let Some(output) = &self.command_output {
|
|
write!(f, "{}\n output from command: {}", self.message, output)
|
|
} else {
|
|
write!(f, "{}", self.message)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<std::io::Error> for ImgError {
|
|
fn from(value: std::io::Error) -> Self {
|
|
Self {
|
|
message: format!("IO Error: {}", value),
|
|
command_output: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for ImgError {}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum DomainError {
|
|
#[error("libvirt error: {0}")]
|
|
VirtError(VirtError),
|
|
#[error("Error processing XML: {0}")]
|
|
XmlError(quick_xml::de::DeError),
|
|
#[error("Domain not found")]
|
|
DomainNotFound,
|
|
}
|
|
|
|
impl PartialEq for DomainError {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
discriminant(self) == discriminant(other)
|
|
}
|
|
}
|
|
|
|
pub type VirtError = virt::error::Error;
|