-
Notifications
You must be signed in to change notification settings - Fork 5
/
vm.go
53 lines (47 loc) · 1.11 KB
/
vm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"net"
"os"
"time"
"github.com/imroc/req"
log "github.com/sirupsen/logrus"
)
func waitForVMToBoot(ctx context.Context, ip net.IP) error {
// Query the agent until it provides a valid response
req.SetTimeout(500 * time.Millisecond)
for {
select {
case <-ctx.Done():
// Timeout
return ctx.Err()
default:
res, err := req.Get("http://" + ip.String() + ":8080/health")
if err != nil {
log.WithError(err).Info("VM not ready yet")
time.Sleep(time.Second)
continue
}
if res.Response().StatusCode != 200 {
time.Sleep(time.Second)
log.Info("VM not ready yet")
} else {
log.WithField("ip", ip).Info("VM agent ready")
return nil
}
time.Sleep(time.Second)
}
}
}
func (vm runningFirecracker) shutDown() {
log.WithField("ip", vm.ip).Info("stopping")
vm.machine.StopVMM()
err := os.Remove(vm.machine.Cfg.SocketPath)
if err != nil {
log.WithError(err).Error("Failed to delete firecracker socket")
}
err = os.Remove("/tmp/rootfs-" + vm.vmmID + ".ext4")
if err != nil {
log.WithError(err).Error("Failed to delete firecracker rootfs")
}
}