annotate src/main.rs @ 13:56e9763abeef

define start cmd
author AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
date Thu, 29 Oct 2020 17:12:09 +0900
parents 0df4d067badb
children 5477c26e6984
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
017344e337e8 use split_whitespace
AnaTofuZ <anatofuz@gmail.com>
parents: 7
diff changeset
1 use clap::Clap;
12
0df4d067badb move each crates
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
2 use ie_virsh::{command, user};
1
dba3414e8f7e get uid, gid, login_user
AnaTofuZ <anatofuz@gmail.com>
parents: 0
diff changeset
3
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
4 #[derive(Clap)]
7
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
5 #[clap(version = "1.0", author = "AnaTofuZ <anatofuz@cr.ie.u-ryukyu.ac.jp>")]
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
6 struct Opts {
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
7 #[clap(subcommand)]
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
8 subcmd: SubCommand,
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
9 }
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
10
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
11 #[derive(Clap)]
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
12 enum SubCommand {
10
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
13 List(List),
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
14 Undefine(UnDefine),
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
15 Define(Define),
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
16 Shutdown(Shutdown),
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
17 Destroy(Destroy),
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
18 Console(Console),
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
19 Start(Start),
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
20 Ttyconsole(TTyConsole),
12
0df4d067badb move each crates
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
21 VNCDisplay(VNCDisplay), //todo define-gdb dumpxml
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
22 }
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
23
7
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
24 /// define (but don't start) a domain from an template XML file
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
25 #[derive(Clap)]
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
26 struct Define {
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
27 name: String,
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
28 }
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
29
11
AnaTofuZ <anatofuz@gmail.com>
parents: 10
diff changeset
30 // vncdisplay
AnaTofuZ <anatofuz@gmail.com>
parents: 10
diff changeset
31 #[derive(Clap)]
AnaTofuZ <anatofuz@gmail.com>
parents: 10
diff changeset
32 struct VNCDisplay {
AnaTofuZ <anatofuz@gmail.com>
parents: 10
diff changeset
33 name_or_id: String,
AnaTofuZ <anatofuz@gmail.com>
parents: 10
diff changeset
34 }
AnaTofuZ <anatofuz@gmail.com>
parents: 10
diff changeset
35
10
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
36 /// undefine a domain
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
37 #[derive(Clap)]
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
38 struct UnDefine {
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
39 name: String,
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
40 }
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
41
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
42 /// start a (previously defined) inactive domain
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
43 #[derive(Clap)]
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
44 struct Start {
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
45 name: String,
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
46 }
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
47
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
48 /// tty console
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
49 #[derive(Clap)]
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
50 struct TTyConsole {
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
51 name_or_id: String,
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
52 }
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
53
7
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
54 /// gracefully shutdown a domain
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
55 #[derive(Clap)]
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
56 struct Shutdown {
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
57 name: String,
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
58 }
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
59
7
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
60 /// list domains
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
61 #[derive(Clap)]
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
62 struct List {}
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
63
10
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
64 /// destroy (stop) a domain
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
65 #[derive(Clap)]
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
66 struct Destroy {
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
67 name: String,
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
68 }
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
69
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
70 /// connect to the guest console
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
71 #[derive(Clap)]
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
72 struct Console {
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
73 name_or_id: String,
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
74 }
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
75
13
56e9763abeef define start cmd
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
76 /*
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
77 struct VM {
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
78 id: u32,
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
79 name: String,
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
80 is_vm_running: bool,
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
81 }
13
56e9763abeef define start cmd
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
82 */
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
83
0
3ef828bc5261 cargo new
AnaTofuZ <anatofuz@gmail.com>
parents:
diff changeset
84 fn main() {
7
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
85 let opts: Opts = Opts::parse();
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
86
12
0df4d067badb move each crates
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
87 let uid = user::getuid();
0df4d067badb move each crates
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
88 let gid = user::getgid();
0df4d067badb move each crates
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
89 let user_name = user::getlogin(uid);
3
5bdb02e05c86 show virsh list --all
AnaTofuZ <anatofuz@gmail.com>
parents: 2
diff changeset
90 println!("uid: {} gid: {} name: {}", uid, gid, user_name);
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
91
7
07b763b84401 rebarse use macro
AnaTofuZ <anatofuz@gmail.com>
parents: 6
diff changeset
92 match opts.subcmd {
10
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
93 SubCommand::List(_) => {
12
0df4d067badb move each crates
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
94 user::set_root_id();
0df4d067badb move each crates
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
95 command::list_command(user_name);
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
96 }
13
56e9763abeef define start cmd
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
97 SubCommand::Start(arg) => {
56e9763abeef define start cmd
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
98 user::set_root_id();
56e9763abeef define start cmd
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
99 command::start_command(user_name, arg.name);
56e9763abeef define start cmd
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
100 }
10
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
101 SubCommand::Define(name) => {}
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
102 SubCommand::Shutdown(name) => {}
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
103 SubCommand::Console(name) => {}
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
104 SubCommand::Destroy(name_or_id) => {}
AnaTofuZ <anatofuz@gmail.com>
parents: 9
diff changeset
105 _ => {}
5
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
106 }
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
107
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
108 //set_root_id();
ef1358b993e1 mmm.....
AnaTofuZ <anatofuz@gmail.com>
parents: 4
diff changeset
109 //list_command(user_name);
0
3ef828bc5261 cargo new
AnaTofuZ <anatofuz@gmail.com>
parents:
diff changeset
110 }
1
dba3414e8f7e get uid, gid, login_user
AnaTofuZ <anatofuz@gmail.com>
parents: 0
diff changeset
111
6
08247e54d78d cargo fmt
AnaTofuZ <anatofuz@gmail.com>
parents: 5
diff changeset
112 fn create_new_vm(user_name: &'static str, vm_name: &'static str, debug_kernel: bool) {}