summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-07-25 12:40:27 +0300
committerLars Wirzenius <liw@liw.fi>2021-07-25 13:30:23 +0300
commitbd87e253000b8a0a73c831877c99291fb430607f (patch)
treeaa63fa87ab905c2bf6e874ad3448bc3c3b71deef /src
parent957e9f268a84f39d05a2f7ff35de105b3b695fac (diff)
downloadvmadm-bd87e253000b8a0a73c831877c99291fb430607f.tar.gz
fix: actually add networks to VM
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/cmd/new.rs3
-rw-r--r--src/install.rs13
-rw-r--r--src/spec.rs14
3 files changed, 22 insertions, 8 deletions
diff --git a/src/cmd/new.rs b/src/cmd/new.rs
index 4b6a4a3..3e89c1d 100644
--- a/src/cmd/new.rs
+++ b/src/cmd/new.rs
@@ -63,6 +63,9 @@ pub fn new(specs: &[Specification]) -> Result<(), NewError> {
let mut args = VirtInstallArgs::new(&spec.name, &image, &init);
args.set_memory(spec.memory_mib);
args.set_vcpus(spec.cpus);
+ for network in spec.networks.iter() {
+ args.add_network(network);
+ }
virt_install(&args, &iso)?;
}
diff --git a/src/install.rs b/src/install.rs
index 8028687..ce2cc0b 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -111,14 +111,11 @@ impl VirtInstallArgs {
pub fn virt_install(args: &VirtInstallArgs, iso: &Path) -> Result<PathBuf, VirtInstallError> {
args.init().create_iso(&iso)?;
- let networks: Vec<String> = if args.networks.is_empty() {
- vec!["--network=default".to_string()]
- } else {
- args.networks
- .iter()
- .map(|s| format!("--network={}", s))
- .collect()
- };
+ 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()));
diff --git a/src/spec.rs b/src/spec.rs
index 1470fdb..c3c6b59 100644
--- a/src/spec.rs
+++ b/src/spec.rs
@@ -110,6 +110,16 @@ impl OneVmInputSpecification {
false
}
}
+
+ fn networks(&self, config: &Configuration) -> Vec<String> {
+ if let Some(ref x) = self.networks {
+ x.clone()
+ } else if let Some(ref x) = config.default_networks {
+ x.clone()
+ } else {
+ vec!["default".to_string()]
+ }
+ }
}
fn get<'a, T>(
@@ -188,6 +198,9 @@ pub struct Specification {
/// Path to CA key for creating host certificate.
pub ca_key: Option<PathBuf>,
+
+ /// List of networks to which host should be added.
+ pub networks: Vec<String>,
}
/// Errors from this module.
@@ -302,6 +315,7 @@ impl Specification {
generate_host_certificate: gen_cert,
autostart: input.autostart(config),
ca_key,
+ networks: input.networks(config),
};
debug!("specification as with defaults applied: {:#?}", spec);