summaryrefslogtreecommitdiff
path: root/src/install.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-07 17:07:20 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-07 17:07:20 +0200
commit1e8ba95def26de67f8fd618549d6b8f80a14ddd8 (patch)
treedc4916152d7c1f488174a7297863e89bad8daa03 /src/install.rs
parent54f0cba69a023ccf0b781dd76a2b370bf6400585 (diff)
downloadvmadm-1e8ba95def26de67f8fd618549d6b8f80a14ddd8.tar.gz
doc: add doc comments to crate
Diffstat (limited to 'src/install.rs')
-rw-r--r--src/install.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/install.rs b/src/install.rs
index 21b9f3f..7506e0d 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -1,24 +1,38 @@
+//! Create a new VM.
+//!
+//! This module runs the `virt-install` tool to create a new VM, using
+//! an existing image file. It attaches the cloud-init ISO
+//! configuration image to the VM.
+
use crate::cloudinit::{CloudInitConfig, CloudInitError};
use crate::image::VirtualMachineImage;
use std::process::Command;
use std::result::Result;
use tempfile::tempdir;
+/// Errors from this module
#[derive(Debug, thiserror::Error)]
pub enum VirtInstallError {
+ /// Failed to create VM.
#[error("virt-install failed: {0}")]
VirtInstallFailed(String),
+ /// I/O error.
#[error(transparent)]
IoError(#[from] std::io::Error),
+ /// Error parsing a string as UTF8.
#[error(transparent)]
StringError(#[from] std::string::FromUtf8Error),
+ /// Error from cloud-init configuration.
#[error(transparent)]
CloudInitError(#[from] CloudInitError),
}
+/// Arguments to virt-install.
+///
+/// These are the arguments we can adjust, for running virt-install.
#[derive(Debug)]
pub struct VirtInstallArgs {
name: String,
@@ -29,6 +43,7 @@ pub struct VirtInstallArgs {
}
impl VirtInstallArgs {
+ /// Create new set of arguments for virt-install.
pub fn new(name: &str, image: &VirtualMachineImage, init: &CloudInitConfig) -> Self {
Self {
name: name.to_string(),
@@ -39,35 +54,43 @@ impl VirtInstallArgs {
}
}
+ /// Name for new VM.
pub fn name(&self) -> &str {
&self.name
}
+ /// Memory for new VM, in MiB.
pub fn memory(&self) -> u64 {
self.memory
}
+ /// Change memory to give to new VM, in MiB.
pub fn set_memory(&mut self, memory: u64) {
self.memory = memory
}
+ /// Virtual CPUs for new VM.
pub fn vcpus(&self) -> u64 {
self.vcpus
}
+ /// Change virtual CPUs for new VM.
pub fn set_vcpus(&mut self, vcpus: u64) {
self.vcpus = vcpus
}
+ /// Image for new VM.
pub fn image(&self) -> &VirtualMachineImage {
&self.image
}
+ /// cloud-init configuration for new VM.
pub fn init(&self) -> &CloudInitConfig {
&self.init
}
}
+/// Create new VM with virt-install.
pub fn virt_install(args: &VirtInstallArgs) -> Result<(), VirtInstallError> {
let dir = tempdir()?;
let iso = dir.path().join("cloudinit.iso");