Mercurial > hg > Members > anatofuz > ie-virsh
changeset 21:9f3d29b8561a
tweak
author | AnaTofuZ <k198584@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 03 Nov 2020 17:36:22 +0900 |
parents | da4858f4658d |
children | 78f246ce5235 |
files | src/command.rs src/xml.rs |
diffstat | 2 files changed, 12 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/command.rs Tue Nov 03 17:21:27 2020 +0900 +++ b/src/command.rs Tue Nov 03 17:36:22 2020 +0900 @@ -12,9 +12,11 @@ pub fn define(user_name: &'static str, vm_name: String) { let vm_name = generate_vm_name(user_name, &vm_name); - let vm_arg = xml::GenerateVMArg::new(user_name, vm_name, false); - vm_arg.generate().ok(); - exec_cmd_from_name_or_id(user_name, &vm_name, "define") + let vm_arg = xml::GenerateVMArg::new(user_name, &vm_name, false); + let result = vm_arg.generate(); + if result.is_ok() { + virsh::command_require_vm_name(&result.unwrap(), "define") + } } pub fn start(user_name: &'static str, vm_name: String) {
--- a/src/xml.rs Tue Nov 03 17:21:27 2020 +0900 +++ b/src/xml.rs Tue Nov 03 17:36:22 2020 +0900 @@ -39,7 +39,7 @@ } impl GenerateVMArg { - pub fn new(user_name: &'static str, vm_name: String, is_debug: bool) -> GenerateVMArg { + pub fn new(user_name: &'static str, vm_name: &str, is_debug: bool) -> GenerateVMArg { let year = user_name.chars().skip(1).take(2).collect::<String>(); let affilication = if year.parse::<u8>().is_ok() { // /etc/libvirt/qemu/e19/e195729 @@ -75,11 +75,11 @@ } } - pub fn generate(self) -> Result<(), Error> { + pub fn generate(self) -> Result<String, Error> { let mut reader = Reader::from_reader(BufReader::new(File::open(TEMPLATE_XML_FILE)?)); - println!("generate xml :{}", self.XMLPATH); - let mut writer = Writer::new(BufWriter::new(File::create(self.XMLPATH).unwrap())); + print!("generate xml :{}\n", self.XMLPATH); + let mut writer = Writer::new(BufWriter::new(File::create(self.XMLPATH.clone()).unwrap())); let mut buf = Vec::new(); loop { match reader.read_event(&mut buf) { @@ -149,11 +149,11 @@ } buf.clear(); } - Ok(()) + print!("generate xml : {}\n", self.XMLPATH); + print!("vnc password : {}\n", self.VNCPassword); + Ok(self.XMLPATH) } - println!("generate xml : {}", self.XMLPATH); - println!("vnc password : {}", self.VNCPassword); } fn generate_pw() -> String {