4646
4747STRATIS_FS_SIZE = Size ("1 TiB" )
4848
49+ STRATIS_CALL_TIMEOUT = 120 * 1000 # 120 s (used by stratis-cli by default) in ms
50+
4951
5052safe_name_characters = "0-9a-zA-Z._-"
5153
@@ -60,7 +62,7 @@ def pool_used(dev_sizes, encrypted=False):
6062 if encrypted :
6163 cmd .append ("--encrypted" )
6264
63- rc , out = util .run_program_and_capture_output (cmd )
65+ rc , out = util .run_program_and_capture_output (cmd , stderr_to_stdout = True )
6466 if rc :
6567 raise StratisError ("Failed to predict usage for stratis pool" )
6668
@@ -78,7 +80,8 @@ def filesystem_md_size(fs_size):
7880
7981 rc , out = util .run_program_and_capture_output ([availability .STRATISPREDICTUSAGE_APP .name , "filesystem" ,
8082 "--filesystem-size" ,
81- str (fs_size .get_bytes ())])
83+ str (fs_size .get_bytes ())],
84+ stderr_to_stdout = True )
8285 if rc :
8386 raise StratisError ("Failed to predict usage for stratis filesystem: %s" % out )
8487
@@ -107,7 +110,8 @@ def remove_pool(pool_uuid):
107110 STRATIS_PATH ,
108111 STRATIS_MANAGER_INTF ,
109112 "DestroyPool" ,
110- GLib .Variant ("(o)" , (pool_info .object_path ,)))
113+ GLib .Variant ("(o)" , (pool_info .object_path ,)),
114+ timeout = STRATIS_CALL_TIMEOUT )
111115 except safe_dbus .DBusCallError as e :
112116 raise StratisError ("Failed to remove stratis pool: %s" % str (e ))
113117 else :
@@ -135,7 +139,8 @@ def remove_filesystem(pool_uuid, fs_uuid):
135139 pool_info .object_path ,
136140 STRATIS_POOL_INTF ,
137141 "DestroyFilesystems" ,
138- GLib .Variant ("(ao)" , ([fs_info .object_path ],)))
142+ GLib .Variant ("(ao)" , ([fs_info .object_path ],)),
143+ timeout = STRATIS_CALL_TIMEOUT )
139144 except safe_dbus .DBusCallError as e :
140145 raise StratisError ("Failed to remove stratis filesystem: %s" % str (e ))
141146 else :
@@ -172,7 +177,7 @@ def set_key(key_desc, passphrase, key_file):
172177 os .close (write )
173178
174179
175- def unlock_pool (pool_uuid ):
180+ def unlock_pool (pool_uuid , method ):
176181 if not availability .STRATIS_DBUS .available :
177182 raise StratisError ("Stratis DBus service not available" )
178183
@@ -181,15 +186,15 @@ def unlock_pool(pool_uuid):
181186 STRATIS_PATH ,
182187 STRATIS_MANAGER_INTF ,
183188 "UnlockPool" ,
184- GLib .Variant ("(ss)" , (pool_uuid , "keyring" )))
189+ GLib .Variant ("(ss)" , (pool_uuid , method )))
185190 except safe_dbus .DBusCallError as e :
186191 raise StratisError ("Failed to unlock pool: %s" % str (e ))
187192 else :
188193 if not succ :
189194 raise StratisError ("Failed to unlock pool: %s" % err )
190195
191196
192- def create_pool (name , devices , encrypted , passphrase , key_file ):
197+ def create_pool (name , devices , encrypted , passphrase , key_file , clevis ):
193198 if not availability .STRATIS_DBUS .available :
194199 raise StratisError ("Stratis DBus service not available" )
195200
@@ -202,10 +207,18 @@ def create_pool(name, devices, encrypted, passphrase, key_file):
202207 key_desc = "blivet-%s" % name # XXX what would be a good key description?
203208 set_key (key_desc , passphrase , key_file )
204209 key_opt = GLib .Variant ("(bs)" , (True , key_desc ))
210+ if clevis :
211+ clevis_config = {"url" : clevis .tang_url }
212+ if clevis .tang_thumbprint :
213+ clevis_config ["thp" ] = clevis .tang_thumbprint
214+ else :
215+ clevis_config ["stratis:tang:trust_url" ] = True
216+ clevis_opt = GLib .Variant ("(b(ss))" , (True , (clevis .pin , json .dumps (clevis_config ))))
217+ else :
218+ clevis_opt = GLib .Variant ("(b(ss))" , (False , ("" , "" )))
205219 else :
206220 key_opt = GLib .Variant ("(bs)" , (False , "" ))
207-
208- clevis_opt = GLib .Variant ("(b(ss))" , (False , ("" , "" )))
221+ clevis_opt = GLib .Variant ("(b(ss))" , (False , ("" , "" )))
209222
210223 try :
211224 ((succ , _paths ), rc , err ) = safe_dbus .call_sync (STRATIS_SERVICE ,
@@ -214,7 +227,8 @@ def create_pool(name, devices, encrypted, passphrase, key_file):
214227 "CreatePool" ,
215228 GLib .Variant ("(s(bq)as(bs)(b(ss)))" , (name , raid_opt ,
216229 devices , key_opt ,
217- clevis_opt )))
230+ clevis_opt )),
231+ timeout = STRATIS_CALL_TIMEOUT )
218232 except safe_dbus .DBusCallError as e :
219233 raise StratisError ("Failed to create stratis pool: %s" % str (e ))
220234 else :
@@ -246,7 +260,34 @@ def create_filesystem(name, pool_uuid, fs_size=None):
246260 pool_info .object_path ,
247261 STRATIS_POOL_INTF ,
248262 "CreateFilesystems" ,
249- GLib .Variant ("(a(s(bs)))" , ([GLib .Variant ("(s(bs))" , (name , size_opt ))],)))
263+ GLib .Variant ("(a(s(bs)))" , ([GLib .Variant ("(s(bs))" , (name , size_opt ))],)),
264+ timeout = STRATIS_CALL_TIMEOUT )
265+ except safe_dbus .DBusCallError as e :
266+ raise StratisError ("Failed to create stratis filesystem on '%s': %s" % (pool_info .name , str (e )))
267+ else :
268+ if not succ :
269+ raise StratisError ("Failed to create stratis filesystem on '%s': %s (%d)" % (pool_info .name , err , rc ))
270+
271+ # repopulate the stratis info cache so the new filesystem will be added
272+ stratis_info .drop_cache ()
273+
274+
275+ def add_device (pool_uuid , device ):
276+ if not availability .STRATIS_DBUS .available :
277+ raise StratisError ("Stratis DBus service not available" )
278+
279+ # repopulate the stratis info cache just to be sure all values are still valid
280+ stratis_info .drop_cache ()
281+
282+ pool_info = stratis_info .pools [pool_uuid ]
283+
284+ try :
285+ ((succ , _paths ), rc , err ) = safe_dbus .call_sync (STRATIS_SERVICE ,
286+ pool_info .object_path ,
287+ STRATIS_POOL_INTF ,
288+ "AddDataDevs" ,
289+ GLib .Variant ("(as)" , ([device ],)),
290+ timeout = STRATIS_CALL_TIMEOUT )
250291 except safe_dbus .DBusCallError as e :
251292 raise StratisError ("Failed to create stratis filesystem on '%s': %s" % (pool_info .name , str (e )))
252293 else :
0 commit comments