| 11 | ) |
| 12 | |
| 13 | func waitForVMToBoot(ctx context.Context, ip net.IP) error { |
| 14 | // Query the agent until it provides a valid response |
| 15 | req.SetTimeout(500 * time.Millisecond) |
| 16 | for { |
| 17 | select { |
| 18 | case <-ctx.Done(): |
| 19 | // Timeout |
| 20 | return ctx.Err() |
| 21 | default: |
| 22 | res, err := req.Get("http://" + ip.String() + ":8080/health") |
| 23 | if err != nil { |
| 24 | log.WithError(err).Info("VM not ready yet") |
| 25 | time.Sleep(time.Second) |
| 26 | continue |
| 27 | } |
| 28 | |
| 29 | if res.Response().StatusCode != 200 { |
| 30 | time.Sleep(time.Second) |
| 31 | log.Info("VM not ready yet") |
| 32 | } else { |
| 33 | log.WithField("ip", ip).Info("VM agent ready") |
| 34 | return nil |
| 35 | } |
| 36 | time.Sleep(time.Second) |
| 37 | } |
| 38 | |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func (vm runningFirecracker) shutDown() { |
| 43 | log.WithField("ip", vm.ip).Info("stopping") |