summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-01-24 15:47:24 +0200
committerLars Wirzenius <liw@liw.fi>2021-01-24 15:47:24 +0200
commit0d10bc096bb4d791b6528d7ca6d450c83cfd1778 (patch)
tree959f423b430e24b0bb553aa6d8129469f107fbdc
parent1a5a6e5e8e356af082b11b549f3ddfa56f0046db (diff)
downloadvmadm-0d10bc096bb4d791b6528d7ca6d450c83cfd1778.tar.gz
create
-rw-r--r--Cargo.toml3
-rw-r--r--src/bin/tool.rs27
-rw-r--r--src/image.rs1
-rw-r--r--src/install.rs12
4 files changed, 40 insertions, 3 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 9e49642..acda35e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,5 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+anyhow = "1"
+tempfile = "3.2"
thiserror = "1"
-tempfile = "3.2" \ No newline at end of file
diff --git a/src/bin/tool.rs b/src/bin/tool.rs
new file mode 100644
index 0000000..18a5c19
--- /dev/null
+++ b/src/bin/tool.rs
@@ -0,0 +1,27 @@
+use std::path::PathBuf;
+
+use vmadm::cloudinit::CloudInitConfig;
+use vmadm::image::VirtualMachineImage;
+use vmadm::install::{virt_install, VirtInstallArgs};
+
+const BASE_PATH: &'static str = "/home/liw/tmp/debian-10-openstack-amd64.qcow2";
+const IMAGE_PATH: &'static str = "/home/liw/tmp/try-vm.qcow2";
+
+fn main() -> anyhow::Result<()> {
+ let mut init = CloudInitConfig::default();
+ init.set_hostname("toy-vm");
+ init.set_authorized_keys("xxx liw-openpgp xxx");
+ println!("init: {:#?}", init);
+
+ let base = PathBuf::from(BASE_PATH);
+ let image = PathBuf::from(IMAGE_PATH);
+ let image = VirtualMachineImage::new_from_base(&base, &image)?;
+ image.resize(1024 * 1024 * 1024 * 10)?;
+
+ let args = VirtInstallArgs::new("toy-vm", &image, &init);
+ println!("{:#?}", args);
+ virt_install(&args)?;
+ println!("OK");
+
+ Ok(())
+}
diff --git a/src/image.rs b/src/image.rs
index 9d30ca0..da7e559 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -35,7 +35,6 @@ impl VirtualMachineImage {
pub fn resize(&self, new_size: usize) -> Result<(), ImageError> {
let r = Command::new("qemu-img")
.arg("resize")
- .arg("-f")
.arg(self.filename())
.arg(format!("{}", new_size))
.output()?;
diff --git a/src/install.rs b/src/install.rs
index 5476277..89969e0 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -19,6 +19,7 @@ pub enum VirtInstallError {
CloudInitError(#[from] CloudInitError),
}
+#[derive(Debug)]
pub struct VirtInstallArgs {
name: String,
memory: usize,
@@ -83,7 +84,16 @@ pub fn virt_install(args: &VirtInstallArgs) -> Result<(), VirtInstallError> {
"--disk=path={},cache=none",
args.image().filename().display()
))
- .arg(format!("--disk=path={},readconly=on", iso.display()))
+ .arg(format!("--disk=path={},readonly=on", iso.display()))
+ .arg("--connect=qemu::///system")
+ .arg("--connect")
+ .arg("qemu:///system")
+ .arg("--cpu=host-passthrough")
+ .arg("--os-variant=debian9")
+ .arg("--import")
+ .arg("--graphics=spice")
+ .arg("--noautoconsole")
+ .arg("--quiet")
.output()?;
if !r.status.success() {
let stderr = String::from_utf8(r.stderr)?;