@@ -75,3 +75,47 @@ func (s *API) WaitForPossibleDeletion(req *WaitForServerRequest, opts ...scw.Req
7575 time .Sleep (time .Until (timeToDelete ))
7676 return server , nil
7777}
78+
79+ func (s * PrivateNetworkAPI ) WaitForServerPrivateNetworks (req * WaitForServerRequest , opts ... scw.RequestOption ) (* []ServerPrivateNetwork , error ) {
80+ timeout := defaultTimeout
81+ if req .Timeout != nil {
82+ timeout = * req .Timeout
83+ }
84+ retryInterval := defaultRetryInterval
85+ if req .RetryInterval != nil {
86+ retryInterval = * req .RetryInterval
87+ }
88+
89+ terminalStatus := map [ServerPrivateNetworkServerStatus ]struct {}{
90+ ServerPrivateNetworkServerStatusAttached : {},
91+ ServerPrivateNetworkServerStatusError : {},
92+ ServerPrivateNetworkServerStatusUnknownStatus : {},
93+ ServerPrivateNetworkServerStatusLocked : {},
94+ }
95+
96+ serverPrivateNetworks , err := async .WaitSync (& async.WaitSyncConfig {
97+ Get : func () (interface {}, bool , error ) {
98+ res , err := s .ListServerPrivateNetworks (& PrivateNetworkAPIListServerPrivateNetworksRequest {
99+ Zone : req .Zone ,
100+ ServerID : & req .ServerID ,
101+ }, opts ... )
102+ if err != nil {
103+ return nil , false , err
104+ }
105+ for _ , serverPrivateNetwork := range res .ServerPrivateNetworks {
106+ _ , isTerminal := terminalStatus [serverPrivateNetwork .Status ]
107+ if ! isTerminal {
108+ return res .ServerPrivateNetworks , isTerminal , err
109+ }
110+ }
111+ return res .ServerPrivateNetworks , true , err
112+ },
113+ Timeout : timeout ,
114+ IntervalStrategy : async .LinearIntervalStrategy (retryInterval ),
115+ })
116+ if err != nil {
117+ return nil , errors .Wrap (err , "waiting for server private network failed" )
118+ }
119+
120+ return serverPrivateNetworks .(* []ServerPrivateNetwork ), nil
121+ }
0 commit comments