Mercurial > hg > Members > anatofuz > ie-virsh
changeset 43:98138c3f00f0
...
author | AnaTofuZ <anatofuz@gmail.com> |
---|---|
date | Sun, 22 Nov 2020 17:50:18 +0900 |
parents | 2787ada7650b |
children | 9d5cb6b2046e |
files | src/command.rs src/virsh.rs |
diffstat | 2 files changed, 11 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/command.rs Sun Nov 22 17:42:50 2020 +0900 +++ b/src/command.rs Sun Nov 22 17:50:18 2020 +0900 @@ -55,8 +55,7 @@ } }; virsh::command_require_vm_name(&xml_path, "define"); - let vm_path = format!("{}{}.qcow2", RENTAL_DIR, &vm_name); - virsh::generate_qemu_from_template(&vm_path, &backing_path); + virsh::generate_qemu_from_template(RENTAL_DIR, &vm_name, &backing_path); } pub fn start(user_name: &str, vm_name: &str) {
--- a/src/virsh.rs Sun Nov 22 17:42:50 2020 +0900 +++ b/src/virsh.rs Sun Nov 22 17:50:18 2020 +0900 @@ -1,6 +1,7 @@ use std::io::{self, Write}; use std::process::Command; +use std::env; use std::fs; use std::path::Path; @@ -68,9 +69,13 @@ io::stderr().write_all(&output.stderr).unwrap(); } -pub fn generate_qemu_from_template(vm_path: &str, template_path: &str) { - //let vm_path = format!("{}{}{}", rental_dir, &vm_name, TEMPLATE_FILE_EXTENSION); - //$qemu-img create -F qcow2 -b ibm-master.qcow2 -f qcow2 ibm-02.qcow2 +pub fn generate_qemu_from_template(vm_path_string: &str, vm_name: &str, template_path: &str) { + let vm_path = Path::new(&vm_path_string); + let ok = env::set_current_dir(&vm_path); + if ok.is_err() { + println!("failed cd at {}", &vm_path_string); + return; + } let output = Command::new("qemu-img") .arg("create") .arg("-F") @@ -79,9 +84,9 @@ .arg(template_path) .arg("-f") .arg(QCOW2) - .arg(vm_path) + .arg(vm_name) .output() - .unwrap_or_else(|_| panic!("failed to generate {}", &vm_path)); + .unwrap_or_else(|_| panic!("failed to generate {}", &vm_name)); io::stdout().write_all(&output.stdout).unwrap(); io::stderr().write_all(&output.stderr).unwrap(); }