forked from solo-io/unik
/
rump-qemu.go
88 lines (73 loc) · 2.02 KB
/
rump-qemu.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package rump
import (
"fmt"
"strings"
"github.com/Sirupsen/logrus"
"github.com/emc-advanced-dev/unik/pkg/compilers"
"github.com/emc-advanced-dev/unik/pkg/types"
unikos "github.com/emc-advanced-dev/unik/pkg/os"
"path/filepath"
"io/ioutil"
)
func CreateImageQemu(kernel string, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) {
// create rump config
var c rumpConfig
if bakedEnv != nil {
c.Env = make(map[string]string)
for i, pair := range bakedEnv {
c.Env[fmt.Sprintf("env%d", i)] = pair
}
}
argv := []string{}
if args != "" {
argv = strings.Split(args, " ")
}
c = setRumpCmdLine(c, "program.bin", argv, false)
bootBlk := blk{
Source: "dev",
Path: "/dev/ld0e",
FSType: "blk",
MountPoint: "/bootpart",
}
c.Blk = append(c.Blk, bootBlk)
res := &types.RawImage{}
for i, mntPoint := range mntPoints {
deviceMapped := fmt.Sprintf("ld%ca", '1'+i)
blk := blk{
Source: "dev",
Path: "/dev/" + deviceMapped,
FSType: "blk",
MountPoint: mntPoint,
}
c.Blk = append(c.Blk, blk)
logrus.Debugf("adding mount point to image: %s:%s", mntPoint, deviceMapped)
res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings,
types.DeviceMapping{MountPoint: mntPoint, DeviceName: deviceMapped})
res.RunSpec.Compiler = compilers.Rump
}
// virtualbox network
c.Net = &net{
If: "vioif0",
Type: "inet",
Method: DHCP,
}
cmdline, err := toRumpJson(c)
if err != nil {
return nil, err
}
logrus.Debugf("writing rump json config: %s", cmdline)
imgFile, err := BuildBootableImage(kernel, cmdline, true, noCleanup)
if err != nil {
return nil, err
}
//copy kernel for qemu
if err := unikos.CopyFile(kernel, filepath.Join(filepath.Dir(imgFile), "program.bin")); err != nil {
return nil, err
}
if err := ioutil.WriteFile(filepath.Join(filepath.Dir(imgFile), "cmdline"), []byte(cmdline), 0644); err != nil {
return nil, err
}
res.LocalImagePath = imgFile
res.StageSpec.ImageFormat = types.ImageFormat_RAW
return res, nil
}