diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-08-03 09:34:08 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-08-05 10:12:21 +0300 |
commit | 37efe8e3d022d21bd2f6af741c8d5ee49da2fff5 (patch) | |
tree | eb301167c07657836ca5b9fdb6e044da8242e976 /src | |
parent | c15ca42605d760d519721a3e39e1834ac5b1cb15 (diff) | |
download | vmadm-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
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/new.rs | 2 | ||||
-rw-r--r-- | src/config.rs | 7 | ||||
-rw-r--r-- | src/install.rs | 9 |
3 files changed, 10 insertions, 8 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") |