13
|
1 use std::io::{self, Write};
|
12
|
2 use std::process::Command;
|
|
3
|
|
4 pub struct ListDumpMsg {
|
|
5 pub info_msg: String,
|
|
6 pub border_line: String,
|
|
7 }
|
|
8
|
|
9 pub fn get_vm_list(user_name: &'static str) -> (ListDumpMsg, Vec<String>) {
|
|
10 let output = Command::new("virsh")
|
|
11 .arg("list")
|
|
12 .arg("--all")
|
|
13 .output()
|
|
14 .expect("failed to virsh");
|
|
15 let virsh_list = String::from_utf8_lossy(&output.stdout);
|
15
|
16 let mut virsh_list = virsh_list.split('\n');
|
12
|
17
|
|
18 let info_msg = virsh_list.next().unwrap();
|
|
19 let border_line = virsh_list.next().unwrap();
|
|
20 let ldump_msg = ListDumpMsg {
|
|
21 info_msg: String::from(info_msg),
|
|
22 border_line: String::from(border_line),
|
|
23 };
|
|
24
|
15
|
25 (
|
12
|
26 ldump_msg,
|
|
27 virsh_list
|
|
28 .filter(|&x| x.contains(user_name))
|
|
29 .map(|x| x.to_string())
|
|
30 .collect(),
|
15
|
31 )
|
12
|
32 }
|
13
|
33
|
16
|
34 pub fn command_require_vm_name(vm_name: String, operation: &str) {
|
13
|
35 let output = Command::new("virsh")
|
16
|
36 .arg(operation)
|
13
|
37 .arg(vm_name)
|
|
38 .output()
|
16
|
39 .unwrap_or_else(|_| panic!("failed to {}", operation));
|
13
|
40
|
|
41 io::stdout().write_all(&output.stdout).unwrap();
|
|
42 io::stderr().write_all(&output.stderr).unwrap();
|
|
43 }
|