@@ -9,16 +9,101 @@ use std::str::FromStr;
9
9
use std:: sync:: Arc ;
10
10
11
11
use anyhow:: Context ;
12
- use serde:: Deserialize ;
12
+ use serde:: { Deserialize , Serialize } ;
13
13
14
+ use cpuid_profile_config:: * ;
14
15
use propolis:: block;
15
16
use propolis:: cpuid;
16
17
use propolis:: hw:: pci:: Bdf ;
17
18
use propolis:: inventory:: ChildRegister ;
18
19
19
20
use crate :: cidata:: build_cidata_be;
20
- pub use propolis_standalone_config:: Config ;
21
- use propolis_standalone_config:: { CpuVendor , CpuidEntry , Device } ;
21
+
22
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
23
+ pub struct Config {
24
+ pub main : Main ,
25
+
26
+ #[ serde( default , rename = "dev" ) ]
27
+ pub devices : BTreeMap < String , Device > ,
28
+
29
+ #[ serde( default , rename = "block_dev" ) ]
30
+ pub block_devs : BTreeMap < String , BlockDevice > ,
31
+
32
+ #[ serde( default , rename = "cpuid" ) ]
33
+ pub cpuid_profiles : BTreeMap < String , CpuidProfile > ,
34
+
35
+ pub cloudinit : Option < CloudInit > ,
36
+ }
37
+ impl Config {
38
+ pub fn cpuid_profile ( & self ) -> Option < & CpuidProfile > {
39
+ match self . main . cpuid_profile . as_ref ( ) {
40
+ Some ( name) => self . cpuid_profiles . get ( name) ,
41
+ None => None ,
42
+ }
43
+ }
44
+ }
45
+
46
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
47
+ pub struct Main {
48
+ pub name : String ,
49
+ pub cpus : u8 ,
50
+ pub bootrom : String ,
51
+ pub memory : usize ,
52
+ pub use_reservoir : Option < bool > ,
53
+ pub cpuid_profile : Option < String > ,
54
+ /// Process exitcode to emit if/when instance halts
55
+ ///
56
+ /// Default: 0
57
+ #[ serde( default ) ]
58
+ pub exit_on_halt : u8 ,
59
+ /// Process exitcode to emit if/when instance reboots
60
+ ///
61
+ /// Default: None, does not exit on reboot
62
+ #[ serde( default ) ]
63
+ pub exit_on_reboot : Option < u8 > ,
64
+ }
65
+
66
+ /// A hard-coded device, either enabled by default or accessible locally
67
+ /// on a machine.
68
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
69
+ pub struct Device {
70
+ pub driver : String ,
71
+
72
+ #[ serde( flatten, default ) ]
73
+ pub options : BTreeMap < String , toml:: Value > ,
74
+ }
75
+
76
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
77
+ pub struct BlockOpts {
78
+ pub block_size : Option < u32 > ,
79
+ pub read_only : Option < bool > ,
80
+ pub skip_flush : Option < bool > ,
81
+ }
82
+
83
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
84
+ pub struct BlockDevice {
85
+ #[ serde( default , rename = "type" ) ]
86
+ pub bdtype : String ,
87
+
88
+ #[ serde( flatten) ]
89
+ pub block_opts : BlockOpts ,
90
+
91
+ #[ serde( flatten, default ) ]
92
+ pub options : BTreeMap < String , toml:: Value > ,
93
+ }
94
+
95
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
96
+ #[ serde( rename_all = "kebab-case" ) ]
97
+ pub struct CloudInit {
98
+ pub user_data : Option < String > ,
99
+ pub meta_data : Option < String > ,
100
+ pub network_config : Option < String > ,
101
+
102
+ // allow path-style contents as well
103
+ pub user_data_path : Option < String > ,
104
+ pub meta_data_path : Option < String > ,
105
+ pub network_config_path : Option < String > ,
106
+ }
22
107
23
108
#[ derive( Deserialize ) ]
24
109
struct FileConfig {
@@ -165,7 +250,7 @@ pub fn parse_cpuid(config: &Config) -> anyhow::Result<Option<cpuid::Set>> {
165
250
166
251
#[ cfg( feature = "crucible" ) ]
167
252
fn create_crucible_backend (
168
- be : & propolis_standalone_config :: BlockDevice ,
253
+ be : & BlockDevice ,
169
254
opts : block:: BackendOpts ,
170
255
log : & slog:: Logger ,
171
256
) -> ( Arc < dyn block:: Backend > , ChildRegister ) {
@@ -259,7 +344,7 @@ fn create_crucible_backend(
259
344
260
345
#[ cfg( feature = "crucible" ) ]
261
346
fn create_crucible_mem_backend (
262
- be : & propolis_standalone_config :: BlockDevice ,
347
+ be : & BlockDevice ,
263
348
opts : block:: BackendOpts ,
264
349
log : & slog:: Logger ,
265
350
) -> ( Arc < dyn block:: Backend > , ChildRegister ) {
@@ -278,7 +363,7 @@ fn create_crucible_mem_backend(
278
363
279
364
#[ cfg( not( feature = "crucible" ) ) ]
280
365
fn create_crucible_backend (
281
- _be : & propolis_standalone_config :: BlockDevice ,
366
+ _be : & BlockDevice ,
282
367
_opts : block:: BackendOpts ,
283
368
_log : & slog:: Logger ,
284
369
) -> ( Arc < dyn block:: Backend > , ChildRegister ) {
@@ -290,7 +375,7 @@ fn create_crucible_backend(
290
375
291
376
#[ cfg( not( feature = "crucible" ) ) ]
292
377
fn create_crucible_mem_backend (
293
- _be : & propolis_standalone_config :: BlockDevice ,
378
+ _be : & BlockDevice ,
294
379
_opts : block:: BackendOpts ,
295
380
_log : & slog:: Logger ,
296
381
) -> ( Arc < dyn block:: Backend > , ChildRegister ) {
0 commit comments