view src/main.rs @ 28:1c3b6b6ee0b1

add show template
author AnaTofuZ <anatofuz@gmail.com>
date Sat, 21 Nov 2020 16:37:58 +0900
parents afec42bdd5ab
children 91a99ff9c4c5
line wrap: on
line source

use clap::Clap;
use ie_virsh::{command, user};

#[derive(Clap)]
#[clap(version = "1.0", 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,
}

/// 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,
            };
            command::define(&user, arg.name);
        }

        SubCommand::Shutdown(arg) => {
            user::set_root_id();
            command::shutdown(&user_name, arg.name);
        }

        SubCommand::Console(arg) => {
            user::set_root_id();
            command::console(&user_name, arg.name);
        }

        SubCommand::Destroy(arg) => {
            user::set_root_id();
            command::destroy(&user_name, arg.name);
        }

        SubCommand::Vncdisplay(arg) => {
            user::set_root_id();
            command::vncdisplay(&user_name, arg.name);
        }

        SubCommand::Ttyconsole(arg) => {
            user::set_root_id();
            command::ttyconsole(&user_name, arg.name);
        }

        SubCommand::Dumpxml(arg) => {
            user::set_root_id();
            command::dumpxml(&user_name, arg.name);
        }

        SubCommand::Undefine(arg) => {
            user::set_root_id();
            command::undefine(&user_name, arg.name);
        }

        SubCommand::Domiflist(arg) => {
            user::set_root_id();
            command::domiflist(&user_name, arg.name);
        }

        SubCommand::Dominfo(arg) => {
            user::set_root_id();
            command::dominfo(&user_name, arg.name);
        }

        SubCommand::Templates(_) => {
            if let Err(e) = command::templates() {
                println!("{}", e);
            }
        }

        _ => {}
    }
}