diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-03-04 09:16:06 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-03-04 09:33:28 +0200 |
commit | 5c8d79d1fa6a6e6f6174558c2d6484683fa37c77 (patch) | |
tree | 7ea950ecae3a1d13716ed397260f2bb576076925 /src/spec.rs | |
parent | bccad77273048aae6be22bf09264ca6c6fd4225b (diff) | |
download | vmadm-5c8d79d1fa6a6e6f6174558c2d6484683fa37c77.tar.gz |
feat: configurable image_directory where VM images go by default
Also, specification file doesn't need to specify an image file
anymore. Instead the image will be named after the VM and put into the
image directory named in the configuration.
Diffstat (limited to 'src/spec.rs')
-rw-r--r-- | src/spec.rs | 15 |
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, |