changeset 5:ef1358b993e1

mmm.....
author AnaTofuZ <anatofuz@gmail.com>
date Tue, 27 Oct 2020 17:14:39 +0900
parents 668a91cd7be8
children 08247e54d78d
files Cargo.lock Cargo.toml src/main.rs
diffstat 3 files changed, 304 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Cargo.lock	Fri Oct 23 17:42:57 2020 +0900
+++ b/Cargo.lock	Tue Oct 27 17:14:39 2020 +0900
@@ -1,6 +1,23 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
 [[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "autocfg"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
+
+[[package]]
 name = "bitflags"
 version = "1.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -19,14 +36,87 @@
 checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
 
 [[package]]
+name = "clap"
+version = "3.0.0-beta.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
+dependencies = [
+ "atty",
+ "bitflags",
+ "clap_derive",
+ "indexmap",
+ "lazy_static",
+ "os_str_bytes",
+ "strsim",
+ "termcolor",
+ "textwrap",
+ "unicode-width",
+ "vec_map",
+]
+
+[[package]]
+name = "clap_derive"
+version = "3.0.0-beta.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
+
+[[package]]
+name = "heck"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
+dependencies = [
+ "unicode-segmentation",
+]
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
+dependencies = [
+ "libc",
+]
+
+[[package]]
 name = "ie-virsh"
 version = "0.1.0"
 dependencies = [
+ "clap",
  "libc",
  "nix",
 ]
 
 [[package]]
+name = "indexmap"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"
+dependencies = [
+ "autocfg",
+ "hashbrown",
+]
+
+[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
 name = "libc"
 version = "0.2.79"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -43,3 +133,147 @@
  "cfg-if",
  "libc",
 ]
+
+[[package]]
+name = "os_str_bytes"
+version = "2.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ac6fe3538f701e339953a3ebbe4f39941aababa8a3f6964635b24ab526daeac"
+
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
+dependencies = [
+ "unicode-xid",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+[[package]]
+name = "syn"
+version = "1.0.48"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
+]
+
+[[package]]
+name = "termcolor"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
+dependencies = [
+ "unicode-width",
+]
+
+[[package]]
+name = "unicode-segmentation"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
+
+[[package]]
+name = "unicode-width"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
+
+[[package]]
+name = "unicode-xid"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
+
+[[package]]
+name = "vec_map"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
+name = "version_check"
+version = "0.9.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
--- a/Cargo.toml	Fri Oct 23 17:42:57 2020 +0900
+++ b/Cargo.toml	Tue Oct 27 17:14:39 2020 +0900
@@ -9,6 +9,7 @@
 [dependencies]
 nix = "0.19.0"
 libc = "0.2.77"
+clap = "3.0.0-beta.2"
 
 [profile.release]
 codegen-units = 1
--- a/src/main.rs	Fri Oct 23 17:42:57 2020 +0900
+++ b/src/main.rs	Tue Oct 27 17:14:39 2020 +0900
@@ -1,13 +1,63 @@
 use nix;
+use clap::{Arg, App, Clap};
 use std::process::Command;
 
+#[derive(Clap)]
+struct Opts {
+    #[clap(subcommand)]
+    subcmd: SubCommand,
+}
+
+#[derive(Clap)]
+enum SubCommand {
+    define(Define),
+    shutdown(Shutdown),
+}
+
+#[derive(Clap)]
+struct Define {
+    name: String,
+}
+
+#[derive(Clap)]
+struct Shutdown {
+    name: String,
+}
+
+
+struct VM {
+    id: u32,
+    name: String,
+    is_vm_running: bool,
+}
+
+
 fn main() {
     let uid = getuid();
     let gid = getgid();
     let user_name = getlogin(uid);
     println!("uid: {} gid: {} name: {}", uid, gid, user_name);
-    set_root_id();
-    list_command(user_name);
+
+    let matches = App::new("ie-virsh")
+            .version("1.0")
+            .author("AnatofuZ <anatofuz@cr.ie.u-ryukyu.ac.jp>")
+            .about("virsh wrapper for ie members")
+            .get_matches();
+
+            /*
+    let opts: Opts = Opts::parse();
+
+    match opts.subcmd {
+        SubCommand::define(name) => {
+        },
+        SubCommand::shutdown(name) => {
+
+        }
+    }
+    */
+
+    //set_root_id();
+    //list_command(user_name);
 }
 
 fn getlogin(uid: u32) -> &'static str {
@@ -27,7 +77,7 @@
     return gid_struct.into();
 }
 
-fn list_command(user_id: &'static str) {
+fn list_command(user_name: &'static str) {
     let output = Command::new("virsh")
         .arg("list")
         .arg("--all")
@@ -38,14 +88,22 @@
     let info_msg = virsh_list.next().unwrap();
     let border_line = virsh_list.next().unwrap();
 
-    let vm_list = virsh_list.filter(|&x| x.contains(user_id));
+    let virsh_emit_vm_list = virsh_list.filter(|&x| x.contains(user_name));
+
+    let mut vm_list : Vec<VM> = Vec::new();
 
     println!("{}\n{}", info_msg, border_line);
-    for vm in vm_list {
-        println!("{}", vm);
+    for emit_vm in virsh_emit_vm_list {
+        let mut vm_infos = emit_vm.split(" ");
+        let vm_status = vm_infos.next().unwrap();
+        let is_vm_running = if vm_status != "-" { true } else { false };
+        let name = vm_infos.next().unwrap();
+        let  vm = VM{ id: 0, is_vm_running: is_vm_running, name: String::from(name)};
+        vm_list.push(vm);
     }
 }
 
+
 fn set_root_id() {
     let id = 0;
     match nix::unistd::seteuid(nix::unistd::Uid::from_raw(id)) {
@@ -67,3 +125,8 @@
         Ok(_) => {}
     }
 }
+
+
+fn create_new_vm(user_name: &'static str, vm_name: &'static str, debug_kernel:bool) {
+
+}
\ No newline at end of file