-
Notifications
You must be signed in to change notification settings - Fork 5
/
options.go
65 lines (60 loc) · 1.7 KB
/
options.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
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
firecracker "github.com/firecracker-microvm/firecracker-go-sdk"
models "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
)
func getFirecrackerConfig(vmmID string) (firecracker.Config, error) {
socket := getSocketPath(vmmID)
return firecracker.Config{
SocketPath: socket,
KernelImagePath: "../../linux/vmlinux",
LogPath: fmt.Sprintf("%s.log", socket),
Drives: []models.Drive{{
DriveID: firecracker.String("1"),
PathOnHost: firecracker.String("/tmp/rootfs-" + vmmID + ".ext4"),
IsRootDevice: firecracker.Bool(true),
IsReadOnly: firecracker.Bool(false),
RateLimiter: firecracker.NewRateLimiter(
// bytes/s
models.TokenBucket{
OneTimeBurst: firecracker.Int64(1024 * 1024), // 1 MiB/s
RefillTime: firecracker.Int64(500), // 0.5s
Size: firecracker.Int64(1024 * 1024),
},
// ops/s
models.TokenBucket{
OneTimeBurst: firecracker.Int64(100), // 100 iops
RefillTime: firecracker.Int64(1000), // 1s
Size: firecracker.Int64(100),
}),
}},
NetworkInterfaces: []firecracker.NetworkInterface{{
// Use CNI to get dynamic IP
CNIConfiguration: &firecracker.CNIConfiguration{
NetworkName: "fcnet",
IfName: "veth0",
},
}},
MachineCfg: models.MachineConfiguration{
VcpuCount: firecracker.Int64(1),
HtEnabled: firecracker.Bool(true),
MemSizeMib: firecracker.Int64(256),
},
}, nil
}
func getSocketPath(vmmID string) string {
filename := strings.Join([]string{
".firecracker.sock",
strconv.Itoa(os.Getpid()),
vmmID,
},
"-",
)
dir := os.TempDir()
return filepath.Join(dir, filename)
}