Mercurial > hg > Members > anatofuz > ie-virsh
annotate src/main.rs @ 19:d37203a877d9
add xml parse/writer
author | AnaTofuZ <k198584@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 03 Nov 2020 11:10:24 +0900 |
parents | 9b24d6767a2f |
children | da4858f4658d |
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), |
14 Undefine(UnDefine), | |
15 Define(Define), | |
16 Shutdown(Shutdown), | |
17 Destroy(Destroy), | |
18 Console(Console), | |
19 Start(Start), | |
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), |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
22 DumpXML(DumpXML), |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
23 DefineGDB(DefineGDB), |
19 | 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)] |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
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)] | |
54 struct UnDefine { | |
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)] | |
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)] | |
94 struct DomIfList { | |
95 name: String, | |
96 } | |
97 | |
98 /// domain information | |
99 #[derive(Clap)] | |
100 struct DomInfo { | |
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(); |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
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(); | |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
120 command::start(user_name, arg.name); |
13 | 121 } |
18 | 122 |
10 | 123 SubCommand::Define(name) => {} |
17
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
124 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
125 SubCommand::Shutdown(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
126 user::set_root_id(); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
127 command::shutdown(user_name, arg.name); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
128 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
129 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
130 SubCommand::Console(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
131 user::set_root_id(); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
132 command::console(user_name, arg.name); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
133 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
134 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
135 SubCommand::Destroy(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
136 user::set_root_id(); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
137 command::destroy(user_name, arg.name); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
138 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
139 |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
140 SubCommand::VNCDisplay(arg) => { |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
141 user::set_root_id(); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
142 command::vncdisplay(user_name, arg.name); |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
143 } |
5477c26e6984
impl sub commands that use uid
AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
parents:
13
diff
changeset
|
144 |
18 | 145 SubCommand::Ttyconsole(arg) => { |
146 user::set_root_id(); | |
147 command::ttyconsole(user_name, arg.name); | |
148 } | |
149 | |
150 SubCommand::DumpXML(arg) => { | |
151 user::set_root_id(); | |
152 command::ttyconsole(user_name, arg.name); | |
153 } | |
154 | |
155 SubCommand::Undefine(arg) => { | |
156 user::set_root_id(); | |
157 command::undefine(user_name, arg.name); | |
158 } | |
159 | |
19 | 160 SubCommand::DomIfList(arg) => { |
161 user::set_root_id(); | |
162 command::domiflist(user_name, arg.name); | |
163 } | |
164 | |
165 SubCommand::DomInfo(arg) => { | |
166 user::set_root_id(); | |
167 command::dominfo(user_name, arg.name); | |
168 } | |
169 | |
10 | 170 _ => {} |
5 | 171 } |
19 | 172 } |