Skip to content

Commit

Permalink
Merge pull request #33 from giggsoff/master
Browse files Browse the repository at this point in the history
Fix args
  • Loading branch information
giggsoff authored Feb 25, 2020
2 parents 8274270 + 99977fe commit 02071ce
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/rkt_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func init() {
rktCreateCmd.Flags().StringVar(&rktctx.uuidFile, "uuid-file-save", "", "File to save uuid")
rktCreateCmd.Flags().StringVar(&rktctx.xenCfgFilename, "xen-cfg-filename", "", "File with xen cfg for stage1")
rktCreateCmd.Flags().StringVar(&rktctx.stage1Path, "stage1-path", "/usr/sbin/stage1-xen.aci", "Stage1 path")

rktCreateCmd.Flags().Var(&rktctx.flagExplicitEnv, "set-env", "environment variable to set for all the apps in the form key=value")
//Workaround to start in Ubuntu
rktCreateCmd.Flags().BoolVar(&rktctx.noOverlay, "no-overlay", false, "Run without overlay")

Expand Down
55 changes: 55 additions & 0 deletions cmd/rkt_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,49 @@ package cmd

import (
"errors"
"fmt"
"strings"
)

type kvMap struct {
mapping map[string]string
}

func (e *kvMap) Set(s string) error {
if e.mapping == nil {
e.mapping = make(map[string]string)
}
pair := strings.SplitN(s, "=", 2)
if len(pair) != 2 {
return fmt.Errorf("must be specified as key=value")
}
if _, exists := e.mapping[pair[0]]; exists {
return fmt.Errorf("key %q already set", pair[0])
}
e.mapping[pair[0]] = pair[1]
return nil
}

func (e *kvMap) IsEmpty() bool {
return len(e.mapping) == 0
}

func (e *kvMap) String() string {
return strings.Join(e.Strings(), "\n")
}

func (e *kvMap) Strings() []string {
var env []string
for n, v := range e.mapping {
env = append(env, n+"="+v)
}
return env
}

func (e *kvMap) Type() string {
return "kvMap"
}

type RKTContext struct {
dir string
insecureOptions string
Expand All @@ -14,6 +55,8 @@ type RKTContext struct {
imageUrl string
uuidFile string
xenCfgFilename string
stage2MP string
flagExplicitEnv kvMap
runPaused bool
stage1Path string
noOverlay bool
Expand Down Expand Up @@ -89,6 +132,9 @@ func (ctx RKTContext) rktCreateToCmd() (err error, args []string, envs string) {
if ctx.stage1Path != "" {
args = append(args, "--stage1-path="+ctx.stage1Path)
}
if ctx.uuidFile != "" {
args = append(args, "--uuid-file-save="+ctx.uuidFile)
}
if ctx.noOverlay {
args = append(args, "--no-overlay")
}
Expand All @@ -98,6 +144,15 @@ func (ctx RKTContext) rktCreateToCmd() (err error, args []string, envs string) {
if ctx.xenCfgFilename != "" {
envs += " STAGE1_SEED_XL_CFG=" + ctx.xenCfgFilename
}
if ctx.stage2MP != "" {
envs += " STAGE2_MNT_PTS=" + ctx.stage2MP
}
explicitEnv := ctx.flagExplicitEnv.Strings()
if len(explicitEnv) > 0 {
for _, el := range explicitEnv {
args = append(args, "--set-env="+el)
}
}
err = nil
return
}
Expand Down
63 changes: 56 additions & 7 deletions tests/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,13 @@
"systemAdapterList": [
{
"uplink": true,
"freeUplink": true,
"name": "eth0",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d58",
"lowerLayerName": "eth0"
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d58"
},
{
"uplink": true,
"freeUplink": true,
"name": "eth1",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d59",
"lowerLayerName": "eth1"
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d59"
}
],
"networkInstances": [
Expand Down Expand Up @@ -122,5 +118,58 @@
"ipType": 1,
"instType": 2
}
]
],
"lispInfo": {
"LispMapServers": [
{
"NameOrIp": "zedcontrol.zededa.net",
"Credential": "zededa-lispers.net"
}
],
"LispInstance": 1000,
"EID": "fd5b:8f21:c6b2:2c14:1d41:bd5f:bf40:d6c4",
"EIDHashLen": 120,
"ZedServers": [
{
"HostName": "zedcontrol",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedlake",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedbobo",
"EID": [
"fdd5:79bf:7261:d9df:aea1:c8d2:842d:b99b"
]
},
{
"HostName": "hikey02",
"EID": [
"fdfd:ceef:cf85:7e40:6d4f:2181:ba06:e668"
]
},
{
"HostName": "hikey04",
"EID": [
"fd12:df08:d686:602d:2145:f7cf:2382:1683"
]
},
{
"HostName": "hikey05",
"EID": [
"fd81:abc5:7d7e:bcd7:40d9:df2c:be4b:600"
]
}
],
"EidAllocationPrefix": "/Q==",
"EidAllocationPrefixLen": 8
},
"manufacturer": "ZedVirtualDevice",
"productName": "ZedVirtual-4G"
}
57 changes: 54 additions & 3 deletions tests/cfg_run_rkt.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,12 @@
"systemAdapterList": [
{
"uplink": true,
"freeUplink": true,
"name": "eth0",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d58",
"lowerLayerName": "eth0"
},
{
"uplink": true,
"freeUplink": true,
"name": "eth1",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d59",
"lowerLayerName": "eth1"
Expand Down Expand Up @@ -196,5 +194,58 @@
"ipType": 1,
"instType": 2
}
]
],
"lispInfo": {
"LispMapServers": [
{
"NameOrIp": "zedcontrol.zededa.net",
"Credential": "zededa-lispers.net"
}
],
"LispInstance": 1000,
"EID": "fd5b:8f21:c6b2:2c14:1d41:bd5f:bf40:d6c4",
"EIDHashLen": 120,
"ZedServers": [
{
"HostName": "zedcontrol",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedlake",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedbobo",
"EID": [
"fdd5:79bf:7261:d9df:aea1:c8d2:842d:b99b"
]
},
{
"HostName": "hikey02",
"EID": [
"fdfd:ceef:cf85:7e40:6d4f:2181:ba06:e668"
]
},
{
"HostName": "hikey04",
"EID": [
"fd12:df08:d686:602d:2145:f7cf:2382:1683"
]
},
{
"HostName": "hikey05",
"EID": [
"fd81:abc5:7d7e:bcd7:40d9:df2c:be4b:600"
]
}
],
"EidAllocationPrefix": "/Q==",
"EidAllocationPrefixLen": 8
},
"manufacturer": "ZedVirtualDevice",
"productName": "ZedVirtual-4G"
}
57 changes: 54 additions & 3 deletions tests/cfg_run_xen.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,12 @@
"systemAdapterList": [
{
"uplink": true,
"freeUplink": true,
"name": "eth0",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d58",
"lowerLayerName": "eth0"
},
{
"uplink": true,
"freeUplink": true,
"name": "eth1",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d59",
"lowerLayerName": "eth1"
Expand Down Expand Up @@ -197,5 +195,58 @@
"ipType": 1,
"instType": 2
}
]
],
"lispInfo": {
"LispMapServers": [
{
"NameOrIp": "zedcontrol.zededa.net",
"Credential": "zededa-lispers.net"
}
],
"LispInstance": 1000,
"EID": "fd5b:8f21:c6b2:2c14:1d41:bd5f:bf40:d6c4",
"EIDHashLen": 120,
"ZedServers": [
{
"HostName": "zedcontrol",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedlake",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedbobo",
"EID": [
"fdd5:79bf:7261:d9df:aea1:c8d2:842d:b99b"
]
},
{
"HostName": "hikey02",
"EID": [
"fdfd:ceef:cf85:7e40:6d4f:2181:ba06:e668"
]
},
{
"HostName": "hikey04",
"EID": [
"fd12:df08:d686:602d:2145:f7cf:2382:1683"
]
},
{
"HostName": "hikey05",
"EID": [
"fd81:abc5:7d7e:bcd7:40d9:df2c:be4b:600"
]
}
],
"EidAllocationPrefix": "/Q==",
"EidAllocationPrefixLen": 8
},
"manufacturer": "ZedVirtualDevice",
"productName": "ZedVirtual-4G"
}
57 changes: 54 additions & 3 deletions tests/cfg_stop_rkt.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,12 @@
"systemAdapterList": [
{
"uplink": true,
"freeUplink": true,
"name": "eth0",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d58",
"lowerLayerName": "eth0"
},
{
"uplink": true,
"freeUplink": true,
"name": "eth1",
"networkUUID": "2e6038c1-ece6-4ffd-b95b-a7302c219d59",
"lowerLayerName": "eth1"
Expand Down Expand Up @@ -196,5 +194,58 @@
"ipType": 1,
"instType": 2
}
]
],
"lispInfo": {
"LispMapServers": [
{
"NameOrIp": "zedcontrol.zededa.net",
"Credential": "zededa-lispers.net"
}
],
"LispInstance": 1000,
"EID": "fd5b:8f21:c6b2:2c14:1d41:bd5f:bf40:d6c4",
"EIDHashLen": 120,
"ZedServers": [
{
"HostName": "zedcontrol",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedlake",
"EID": [
"fd45:efca:3607:4c1d:eace:a947:3464:d21e"
]
},
{
"HostName": "zedbobo",
"EID": [
"fdd5:79bf:7261:d9df:aea1:c8d2:842d:b99b"
]
},
{
"HostName": "hikey02",
"EID": [
"fdfd:ceef:cf85:7e40:6d4f:2181:ba06:e668"
]
},
{
"HostName": "hikey04",
"EID": [
"fd12:df08:d686:602d:2145:f7cf:2382:1683"
]
},
{
"HostName": "hikey05",
"EID": [
"fd81:abc5:7d7e:bcd7:40d9:df2c:be4b:600"
]
}
],
"EidAllocationPrefix": "/Q==",
"EidAllocationPrefixLen": 8
},
"manufacturer": "ZedVirtualDevice",
"productName": "ZedVirtual-4G"
}
Loading

0 comments on commit 02071ce

Please sign in to comment.