# HG changeset patch # User AnaTofuZ # Date 1605946496 -32400 # Node ID ae7ba39dfcbe597fa2d7181fbb1ca5444200888a # Parent 26111ba2fea14d74abd0ba90f4cc3099153a295c return the template vec diff -r 26111ba2fea1 -r ae7ba39dfcbe src/command.rs --- a/src/command.rs Sat Nov 21 16:59:29 2020 +0900 +++ b/src/command.rs Sat Nov 21 17:14:56 2020 +0900 @@ -2,11 +2,7 @@ use super::virsh; use super::xml; -use std::{fs, io}; - -const TEMPLATE_DIR: &str = "/ie-ryukyu/kvm/images/templates/"; -const TEMPLATE_SUFFIX: &str = "template-"; -const TEMPLATE_FILE_EXTENSION: &str = ".qcow2"; +use std::io; pub fn list(user_name: &str) { let (ldump_msg, vm_list_strs) = virsh::get_vm_list(user_name); @@ -17,24 +13,11 @@ } } -pub fn templates() -> io::Result<()> { - let mut entries = fs::read_dir(TEMPLATE_DIR)? - .map(|res| { - res.map(|e| { - e.path() - .display() - .to_string() - .replace(TEMPLATE_DIR, "") - .replace(TEMPLATE_SUFFIX, "") - .replace(TEMPLATE_FILE_EXTENSION, "") - }) - }) - .collect::, io::Error>>()?; +pub fn templates() -> Result<(), io::Error> { + let templates_list = virsh::get_template_list()?; - entries.sort(); - - for entry in entries { - println!("{}", entry); + for name in templates_list { + println!("{}", name); } Ok(()) diff -r 26111ba2fea1 -r ae7ba39dfcbe src/virsh.rs --- a/src/virsh.rs Sat Nov 21 16:59:29 2020 +0900 +++ b/src/virsh.rs Sat Nov 21 17:14:56 2020 +0900 @@ -1,11 +1,35 @@ use std::io::{self, Write}; use std::process::Command; +use std::fs; + +const TEMPLATE_DIR: &str = "/ie-ryukyu/kvm/images/templates/"; +const TEMPLATE_SUFFIX: &str = "template-"; +const TEMPLATE_FILE_EXTENSION: &str = ".qcow2"; + pub struct ListDumpMsg { pub info_msg: String, pub border_line: String, } +pub fn get_template_list() -> Result, io::Error> { + let mut entries = fs::read_dir(TEMPLATE_DIR)? + .map(|res| { + res.map(|e| { + e.path() + .display() + .to_string() + .replace(TEMPLATE_DIR, "") + .replace(TEMPLATE_SUFFIX, "") + .replace(TEMPLATE_FILE_EXTENSION, "") + }) + }) + .collect::, io::Error>>()?; + + entries.sort(); + Ok(entries) +} + pub fn get_vm_list(user_name: &str) -> (ListDumpMsg, Vec) { let output = Command::new("virsh") .arg("list")