@@ -384,3 +384,48 @@ func (s *API) WaitForMACAddress(req *WaitForMACAddressRequest, opts ...scw.Reque
384384func (r * GetServerTypesAvailabilityResponse ) UnsafeSetTotalCount (totalCount int ) {
385385 r .TotalCount = uint32 (totalCount )
386386}
387+
388+ // WaitForServerRDPPasswordRequest is used by WaitForServerRDPPassword method.
389+ type WaitForServerRDPPasswordRequest struct {
390+ ServerID string
391+ Zone scw.Zone
392+ Timeout * time.Duration
393+ RetryInterval * time.Duration
394+ }
395+
396+ // WaitForServerRDPPassword wait for an RDP password to be generated for an instance before returning.
397+ // This function can be used to wait for a windows instance to boot up.
398+ func (s * API ) WaitForServerRDPPassword (req * WaitForServerRDPPasswordRequest , opts ... scw.RequestOption ) (* Server , error ) {
399+ timeout := defaultTimeout
400+ if req .Timeout != nil {
401+ timeout = * req .Timeout
402+ }
403+ retryInterval := defaultRetryInterval
404+ if req .RetryInterval != nil {
405+ retryInterval = * req .RetryInterval
406+ }
407+
408+ server , err := async .WaitSync (& async.WaitSyncConfig {
409+ Get : func () (interface {}, bool , error ) {
410+ res , err := s .GetServer (& GetServerRequest {
411+ ServerID : req .ServerID ,
412+ Zone : req .Zone ,
413+ }, opts ... )
414+ if err != nil {
415+ return nil , false , err
416+ }
417+
418+ if res .Server .AdminPasswordEncryptedValue != nil && * res .Server .AdminPasswordEncryptedValue != "" {
419+ return res .Server , true , err
420+ }
421+
422+ return res .Server , false , err
423+ },
424+ Timeout : timeout ,
425+ IntervalStrategy : async .LinearIntervalStrategy (retryInterval ),
426+ })
427+ if err != nil {
428+ return nil , errors .Wrap (err , "waiting for server failed" )
429+ }
430+ return server .(* Server ), nil
431+ }
0 commit comments