Skip to content

Commit dd7ae0e

Browse files
authored
feat(apple-silicon): add waiter terminal status ServerPrivateNetworkSt… (scaleway#2408)
1 parent 321fffa commit dd7ae0e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

api/applesilicon/v1alpha1/apple_silicon_utils.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,39 @@ func (s *PrivateNetworkAPI) WaitForServerPrivateNetworks(req *WaitForServerReque
119119

120120
return serverPrivateNetworks.([]*ServerPrivateNetwork), nil
121121
}
122+
123+
func (s *API) WaitForServerVPCOptionTerminalState(req *WaitForServerRequest, opts ...scw.RequestOption) error {
124+
timeout := defaultTimeout
125+
if req.Timeout != nil {
126+
timeout = *req.Timeout
127+
}
128+
retryInterval := defaultRetryInterval
129+
if req.RetryInterval != nil {
130+
retryInterval = *req.RetryInterval
131+
}
132+
133+
terminalStatus := map[ServerPrivateNetworkStatus]struct{}{
134+
ServerPrivateNetworkStatusVpcEnabled: {},
135+
ServerPrivateNetworkStatusVpcDisabled: {},
136+
}
137+
_, err := async.WaitSync(&async.WaitSyncConfig{
138+
Get: func() (interface{}, bool, error) {
139+
res, err := s.GetServer(&GetServerRequest{
140+
ServerID: req.ServerID,
141+
Zone: req.Zone,
142+
}, opts...)
143+
if err != nil {
144+
return nil, false, err
145+
}
146+
_, isTerminal := terminalStatus[res.VpcStatus]
147+
148+
return res, isTerminal, nil
149+
},
150+
Timeout: timeout,
151+
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
152+
})
153+
if err != nil {
154+
return errors.Wrap(err, "waiting for vpc option terminal state failed")
155+
}
156+
return nil
157+
}

0 commit comments

Comments
 (0)