github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/compilers/rump/rump-xen.go (about)

     1  package rump
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/solo-io/unik/pkg/compilers"
     8  	"github.com/solo-io/unik/pkg/types"
     9  )
    10  
    11  func CreateImageXen(kernel, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) {
    12  	return createImageXen(kernel, args, mntPoints, bakedEnv, noCleanup, false)
    13  }
    14  
    15  func CreateImageXenAddStub(kernel, args string, mntPoints, bakedEnv []string, noCleanup bool) (*types.RawImage, error) {
    16  	return createImageXen(kernel, args, mntPoints, bakedEnv, noCleanup, true)
    17  }
    18  
    19  func createImageXen(kernel, args string, mntPoints, bakedEnv []string, noCleanup, addStub bool) (*types.RawImage, error) {
    20  	// create rump config
    21  	var c rumpConfig
    22  	if bakedEnv != nil {
    23  		c.Env = make(map[string]string)
    24  		for i, pair := range bakedEnv {
    25  			c.Env[fmt.Sprintf("env%d", i)] = pair
    26  		}
    27  	}
    28  
    29  	argv := []string{}
    30  	if args != "" {
    31  		argv = strings.Split(args, " ")
    32  	}
    33  	c = setRumpCmdLine(c, "program.bin", argv, addStub)
    34  
    35  	res := &types.RawImage{}
    36  	volIndex := 0
    37  	// add root -> sda1 mapping
    38  	res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings, types.DeviceMapping{MountPoint: "/", DeviceName: "/dev/sda1"})
    39  
    40  	bootBlk := blk{
    41  		Source:     "etfs",
    42  		Path:       "sda1",
    43  		FSType:     "blk",
    44  		MountPoint: "/bootpart",
    45  	}
    46  	c.Blk = append(c.Blk, bootBlk)
    47  
    48  	for _, mntPoint := range mntPoints {
    49  		// start from sdb; sda is for root.
    50  		volIndex++
    51  		deviceMapped := fmt.Sprintf("sd%c1", 'a'+volIndex)
    52  		blk := blk{
    53  			Source:     "etfs",
    54  			Path:       deviceMapped,
    55  			FSType:     "blk",
    56  			MountPoint: mntPoint,
    57  		}
    58  
    59  		c.Blk = append(c.Blk, blk)
    60  		res.RunSpec.DeviceMappings = append(res.RunSpec.DeviceMappings, types.DeviceMapping{MountPoint: mntPoint, DeviceName: "/dev/" + deviceMapped})
    61  	}
    62  
    63  	// aws network
    64  	c.Net = &net{
    65  		If:     "xenif0",
    66  		Cloner: "true",
    67  		Type:   "inet",
    68  		Method: DHCP,
    69  	}
    70  
    71  	cmdline, err := toRumpJson(c)
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  	imgFile, err := compilers.BuildBootableImage(kernel, cmdline, false, noCleanup)
    76  
    77  	if err != nil {
    78  		return nil, err
    79  	}
    80  
    81  	res.LocalImagePath = imgFile
    82  	res.StageSpec = types.StageSpec{
    83  		ImageFormat:           types.ImageFormat_RAW,
    84  		XenVirtualizationType: types.XenVirtualizationType_Paravirtual,
    85  	}
    86  	res.RunSpec.DefaultInstanceMemory = 1024 // todo: investigate why rump uses so much memory on xen
    87  
    88  	return res, nil
    89  }