summaryrefslogtreecommitdiff
path: root/src/install.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-07-25 10:45:27 +0300
committerLars Wirzenius <liw@liw.fi>2021-07-25 11:44:44 +0300
commit40f951a3adbbba94942e007434946a2192eb8989 (patch)
tree47653653c827b3899d95a4bf37e8ce5d528c02ff /src/install.rs
parentbe53a50f86c3f9dcbc003d2ced9824829ee81f19 (diff)
downloadvmadm-40f951a3adbbba94942e007434946a2192eb8989.tar.gz
feat: allow use to add a VM on virtual networks
Sponsored-by: author
Diffstat (limited to 'src/install.rs')
-rw-r--r--src/install.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/install.rs b/src/install.rs
index 94c703c..c84f30a 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -40,6 +40,7 @@ pub struct VirtInstallArgs {
vcpus: u64,
image: VirtualMachineImage,
init: CloudInitConfig,
+ networks: Vec<String>,
}
impl VirtInstallArgs {
@@ -51,6 +52,7 @@ impl VirtInstallArgs {
vcpus: 1,
image: image.clone(),
init: init.clone(),
+ networks: vec![],
}
}
@@ -88,12 +90,31 @@ impl VirtInstallArgs {
pub fn init(&self) -> &CloudInitConfig {
&self.init
}
+
+ /// Add another network to add to the VM.
+ pub fn add_network(&mut self, network: &str) {
+ self.networks.push(network.to_string());
+ }
+
+ /// Return list of networks to add to the VM.
+ pub fn networks(&self) -> Vec<String> {
+ self.networks.clone()
+ }
}
/// 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> = if args.networks.is_empty() {
+ vec!["--network=default".to_string()]
+ } else {
+ args.networks
+ .iter()
+ .map(|s| format!("--network={}", s))
+ .collect()
+ };
+
let r = Command::new("virt-install")
.arg("--name")
.arg(args.name())
@@ -115,6 +136,7 @@ pub fn virt_install(args: &VirtInstallArgs, iso: &Path) -> Result<PathBuf, VirtI
.arg("--graphics=spice")
.arg("--noautoconsole")
.arg("--quiet")
+ .args(&networks)
.output()
.map_err(VirtInstallError::Run)?;
if !r.status.success() {