Mercurial > hg > Members > anatofuz > ie-virsh
diff src/main.rs @ 5:ef1358b993e1
mmm.....
author | AnaTofuZ <anatofuz@gmail.com> |
---|---|
date | Tue, 27 Oct 2020 17:14:39 +0900 |
parents | 668a91cd7be8 |
children | 08247e54d78d |
line wrap: on
line diff
--- 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