comparison src/main.rs @ 6:08247e54d78d

cargo fmt
author AnaTofuZ <anatofuz@gmail.com>
date Tue, 27 Oct 2020 17:17:24 +0900 (2020-10-27)
parents ef1358b993e1
children 07b763b84401
comparison
equal deleted inserted replaced
5:ef1358b993e1 6:08247e54d78d
1 use clap::{App, Arg, Clap};
1 use nix; 2 use nix;
2 use clap::{Arg, App, Clap};
3 use std::process::Command; 3 use std::process::Command;
4 4
5 #[derive(Clap)] 5 #[derive(Clap)]
6 struct Opts { 6 struct Opts {
7 #[clap(subcommand)] 7 #[clap(subcommand)]
22 #[derive(Clap)] 22 #[derive(Clap)]
23 struct Shutdown { 23 struct Shutdown {
24 name: String, 24 name: String,
25 } 25 }
26 26
27
28 struct VM { 27 struct VM {
29 id: u32, 28 id: u32,
30 name: String, 29 name: String,
31 is_vm_running: bool, 30 is_vm_running: bool,
32 } 31 }
33
34 32
35 fn main() { 33 fn main() {
36 let uid = getuid(); 34 let uid = getuid();
37 let gid = getgid(); 35 let gid = getgid();
38 let user_name = getlogin(uid); 36 let user_name = getlogin(uid);
39 println!("uid: {} gid: {} name: {}", uid, gid, user_name); 37 println!("uid: {} gid: {} name: {}", uid, gid, user_name);
40 38
41 let matches = App::new("ie-virsh") 39 let matches = App::new("ie-virsh")
42 .version("1.0") 40 .version("1.0")
43 .author("AnatofuZ <anatofuz@cr.ie.u-ryukyu.ac.jp>") 41 .author("AnatofuZ <anatofuz@cr.ie.u-ryukyu.ac.jp>")
44 .about("virsh wrapper for ie members") 42 .about("virsh wrapper for ie members")
45 .get_matches(); 43 .get_matches();
46 44
47 /* 45 /*
48 let opts: Opts = Opts::parse(); 46 let opts: Opts = Opts::parse();
49 47
50 match opts.subcmd { 48 match opts.subcmd {
51 SubCommand::define(name) => { 49 SubCommand::define(name) => {
52 }, 50 },
88 let info_msg = virsh_list.next().unwrap(); 86 let info_msg = virsh_list.next().unwrap();
89 let border_line = virsh_list.next().unwrap(); 87 let border_line = virsh_list.next().unwrap();
90 88
91 let virsh_emit_vm_list = virsh_list.filter(|&x| x.contains(user_name)); 89 let virsh_emit_vm_list = virsh_list.filter(|&x| x.contains(user_name));
92 90
93 let mut vm_list : Vec<VM> = Vec::new(); 91 let mut vm_list: Vec<VM> = Vec::new();
94 92
95 println!("{}\n{}", info_msg, border_line); 93 println!("{}\n{}", info_msg, border_line);
96 for emit_vm in virsh_emit_vm_list { 94 for emit_vm in virsh_emit_vm_list {
97 let mut vm_infos = emit_vm.split(" "); 95 let mut vm_infos = emit_vm.split(" ");
98 let vm_status = vm_infos.next().unwrap(); 96 let vm_status = vm_infos.next().unwrap();
99 let is_vm_running = if vm_status != "-" { true } else { false }; 97 let is_vm_running = if vm_status != "-" { true } else { false };
100 let name = vm_infos.next().unwrap(); 98 let name = vm_infos.next().unwrap();
101 let vm = VM{ id: 0, is_vm_running: is_vm_running, name: String::from(name)}; 99 let vm = VM {
100 id: 0,
101 is_vm_running: is_vm_running,
102 name: String::from(name),
103 };
102 vm_list.push(vm); 104 vm_list.push(vm);
103 } 105 }
104 } 106 }
105
106 107
107 fn set_root_id() { 108 fn set_root_id() {
108 let id = 0; 109 let id = 0;
109 match nix::unistd::seteuid(nix::unistd::Uid::from_raw(id)) { 110 match nix::unistd::seteuid(nix::unistd::Uid::from_raw(id)) {
110 Err(err) => panic!("failed seteuid {}", err), 111 Err(err) => panic!("failed seteuid {}", err),
124 Err(err) => panic!("failed setdid{}", err), 125 Err(err) => panic!("failed setdid{}", err),
125 Ok(_) => {} 126 Ok(_) => {}
126 } 127 }
127 } 128 }
128 129
129 130 fn create_new_vm(user_name: &'static str, vm_name: &'static str, debug_kernel: bool) {}
130 fn create_new_vm(user_name: &'static str, vm_name: &'static str, debug_kernel:bool) {
131
132 }