Mercurial > hg > Members > anatofuz > ie-virsh
view src/main.rs @ 54:ab3350def09b
...
author | AnaTofuZ <k198584@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Nov 2020 09:42:54 +0900 |
parents | 28adbde55fe7 |
children | d6ef7ea91ff4 |
line wrap: on
line source
use clap::{crate_version, Clap}; use ie_virsh::{command, user}; #[derive(Clap)] #[clap(version = crate_version!(), author = "AnaTofuZ <anatofuz@cr.ie.u-ryukyu.ac.jp>")] struct Opts { #[clap(subcommand)] subcmd: SubCommand, } #[derive(Clap)] enum SubCommand { List(List), Undefine(Undefine), Define(Define), Shutdown(Shutdown), Destroy(Destroy), Console(Console), Start(Start), Ttyconsole(TTyconsole), Vncdisplay(Vncdisplay), Dumpxml(Dumpxml), DefineGDB(DefineGDB), Domiflist(Domiflist), Dominfo(Dominfo), Templates(Templates), } /// show templates vm #[derive(Clap)] struct Templates {} /// define the domain in which the gdb port is opened from the template XML file #[derive(Clap)] struct DefineGDB { name: String, } /// define (but don't start) a domain from an template XML file #[derive(Clap)] struct Define { name: String, /// create a VM with a differential from the template VM registered in $ie-virsh templates #[clap(short, long, parse(from_str))] template: Option<String>, } /// domain information in XML #[derive(Clap)] struct Dumpxml { name: String, } /// vncdisplay #[derive(Clap)] struct Vncdisplay { name: String, } /// undefine a domain #[derive(Clap)] struct Undefine { name: String, } /// start a (previously defined) inactive domain #[derive(Clap)] struct Start { name: String, } /// tty console #[derive(Clap)] struct TTyconsole { name: String, } /// gracefully shutdown a domain #[derive(Clap)] struct Shutdown { name: String, } /// list domains #[derive(Clap)] struct List {} /// destroy (stop) a domain #[derive(Clap)] struct Destroy { name: String, } /// connect to the guest console #[derive(Clap)] struct Console { name: String, } /// list all domain virtual interfaces #[derive(Clap)] struct Domiflist { name: String, } /// domain information #[derive(Clap)] struct Dominfo { name: String, } fn main() { let opts: Opts = Opts::parse(); let uid = user::getuid(); let gid = user::getgid(); let user_name = user::getlogin(uid); println!("uid: {} gid: {} name: {}", uid, gid, user_name); match opts.subcmd { SubCommand::List(_) => { user::set_root_id(); command::list(&user_name); } SubCommand::Start(arg) => { user::set_root_id(); command::start(&user_name, &arg.name); } SubCommand::Define(arg) => { user::set_root_id(); let user = user::User { uid, gid, name: user_name, }; let userdetail = user::UserDetail::new(&user); if let Some(template) = arg.template { command::define_from_template(&userdetail, &arg.name, &template); return; } command::define(&userdetail, &arg.name); } SubCommand::Shutdown(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "shutdown"); } SubCommand::Console(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "console"); } SubCommand::Destroy(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "destroy"); } SubCommand::Vncdisplay(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "vncdisplay"); } SubCommand::Ttyconsole(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "ttyconsole"); } SubCommand::Dumpxml(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "dumpxml"); } SubCommand::Undefine(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "undefine"); } SubCommand::Domiflist(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "domiflist"); } SubCommand::Dominfo(arg) => { user::set_root_id(); command::common(&user_name, &arg.name, "dominfo"); } SubCommand::Templates(_) => { if let Err(e) = command::templates() { println!("{}", e); } } _ => {} } }