Mercurial > hg > Members > anatofuz > ie-virsh
view src/virsh.rs @ 19:d37203a877d9
add xml parse/writer
author | AnaTofuZ <k198584@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 03 Nov 2020 11:10:24 +0900 |
parents | 1da4937628be |
children | e8ba0f63c227 |
line wrap: on
line source
use std::io::{self, Write}; use std::process::Command; pub struct ListDumpMsg { pub info_msg: String, pub border_line: String, } pub fn get_vm_list(user_name: &'static str) -> (ListDumpMsg, Vec<String>) { let output = Command::new("virsh") .arg("list") .arg("--all") .output() .expect("failed to virsh"); let virsh_list = String::from_utf8_lossy(&output.stdout); let mut virsh_list = virsh_list.split('\n'); let info_msg = virsh_list.next().unwrap(); let border_line = virsh_list.next().unwrap(); let ldump_msg = ListDumpMsg { info_msg: String::from(info_msg), border_line: String::from(border_line), }; ( ldump_msg, virsh_list .filter(|&x| x.contains(user_name)) .map(|x| x.to_string()) .collect(), ) } pub fn command_require_vm_name(vm_name: String, operation: &str) { let output = Command::new("virsh") .arg(operation) .arg(vm_name) .output() .unwrap_or_else(|_| panic!("failed to {}", operation)); io::stdout().write_all(&output.stdout).unwrap(); io::stderr().write_all(&output.stderr).unwrap(); }