summaryrefslogtreecommitdiff
path: root/src/spec.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/spec.rs')
-rw-r--r--src/spec.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/spec.rs b/src/spec.rs
index 0a3d097..8325d98 100644
--- a/src/spec.rs
+++ b/src/spec.rs
@@ -23,7 +23,7 @@ struct InputSpecification {
pub ed25519_host_cert: Option<String>,
pub base: Option<PathBuf>,
- pub image: PathBuf,
+ pub image: Option<PathBuf>,
pub image_size_gib: u64,
pub memory_mib: u64,
pub cpus: u64,
@@ -54,6 +54,9 @@ pub enum SpecificationError {
#[error("No base image or default base image specified: {0}")]
NoBaseImage(PathBuf),
+ #[error("No image filename and no image directory specified in configuration")]
+ NoImage,
+
#[error("Failed to read SSH public key file {0}")]
SshKeyRead(PathBuf, #[source] std::io::Error),
@@ -85,6 +88,14 @@ impl Specification {
return Err(SpecificationError::NoBaseImage(filename.to_path_buf()));
};
+ let image = if let Some(image) = input.image {
+ image.to_path_buf()
+ } else if let Some(dirname) = &config.image_directory {
+ dirname.join(format!("{}.qcow2", input.name))
+ } else {
+ return Err(SpecificationError::NoImage.into());
+ };
+
let spec = Specification {
name: input.name.clone(),
ssh_keys: ssh_keys(&input.ssh_key_files)?,
@@ -97,7 +108,7 @@ impl Specification {
ed25519_host_key: input.ed25519_host_key,
ed25519_host_cert: input.ed25519_host_cert,
base,
- image: input.image.clone(),
+ image,
image_size_gib: input.image_size_gib,
memory_mib: input.memory_mib,
cpus: input.cpus,