@@ -114,3 +114,56 @@ func (s *API) WaitForGatewayNetwork(req *WaitForGatewayNetworkRequest, opts ...s
114114
115115 return gatewayNetwork .(* GatewayNetwork ), nil
116116}
117+
118+ // WaitForDHCPEntriesRequest is used by WaitForDHCPEntries method
119+ type WaitForDHCPEntriesRequest struct {
120+ GatewayNetworkID * string
121+ MacAddress string
122+
123+ Zone scw.Zone
124+ Timeout * time.Duration
125+ RetryInterval * time.Duration
126+ }
127+
128+ // WaitForDHCPEntries waits for at least one dhcp entry with the correct mac address.
129+ // This function can be used to wait for an instance to use dhcp
130+ func (s * API ) WaitForDHCPEntries (req * WaitForDHCPEntriesRequest , opts ... scw.RequestOption ) (* ListDHCPEntriesResponse , error ) {
131+ timeout := defaultTimeout
132+ if req .Timeout != nil {
133+ timeout = * req .Timeout
134+ }
135+ retryInterval := defaultRetryInterval
136+ if req .RetryInterval != nil {
137+ retryInterval = * req .RetryInterval
138+ }
139+
140+ dhcpEntries , err := async .WaitSync (& async.WaitSyncConfig {
141+ Get : func () (interface {}, bool , error ) {
142+ entries , err := s .ListDHCPEntries (& ListDHCPEntriesRequest {
143+ Zone : req .Zone ,
144+ GatewayNetworkID : req .GatewayNetworkID ,
145+ MacAddress : & req .MacAddress ,
146+ }, opts ... )
147+ if err != nil {
148+ return nil , false , err
149+ }
150+
151+ containsMacAddress := false
152+ for _ , entry := range entries .DHCPEntries {
153+ if entry .MacAddress == req .MacAddress {
154+ containsMacAddress = true
155+ break
156+ }
157+ }
158+
159+ return entries , containsMacAddress , err
160+ },
161+ Timeout : timeout ,
162+ IntervalStrategy : async .LinearIntervalStrategy (retryInterval ),
163+ })
164+ if err != nil {
165+ return nil , errors .Wrap (err , "waiting for gateway network failed" )
166+ }
167+
168+ return dhcpEntries .(* ListDHCPEntriesResponse ), nil
169+ }
0 commit comments