github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/compilers/rump/rump-vmware.go (about) 1 package rump 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/sirupsen/logrus" 8 "github.com/solo-io/unik/pkg/compilers" 9 "github.com/solo-io/unik/pkg/types" 10 ) 11 12 func CreateImageVmware(kernel string, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) { 13 return createImageVmware(kernel, args, mntPoints, bakedEnv, noCleanup, false) 14 } 15 16 func CreateImageVmwareAddStub(kernel string, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) { 17 return createImageVmware(kernel, args, mntPoints, bakedEnv, noCleanup, true) 18 } 19 20 func createImageVmware(kernel string, args string, mntPoints, bakedEnv []string, noCleanup, addStub bool) (*types.RawImage, error) { 21 // create rump config 22 var c rumpConfig 23 if bakedEnv != nil { 24 c.Env = make(map[string]string) 25 for i, pair := range bakedEnv { 26 c.Env[fmt.Sprintf("env%d", i)] = pair 27 } 28 } 29 30 argv := []string{} 31 if args != "" { 32 argv = strings.Split(args, " ") 33 } 34 c = setRumpCmdLine(c, "program.bin", argv, addStub) 35 36 res := &types.RawImage{} 37 // add root -> sd0 mapping 38 res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings, types.DeviceMapping{MountPoint: "/", DeviceName: "sd0"}) 39 40 bootBlk := blk{ 41 Source: "dev", 42 Path: "/dev/sd0e", // no disk label on the boot partition; so partition e is used. 43 FSType: "blk", 44 MountPoint: "/bootpart", 45 } 46 c.Blk = append(c.Blk, bootBlk) 47 48 for i, mntPoint := range mntPoints { 49 deviceMapped := fmt.Sprintf("sd%ca", '1'+i) 50 blk := blk{ 51 Source: "dev", 52 Path: "/dev/" + deviceMapped, 53 FSType: "blk", 54 MountPoint: mntPoint, 55 } 56 57 c.Blk = append(c.Blk, blk) 58 res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings, types.DeviceMapping{MountPoint: mntPoint, DeviceName: deviceMapped}) 59 } 60 61 // aws network 62 c.Net = &net{ 63 If: "wm0", 64 Type: "inet", 65 Method: DHCP, 66 } 67 68 cmdline, err := toRumpJson(c) 69 if err != nil { 70 return nil, err 71 } 72 73 imgFile, err := compilers.BuildBootableImage(kernel, cmdline, true, noCleanup) 74 if err != nil { 75 return nil, err 76 } 77 78 res.LocalImagePath = imgFile 79 res.StageSpec.ImageFormat = types.ImageFormat_RAW 80 res.RunSpec.StorageDriver = types.StorageDriver_SCSI 81 res.RunSpec.VsphereNetworkType = types.VsphereNetworkType_E1000 82 res.RunSpec.DefaultInstanceMemory = 256 83 logrus.WithField("runspec", res.RunSpec).Infof("created raw vmware image") 84 return res, nil 85 }