Mercurial > hg > Members > anatofuz > ie-virsh
annotate src/main.rs @ 24:e8ba0f63c227
remove static variable
author | AnaTofuZ <anatofuz@gmail.com> |
---|---|
date | Tue, 03 Nov 2020 18:37:04 +0900 |
parents | 78f246ce5235 |
children | da27437a94b0 |
rev | line source |
---|---|
8 | 1 use clap::Clap; |
12 | 2 use ie_virsh::{command, user}; |
1 | 3 |
5 | 4 #[derive(Clap)] |
7 | 5 #[clap(version = "1.0", author = "AnaTofuZ <anatofuz@cr.ie.u-ryukyu.ac.jp>")] |
5 | 6 struct Opts { |
7 #[clap(subcommand)] | |
8 subcmd: SubCommand, | |
9 } | |
10 | |
11 #[derive(Clap)] | |
12 enum SubCommand { | |
10 | 13 List(List), |
22 | 14 Undefine(Undefine), |
10 | 15 Define(Define), |
16 Shutdown(Shutdown), | |
17 Destroy(Destroy), | |
18 Console(Console), | |
19 Start(Start), | |
22 | 20 Ttyconsole(TTyconsole), |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
21 VNCDisplay(VNCDisplay), |
22 | 22 Dumpxml(Dumpxml), |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
23 DefineGDB(DefineGDB), |
22 | 24 Domiflist(Domiflist), |
25 Dominfo(Dominfo), | |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
26 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
27 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
28 /// define the domain in which the gdb port is opened from the template XML file |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
29 #[derive(Clap)] |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
30 struct DefineGDB { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
31 name: String, |
5 | 32 } |
33 | |
7 | 34 /// define (but don't start) a domain from an template XML file |
5 | 35 #[derive(Clap)] |
36 struct Define { | |
37 name: String, | |
38 } | |
39 | |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
40 /// domain information in XML |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
41 #[derive(Clap)] |
22 | 42 struct Dumpxml { |
18 | 43 name: String, |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
44 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
45 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
46 /// vncdisplay |
11 | 47 #[derive(Clap)] |
48 struct VNCDisplay { | |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
49 name: String, |
11 | 50 } |
51 | |
10 | 52 /// undefine a domain |
53 #[derive(Clap)] | |
22 | 54 struct Undefine { |
10 | 55 name: String, |
56 } | |
57 | |
58 /// start a (previously defined) inactive domain | |
59 #[derive(Clap)] | |
60 struct Start { | |
61 name: String, | |
62 } | |
63 | |
64 /// tty console | |
65 #[derive(Clap)] | |
22 | 66 struct TTyconsole { |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
67 name: String, |
10 | 68 } |
69 | |
7 | 70 /// gracefully shutdown a domain |
5 | 71 #[derive(Clap)] |
72 struct Shutdown { | |
73 name: String, | |
74 } | |
75 | |
7 | 76 /// list domains |
77 #[derive(Clap)] | |
78 struct List {} | |
79 | |
10 | 80 /// destroy (stop) a domain |
81 #[derive(Clap)] | |
82 struct Destroy { | |
83 name: String, | |
84 } | |
85 | |
86 /// connect to the guest console | |
87 #[derive(Clap)] | |
88 struct Console { | |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
89 name: String, |
10 | 90 } |
91 | |
19 | 92 /// list all domain virtual interfaces |
93 #[derive(Clap)] | |
22 | 94 struct Domiflist { |
19 | 95 name: String, |
96 } | |
97 | |
98 /// domain information | |
99 #[derive(Clap)] | |
22 | 100 struct Dominfo { |
19 | 101 name: String, |
102 } | |
103 | |
0 | 104 fn main() { |
7 | 105 let opts: Opts = Opts::parse(); |
106 | |
12 | 107 let uid = user::getuid(); |
108 let gid = user::getgid(); | |
109 let user_name = user::getlogin(uid); | |
3 | 110 println!("uid: {} gid: {} name: {}", uid, gid, user_name); |
5 | 111 |
7 | 112 match opts.subcmd { |
10 | 113 SubCommand::List(_) => { |
12 | 114 user::set_root_id(); |
24 | 115 command::list(&user_name); |
5 | 116 } |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
117 |
13 | 118 SubCommand::Start(arg) => { |
119 user::set_root_id(); | |
24 | 120 command::start(&user_name, arg.name); |
13 | 121 } |
18 | 122 |
20 | 123 SubCommand::Define(arg) => { |
124 user::set_root_id(); | |
24 | 125 let user = user::User{ |
126 Uid: uid, | |
127 Gid: gid, | |
128 Name: user_name.to_string() | |
129 }; | |
130 command::define(&user, arg.name); | |
20 | 131 } |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
132 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
133 SubCommand::Shutdown(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
134 user::set_root_id(); |
24 | 135 command::shutdown(&user_name, arg.name); |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
136 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
137 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
138 SubCommand::Console(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
139 user::set_root_id(); |
24 | 140 command::console(&user_name, arg.name); |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
141 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
142 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
143 SubCommand::Destroy(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
144 user::set_root_id(); |
24 | 145 command::destroy(&user_name, arg.name); |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
146 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
147 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
148 SubCommand::VNCDisplay(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
149 user::set_root_id(); |
24 | 150 command::vncdisplay(&user_name, arg.name); |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
151 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
152 |
18 | 153 SubCommand::Ttyconsole(arg) => { |
154 user::set_root_id(); | |
24 | 155 command::ttyconsole(&user_name, arg.name); |
18 | 156 } |
157 | |
22 | 158 SubCommand::Dumpxml(arg) => { |
18 | 159 user::set_root_id(); |
24 | 160 command::dumpxml(&user_name, arg.name); |
18 | 161 } |
162 | |
163 SubCommand::Undefine(arg) => { | |
164 user::set_root_id(); | |
24 | 165 command::undefine(&user_name, arg.name); |
18 | 166 } |
167 | |
22 | 168 SubCommand::Domiflist(arg) => { |
19 | 169 user::set_root_id(); |
24 | 170 command::domiflist(&user_name, arg.name); |
19 | 171 } |
172 | |
22 | 173 SubCommand::Dominfo(arg) => { |
19 | 174 user::set_root_id(); |
24 | 175 command::dominfo(&user_name, arg.name); |
19 | 176 } |
177 | |
10 | 178 _ => {} |
5 | 179 } |
19 | 180 } |