diff src/command.rs @ 32:ae7ba39dfcbe

return the template vec
author AnaTofuZ <anatofuz@gmail.com>
date Sat, 21 Nov 2020 17:14:56 +0900
parents 26111ba2fea1
children ba66504b5256
line wrap: on
line diff
--- 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::<Result<Vec<_>, 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(())