@@ -397,3 +397,55 @@ func (s *API) WaitForServerRDPPassword(req *WaitForServerRDPPasswordRequest, opt
397397 }
398398 return server .(* Server ), nil
399399}
400+
401+ type WaitForServerFileSystemRequest struct {
402+ ServerID string
403+ Zone scw.Zone
404+ Timeout * time.Duration
405+ RetryInterval * time.Duration
406+ }
407+
408+ func (s * API ) WaitForServerFileSystem (req * WaitForServerFileSystemRequest , opts ... scw.RequestOption ) (* Server , error ) {
409+ timeout := defaultTimeout
410+ if req .Timeout != nil {
411+ timeout = * req .Timeout
412+ }
413+ retryInterval := defaultRetryInterval
414+ if req .RetryInterval != nil {
415+ retryInterval = * req .RetryInterval
416+ }
417+
418+ terminalStatus := map [ServerFilesystemState ]struct {}{
419+ ServerFilesystemStateAvailable : {},
420+ ServerFilesystemStateUnknownState : {},
421+ }
422+
423+ result , err := async .WaitSync (& async.WaitSyncConfig {
424+ Get : func () (interface {}, bool , error ) {
425+ res , err := s .GetServer (& GetServerRequest {
426+ ServerID : req .ServerID ,
427+ Zone : req .Zone ,
428+ }, opts ... )
429+ if err != nil {
430+ return nil , false , err
431+ }
432+
433+ allFilesystemsReady := true
434+ for _ , fs := range res .Server .Filesystems {
435+ if _ , ok := terminalStatus [fs .State ]; ! ok {
436+ allFilesystemsReady = false
437+ break
438+ }
439+ }
440+
441+ return res .Server , allFilesystemsReady , nil
442+ },
443+ Timeout : timeout ,
444+ IntervalStrategy : async .LinearIntervalStrategy (retryInterval ),
445+ })
446+ if err != nil {
447+ return nil , errors .Wrap (err , "waiting for server filesystems failed" )
448+ }
449+
450+ return result .(* Server ), nil
451+ }
0 commit comments