MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / BootInstanceAndWait

Method BootInstanceAndWait

src/cmd/linuxkit/scaleway.go:195–272  ·  view source on GitHub ↗

BootInstanceAndWait boots and wait for instance to be booted

(instanceID string)

Source from the content-addressed store, hash-verified

193
194// BootInstanceAndWait boots and wait for instance to be booted
195func (s *ScalewayClient) BootInstanceAndWait(instanceID string) error {
196 serverActionRequest := &instance.ServerActionRequest{
197 ServerID: instanceID,
198 Action: instance.ServerActionPoweron,
199 }
200
201 _, err := s.instanceAPI.ServerAction(serverActionRequest)
202 if err != nil {
203 return err
204 }
205
206 log.Debugf("Waiting for server %s to be started", instanceID)
207
208 // code taken from scaleway-cli, could need some changes
209 promise := make(chan bool)
210 var server *instance.Server
211 var currentState instance.ServerState
212
213 go func() {
214 defer close(promise)
215
216 for {
217 serverResp, err := s.instanceAPI.GetServer(&instance.GetServerRequest{
218 ServerID: instanceID,
219 })
220 server = serverResp.Server
221 if err != nil {
222 promise <- false
223 return
224 }
225
226 if currentState != server.State {
227 currentState = server.State
228 }
229
230 if server.State == instance.ServerStateRunning {
231 break
232 }
233 if server.State == instance.ServerStateStopped {
234 promise <- false
235 return
236 }
237 time.Sleep(1 * time.Second)
238 }
239
240 ip := server.PublicIP.Address.String()
241 dest := fmt.Sprintf("%s:22", ip)
242 for {
243 conn, err := net.Dial("tcp", dest)
244 if err == nil {
245 defer func() {
246 _ = conn.Close()
247 }()
248 break
249 } else {
250 time.Sleep(1 * time.Second)
251 }
252 }

Callers 1

pushScalewayCmdFunction · 0.95

Calls 2

StringMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected