comparison src/command.rs @ 20:da4858f4658d

impl define cmd
author AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
date Tue, 03 Nov 2020 17:21:27 +0900
parents d37203a877d9
children 9f3d29b8561a
comparison
equal deleted inserted replaced
19:d37203a877d9 20:da4858f4658d
9 println!("{}", vm_info); 9 println!("{}", vm_info);
10 } 10 }
11 } 11 }
12 12
13 pub fn define(user_name: &'static str, vm_name: String) { 13 pub fn define(user_name: &'static str, vm_name: String) {
14 xml::generate(); 14 let vm_name = generate_vm_name(user_name, &vm_name);
15 let vm_arg = xml::GenerateVMArg::new(user_name, vm_name, false);
16 vm_arg.generate().ok();
17 exec_cmd_from_name_or_id(user_name, &vm_name, "define")
15 } 18 }
16 19
17 pub fn start(user_name: &'static str, vm_name: String) { 20 pub fn start(user_name: &'static str, vm_name: String) {
18 virsh::command_require_vm_name(get_vm_name(user_name, &vm_name), "start"); 21 virsh::command_require_vm_name(get_vm_name(user_name, &vm_name), "start");
19 } 22 }
86 if vm_name.starts_with(user_name) { 89 if vm_name.starts_with(user_name) {
87 return vm_name; 90 return vm_name;
88 } 91 }
89 format!("{}-{}", user_name, vm_name) 92 format!("{}-{}", user_name, vm_name)
90 } 93 }
94
95
96 fn generate_vm_name(user_name:&'static str, vm_name: &str) -> String {
97 if vm_name.starts_with(user_name) {
98 return vm_name.to_string();
99 }
100 format!("{}-{}", user_name, vm_name)
101 }