Mercurial > hg > Members > anatofuz > ie-virsh
comparison src/command.rs @ 39:f667f3a4bbee
backing file cmd
author | AnaTofuZ <anatofuz@gmail.com> |
---|---|
date | Sun, 22 Nov 2020 15:47:37 +0900 |
parents | 6f1b90844b7f |
children | d3055f6c6fb7 |
comparison
equal
deleted
inserted
replaced
38:6f1b90844b7f | 39:f667f3a4bbee |
---|---|
23 Ok(()) | 23 Ok(()) |
24 } | 24 } |
25 | 25 |
26 pub fn define(user: &user::User, vm_name: &str) { | 26 pub fn define(user: &user::User, vm_name: &str) { |
27 let vm_name = generate_vm_name(&user.name, &vm_name); | 27 let vm_name = generate_vm_name(&user.name, &vm_name); |
28 let vm_xml = xml::Builder::new(&user.name, &vm_name).finalize(); | 28 let builder = xml::Builder::new(&user.name, &vm_name).finalize(); |
29 if let Ok(xml_path) = vm_xml.generate() { | 29 if let Ok(xml_path) = builder.generate() { |
30 virsh::command_require_vm_name(xml_path, "define") | 30 virsh::command_require_vm_name(&xml_path, "define") |
31 } | |
32 } | |
33 | |
34 pub fn define_from_template(user: &user::User, vm_name: &str, template: &str) { | |
35 let vm_name = generate_vm_name(&user.name, &vm_name); | |
36 let template_path = match virsh::get_template_path(template) { | |
37 Some(path) => path, | |
38 None => { | |
39 println!("not found {}", template); | |
40 return; | |
41 } | |
42 }; | |
43 let builder = xml::Builder::new(&user.name, &vm_name) | |
44 .backing(&template_path) | |
45 .finalize(); | |
46 if let Ok(xml_path) = builder.generate() { | |
47 virsh::command_require_vm_name(&xml_path, "define") | |
31 } | 48 } |
32 } | 49 } |
33 | 50 |
34 pub fn start(user_name: &str, vm_name: &str) { | 51 pub fn start(user_name: &str, vm_name: &str) { |
35 virsh::command_require_vm_name(get_vm_name(user_name, vm_name), "start"); | 52 virsh::command_require_vm_name(&get_vm_name(user_name, vm_name), "start"); |
36 } | 53 } |
37 | 54 |
38 pub fn common(user_name: &str, vm_name: &str, command: &str) { | 55 pub fn common(user_name: &str, vm_name: &str, command: &str) { |
39 exec_cmd_from_name_or_id(user_name, vm_name, command) | 56 exec_cmd_from_name_or_id(user_name, vm_name, command) |
40 } | 57 } |
41 | |
42 | 58 |
43 pub fn dumpvncpasswd(_user_name: &str, _vm_name: &str) {} | 59 pub fn dumpvncpasswd(_user_name: &str, _vm_name: &str) {} |
44 | 60 |
45 fn exec_cmd_from_name_or_id(user_name: &str, name_or_id: &str, command: &str) { | 61 fn exec_cmd_from_name_or_id(user_name: &str, name_or_id: &str, command: &str) { |
46 if name_or_id.parse::<u8>().is_ok() { | 62 if name_or_id.parse::<u8>().is_ok() { |
47 let vm_name_or_none = get_vm_name_from_id(user_name, &name_or_id); | 63 let vm_name_or_none = get_vm_name_from_id(user_name, &name_or_id); |
48 if let Some(vm_name) = vm_name_or_none { | 64 if let Some(vm_name) = vm_name_or_none { |
49 return virsh::command_require_vm_name(vm_name, command); | 65 return virsh::command_require_vm_name(&vm_name, command); |
50 } | 66 } |
51 } | 67 } |
52 virsh::command_require_vm_name(get_vm_name(user_name, name_or_id), command); | 68 virsh::command_require_vm_name(&get_vm_name(user_name, name_or_id), command); |
53 } | 69 } |
54 | 70 |
55 fn get_vm_name_from_id(user_name: &str, arg_id: &str) -> Option<String> { | 71 fn get_vm_name_from_id(user_name: &str, arg_id: &str) -> Option<String> { |
56 let (_, vm_list_strs) = virsh::get_vm_list(user_name); | 72 let (_, vm_list_strs) = virsh::get_vm_list(user_name); |
57 for vm in vm_list_strs { | 73 for vm in vm_list_strs { |