summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-04 07:34:34 +0000
committerLars Wirzenius <liw@liw.fi>2021-03-04 07:34:34 +0000
commit5141d3a654e3abc8064a6ba252220426701a5f89 (patch)
tree7ea950ecae3a1d13716ed397260f2bb576076925
parentbccad77273048aae6be22bf09264ca6c6fd4225b (diff)
parent5c8d79d1fa6a6e6f6174558c2d6484683fa37c77 (diff)
downloadvmadm-5141d3a654e3abc8064a6ba252220426701a5f89.tar.gz
Merge branch 'image-dir' into 'main'
feat: configurable image_directory where VM images go by default See merge request larswirzenius/vmadm!7
-rw-r--r--src/config.rs1
-rw-r--r--src/spec.rs15
-rw-r--r--subplot/vmadm.py5
-rw-r--r--subplot/vmadm.yaml2
-rw-r--r--vmadm.md8
5 files changed, 24 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs
index 9ba4a7f..dd6c2d7 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
#[derive(Default, Debug, Deserialize)]
pub struct Configuration {
pub default_base_image: Option<PathBuf>,
+ pub image_directory: Option<PathBuf>,
}
#[derive(Debug, thiserror::Error)]
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,
diff --git a/subplot/vmadm.py b/subplot/vmadm.py
index 2daa81c..1ee2914 100644
--- a/subplot/vmadm.py
+++ b/subplot/vmadm.py
@@ -20,6 +20,7 @@ def install_vmadm(ctx):
# directories.
os.mkdir(".ssh")
os.mkdir("expected")
+ os.mkdir("images")
def ensure_base_image(ctx):
@@ -35,11 +36,11 @@ def ensure_base_image(ctx):
shutil.copy(base, "base.qcow2")
-def invoke_cloud_init(ctx, filename=None, dirname=None):
+def invoke_cloud_init(ctx, config=None, filename=None, dirname=None):
runcmd_run = globals()["runcmd_run"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
- runcmd_run(ctx, ["vmadm", "cloud-init", filename, dirname])
+ runcmd_run(ctx, ["vmadm", "cloud-init", "--config", config, filename, dirname])
runcmd_exit_code_is_zero(ctx)
diff --git a/subplot/vmadm.yaml b/subplot/vmadm.yaml
index a8810ae..ec7d424 100644
--- a/subplot/vmadm.yaml
+++ b/subplot/vmadm.yaml
@@ -4,7 +4,7 @@
- given: "a Debian 10 OpenStack cloud image"
function: ensure_base_image
-- when: "I invoke vmadm cloud-init {filename} {dirname}"
+- when: "I invoke vmadm cloud-init --config {config} {filename} {dirname}"
function: invoke_cloud_init
- when: "I invoke vmadm new {filename}"
diff --git a/vmadm.md b/vmadm.md
index 8881a0a..1a056ac 100644
--- a/vmadm.md
+++ b/vmadm.md
@@ -66,10 +66,14 @@ given file init.yaml
given file .ssh/id_rsa.pub from init_ssh_key_pub
given file expected/meta-data from init-metadata
given file expected/user-data from init-userdata
-when I invoke vmadm cloud-init init.yaml actual
+when I invoke vmadm cloud-init --config config.yaml init.yaml actual
then directories actual and expected are identical
~~~
+~~~{#config.yaml .file. yaml}
+image_directory: images
+---
+
~~~{#init.yaml .file .yaml}
name: init-test
ssh_key_files:
@@ -83,7 +87,7 @@ ecdsa_host_cert: ecdsa-certificate
ed25519_host_key: ed25519-private
ed25519_host_cert: ed25519-certificate
base: /home/liw/tmp/debian-10-openstack-amd64.qcow2
-image: init.qcow2
+image: images/init.qcow2
image_size_gib: 5
memory_mib: 2048
cpus: 1