summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-08-03 09:34:08 +0300
committerLars Wirzenius <liw@liw.fi>2021-08-05 10:12:21 +0300
commit37efe8e3d022d21bd2f6af741c8d5ee49da2fff5 (patch)
treeeb301167c07657836ca5b9fdb6e044da8242e976
parentc15ca42605d760d519721a3e39e1834ac5b1cb15 (diff)
downloadvmadm-37efe8e3d022d21bd2f6af741c8d5ee49da2fff5.tar.gz
feat: if no networks are specified, use default
Also, drop lan, wan from test config, because we can't assume they're available in the environment the tests are run in. Sponsored-by: author
-rw-r--r--src/cmd/new.rs2
-rw-r--r--src/config.rs7
-rw-r--r--src/install.rs9
-rw-r--r--subplot/vmadm.py3
-rw-r--r--vmadm.md8
5 files changed, 15 insertions, 14 deletions
diff --git a/src/cmd/new.rs b/src/cmd/new.rs
index 3e89c1d..197b3dc 100644
--- a/src/cmd/new.rs
+++ b/src/cmd/new.rs
@@ -45,7 +45,7 @@ pub fn new(specs: &[Specification]) -> Result<(), NewError> {
info!("creating new VM {}", spec.name);
info!("creating cloud-init config");
- let init = CloudInitConfig::from(&spec)?;
+ let init = CloudInitConfig::from(spec)?;
info!(
"creating VM image {} from {}",
diff --git a/src/config.rs b/src/config.rs
index 4786bdb..50b94b0 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -64,6 +64,7 @@ impl Configuration {
.map_err(|err| ConfigurationError::ReadError(filename.to_path_buf(), err))?;
let mut config: Configuration = serde_yaml::from_slice(&config)?;
config.expand_tildes();
+ config.fill_in_missing_networks();
debug!("config: {:#?}", config);
Ok(config)
} else {
@@ -71,6 +72,12 @@ impl Configuration {
}
}
+ fn fill_in_missing_networks(&mut self) {
+ if self.default_networks.is_none() {
+ self.default_networks = Some(vec!["default".to_string()]);
+ }
+ }
+
fn expand_tildes(&mut self) {
expand_optional_pathbuf(&mut self.default_base_image);
expand_optional_pathbuf(&mut self.image_directory);
diff --git a/src/install.rs b/src/install.rs
index ce2cc0b..17b7be8 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -6,7 +6,6 @@
use crate::cloudinit::{CloudInitConfig, CloudInitError};
use crate::image::VirtualMachineImage;
-use log::debug;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::result::Result;
@@ -109,17 +108,13 @@ impl VirtInstallArgs {
/// Create new VM with virt-install.
pub fn virt_install(args: &VirtInstallArgs, iso: &Path) -> Result<PathBuf, VirtInstallError> {
- args.init().create_iso(&iso)?;
-
let networks: Vec<String> = args
.networks
.iter()
.map(|s| format!("--network=network={}", s))
.collect();
- debug!("virt-install networks: {:?}", networks);
- if networks.is_empty() {
- return Err(VirtInstallError::NoNetworks(args.name.clone()));
- }
+
+ args.init().create_iso(iso)?;
let r = Command::new("virt-install")
.arg("--name")
diff --git a/subplot/vmadm.py b/subplot/vmadm.py
index acca754..473a673 100644
--- a/subplot/vmadm.py
+++ b/subplot/vmadm.py
@@ -137,10 +137,13 @@ def _expand_tilde(o):
def _assert_equal_objects(a, b):
+ logging.debug(f"comparing {a!r} and {b!r}")
assert type(a) == type(b)
if isinstance(a, dict):
+ logging.debug("both a and b are dicts")
for key in a:
assert key in b, f"wanted b to have key {key!r}"
+ logging.debug(f"comparing values for key {key!r}")
_assert_equal_objects(a[key], b[key])
for key in b:
assert key in a, f"wanted a to have key {key!r}"
diff --git a/vmadm.md b/vmadm.md
index 4308ac6..a109a44 100644
--- a/vmadm.md
+++ b/vmadm.md
@@ -50,9 +50,6 @@ default_memory_mib: 2048
default_cpus: 1
default_generate_host_certificate: true
default_autostart: true
-default_networks:
-- lan
-- wan
ca_key: ca_key
authorized_keys:
- ~/.ssh/id_rsa.pub
@@ -68,8 +65,7 @@ authorized_keys:
"default_generate_host_certificate": true,
"default_autostart": true,
"default_networks": [
- "lan",
- "wan"
+ "default"
],
"ca_key": "ca_key",
"authorized_keys": [
@@ -89,7 +85,7 @@ foo: {}
"ssh_keys": [
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChZ6mVuGLBpW7SarFU/Tu6TemquNxatbMUZuTk8RqVtbkvTKeWFZ5h5tntWPHgST8ykYFaIrr8eYuKQkKdBxHW7H8kejTNwRu/rDbRYX5wxTn4jw4RVopGTpxMlGrWeu5CkWPoLAhQtIzzUAnrDGp9sqG6P1G4ohI61wZMFQta9R2uNxXnnes+e2r4Y78GxmlQH/o0ouI8fBnsxRK0IoSfFs2LutO6wjyzR59FdC9TT7wufd5kXMRzxsmPGeXzNcaqvHGxBvRucGFclCkqSRwk3GNEpXZQhlCIoTIoRu0IPAp/430tlx9zJMhhwDlZsOOXRrFYpdWVMSTAAKECLSYx liw@exolobe1"
],
- "networks": ["lan", "wan"],
+ "networks": ["default"],
"rsa_host_key": null,
"rsa_host_cert": null,
"dsa_host_key": null,