@@ -22,7 +22,7 @@ use ostree_ext::container as ostree_container;
22
22
use ostree_ext:: container:: SignatureSource ;
23
23
use ostree_ext:: ostree;
24
24
use ostree_ext:: prelude:: Cast ;
25
- use serde:: Serialize ;
25
+ use serde:: { Deserialize , Serialize } ;
26
26
27
27
use crate :: containerenv:: ContainerExecutionInfo ;
28
28
use crate :: lsm:: lsm_label;
@@ -38,7 +38,8 @@ const RUN_BOOTC: &str = "/run/bootc";
38
38
/// This is an ext4 special directory we need to ignore.
39
39
const LOST_AND_FOUND : & str = "lost+found" ;
40
40
41
- #[ derive( clap:: ValueEnum , Debug , Copy , Clone , PartialEq , Eq ) ]
41
+ #[ derive( clap:: ValueEnum , Debug , Copy , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
42
+ #[ serde( rename_all = "kebab-case" ) ]
42
43
pub ( crate ) enum BlockSetup {
43
44
Direct ,
44
45
Tpm2Luks ,
@@ -50,7 +51,7 @@ impl Default for BlockSetup {
50
51
}
51
52
}
52
53
53
- #[ derive( clap:: ValueEnum , Debug , Copy , Clone , PartialEq , Eq ) ]
54
+ #[ derive( clap:: ValueEnum , Debug , Copy , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
54
55
pub ( crate ) enum Filesystem {
55
56
Xfs ,
56
57
Ext4 ,
@@ -88,12 +89,13 @@ const PREPPN: u32 = 1;
88
89
#[ cfg( target_arch = "ppc64" ) ]
89
90
const RESERVEDPN : u32 = 1 ;
90
91
91
- #[ derive( clap:: Args , Debug , Clone ) ]
92
+ #[ derive( clap:: Args , Debug , Clone , Serialize , Deserialize ) ]
92
93
pub ( crate ) struct InstallTargetOpts {
93
94
// TODO: A size specifier which allocates free space for the root in *addition* to the base container image size
94
95
// pub(crate) root_additional_size: Option<String>
95
96
/// The transport; e.g. oci, oci-archive. Defaults to `registry`.
96
97
#[ clap( long, default_value = "registry" ) ]
98
+ #[ serde( default ) ]
97
99
pub ( crate ) target_transport : String ,
98
100
99
101
/// Specify the image to fetch for subsequent updates
@@ -102,14 +104,15 @@ pub(crate) struct InstallTargetOpts {
102
104
103
105
/// Explicitly opt-out of requiring any form of signature verification.
104
106
#[ clap( long) ]
107
+ #[ serde( default ) ]
105
108
pub ( crate ) target_no_signature_verification : bool ,
106
109
107
110
/// Enable verification via an ostree remote
108
111
#[ clap( long) ]
109
112
pub ( crate ) target_ostree_remote : Option < String > ,
110
113
}
111
114
112
- #[ derive( clap:: Args , Debug , Clone ) ]
115
+ #[ derive( clap:: Args , Debug , Clone , Serialize , Deserialize ) ]
113
116
pub ( crate ) struct InstallConfigOpts {
114
117
/// Path to an Ignition config file
115
118
#[ clap( long, value_parser) ]
@@ -127,6 +130,7 @@ pub(crate) struct InstallConfigOpts {
127
130
/// This is currently necessary to install *from* a system with SELinux disabled
128
131
/// but where the target does have SELinux enabled.
129
132
#[ clap( long) ]
133
+ #[ serde( default ) ]
130
134
pub ( crate ) disable_selinux : bool ,
131
135
132
136
// Only occupy at most this much space (if no units are provided, GB is assumed).
@@ -139,24 +143,28 @@ pub(crate) struct InstallConfigOpts {
139
143
}
140
144
141
145
/// Options for installing to a block device
142
- #[ derive( Debug , Clone , clap:: Args ) ]
146
+ #[ derive( Debug , Clone , clap:: Args , Serialize , Deserialize ) ]
147
+ #[ serde( rename_all = "kebab-case" ) ]
143
148
pub ( crate ) struct InstallBlockDeviceOpts {
144
149
/// Target block device for installation. The entire device will be wiped.
145
150
pub ( crate ) device : Utf8PathBuf ,
146
151
147
152
/// Automatically wipe all existing data on device
148
153
#[ clap( long) ]
154
+ #[ serde( default ) ]
149
155
pub ( crate ) wipe : bool ,
150
156
151
157
/// Target root block device setup.
152
158
///
153
159
/// direct: Filesystem written directly to block device
154
160
/// tpm2-luks: Bind unlock of filesystem to presence of the default tpm2 device.
155
161
#[ clap( long, value_enum, default_value_t) ]
162
+ #[ serde( default ) ]
156
163
pub ( crate ) block_setup : BlockSetup ,
157
164
158
165
/// Target root filesystem type.
159
166
#[ clap( long, value_enum, default_value_t) ]
167
+ #[ serde( default ) ]
160
168
pub ( crate ) filesystem : Filesystem ,
161
169
162
170
/// Size of the root partition (default specifier: M). Allowed specifiers: M (mebibytes), G (gibibytes), T (tebibytes).
@@ -167,15 +175,18 @@ pub(crate) struct InstallBlockDeviceOpts {
167
175
}
168
176
169
177
/// Perform an installation to a block device.
170
- #[ derive( Debug , Clone , clap:: Parser ) ]
178
+ #[ derive( Debug , Clone , clap:: Parser , Serialize , Deserialize ) ]
171
179
pub ( crate ) struct InstallOpts {
172
180
#[ clap( flatten) ]
181
+ #[ serde( flatten) ]
173
182
pub ( crate ) block_opts : InstallBlockDeviceOpts ,
174
183
175
184
#[ clap( flatten) ]
185
+ #[ serde( flatten) ]
176
186
pub ( crate ) target_opts : InstallTargetOpts ,
177
187
178
188
#[ clap( flatten) ]
189
+ #[ serde( flatten) ]
179
190
pub ( crate ) config_opts : InstallConfigOpts ,
180
191
}
181
192
@@ -1163,3 +1174,12 @@ pub(crate) async fn install_to_filesystem(opts: InstallToFilesystemOpts) -> Resu
1163
1174
1164
1175
Ok ( ( ) )
1165
1176
}
1177
+
1178
+ #[ test]
1179
+ fn install_opts_serializable ( ) {
1180
+ let c: InstallOpts = serde_json:: from_value ( serde_json:: json!( {
1181
+ "device" : "/dev/vda"
1182
+ } ) )
1183
+ . unwrap ( ) ;
1184
+ assert_eq ! ( c. block_opts. device, "/dev/vda" ) ;
1185
+ }
0 commit comments