forked from solo-io/unik
/
rump-vmware.go
84 lines (70 loc) · 2.29 KB
/
rump-vmware.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
package rump
import (
"fmt"
"strings"
"github.com/Sirupsen/logrus"
"github.com/emc-advanced-dev/unik/pkg/types"
)
func CreateImageVmware(kernel string, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) {
return createImageVmware(kernel, args, mntPoints, bakedEnv, noCleanup, false)
}
func CreateImageVmwareAddStub(kernel string, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) {
return createImageVmware(kernel, args, mntPoints, bakedEnv, noCleanup, true)
}
func createImageVmware(kernel string, args string, mntPoints, bakedEnv []string, noCleanup, addStub 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, addStub)
res := &types.RawImage{}
// add root -> sd0 mapping
res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings, types.DeviceMapping{MountPoint: "/", DeviceName: "sd0"})
bootBlk := blk{
Source: "dev",
Path: "/dev/sd0e", // no disk label on the boot partition; so partition e is used.
FSType: "blk",
MountPoint: "/bootpart",
}
c.Blk = append(c.Blk, bootBlk)
for i, mntPoint := range mntPoints {
deviceMapped := fmt.Sprintf("sd1%c", 'a'+i)
blk := blk{
Source: "dev",
Path: "/dev/" + deviceMapped,
FSType: "blk",
MountPoint: mntPoint,
}
c.Blk = append(c.Blk, blk)
res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings, types.DeviceMapping{MountPoint: mntPoint, DeviceName: deviceMapped})
}
// aws network
c.Net = &net{
If: "wm0",
Type: "inet",
Method: DHCP,
}
cmdline, err := toRumpJson(c)
if err != nil {
return nil, err
}
imgFile, err := BuildBootableImage(kernel, cmdline, true, noCleanup)
if err != nil {
return nil, err
}
res.LocalImagePath = imgFile
res.StageSpec.ImageFormat = types.ImageFormat_RAW
res.RunSpec.StorageDriver = types.StorageDriver_SCSI
res.RunSpec.VsphereNetworkType = types.VsphereNetworkType_E1000
res.RunSpec.DefaultInstanceMemory = 256
logrus.WithField("runspec", res.RunSpec).Infof("created raw vmware image")
return res, nil
}