@@ -122,12 +122,17 @@ def make_reverse_cpu_traits_mapping() -> ty.Dict[str, str]:
122
122
VTPM_DIR = '/var/lib/libvirt/swtpm/'
123
123
124
124
125
+ class EncryptionOptions (ty .TypedDict ):
126
+ secret : str
127
+ format : str
128
+
129
+
125
130
def create_image (
126
131
path : str ,
127
132
disk_format : str ,
128
133
disk_size : ty .Optional [ty .Union [str , int ]],
129
134
backing_file : ty .Optional [str ] = None ,
130
- encryption : ty .Optional [ty . Dict [ str , ty . Any ] ] = None
135
+ encryption : ty .Optional [EncryptionOptions ] = None
131
136
) -> None :
132
137
"""Disk image creation with qemu-img
133
138
:param path: Desired location of the disk image
@@ -140,7 +145,7 @@ def create_image(
140
145
Can be None in the case of a COW image.
141
146
:param backing_file: (Optional) Backing file to use.
142
147
:param encryption: (Optional) Dict detailing various encryption attributes
143
- such as the format and passphrase.
148
+ such as the format and passphrase.
144
149
"""
145
150
cmd = [
146
151
'env' , 'LC_ALL=C' , 'LANG=C' , 'qemu-img' , 'create' , '-f' , disk_format
@@ -170,7 +175,7 @@ def create_image(
170
175
if encryption :
171
176
with tempfile .NamedTemporaryFile (mode = 'tr+' , encoding = 'utf-8' ) as f :
172
177
# Write out the passphrase secret to a temp file
173
- f .write (encryption . get ( 'secret' ) )
178
+ f .write (encryption [ 'secret' ] )
174
179
175
180
# Ensure the secret is written to disk, we can't .close() here as
176
181
# that removes the file when using NamedTemporaryFile
@@ -180,7 +185,7 @@ def create_image(
180
185
encryption_opts = [
181
186
'--object' , f"secret,id=sec,file={ f .name } " ,
182
187
'-o' , 'encrypt.key-secret=sec' ,
183
- '-o' , f"encrypt.format={ encryption . get ( 'format' ) } " ,
188
+ '-o' , f"encrypt.format={ encryption [ 'format' ] } " ,
184
189
]
185
190
# Supported luks options:
186
191
# cipher-alg=<str> - Name of cipher algorithm and key length
0 commit comments