diff options
author | Flavio Castelli <fcastelli@suse.com> | 2018-02-20 09:37:39 +0100 |
---|---|---|
committer | Flavio Castelli <flavio@castelli.me> | 2018-02-20 16:38:08 +0100 |
commit | 09834dbcf6d3353850cea0f51b4b07d811d3628d (patch) | |
tree | 9bfe565a07dc29066c24159911dd6d5bebfe5a28 /libvirt | |
parent | e456355639d72af6ff2da2acd30ec3e914bdd996 (diff) | |
download | terraform-provider-libvirt-09834dbcf6d3353850cea0f51b4b07d811d3628d.tar terraform-provider-libvirt-09834dbcf6d3353850cea0f51b4b07d811d3628d.tar.gz |
Handle keyword-less kernel params
Allow kernel params that don't have a key/value structure to be handled.
Signed-off-by: Flavio Castelli <fcastelli@suse.com>
Diffstat (limited to 'libvirt')
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 9 | ||||
-rw-r--r-- | libvirt/utils_domain_def.go | 13 | ||||
-rw-r--r-- | libvirt/utils_domain_def_test.go | 4 |
3 files changed, 23 insertions, 3 deletions
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 8d9be0e1..f7d7a074 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -992,7 +992,14 @@ func setCmdlineArgs(d *schema.ResourceData, domainDef *libvirtxml.Domain) { var cmdlineArgs []string for i := 0; i < d.Get("cmdline.#").(int); i++ { for k, v := range d.Get(fmt.Sprintf("cmdline.%d", i)).(map[string]interface{}) { - cmdlineArgs = append(cmdlineArgs, fmt.Sprintf("%s=%v", k, v)) + var cmd string + if k == "_" { + // keyless cmd (eg: nosplash) + cmd = fmt.Sprintf("%v", v) + } else { + cmd = fmt.Sprintf("%s=%v", k, v) + } + cmdlineArgs = append(cmdlineArgs, cmd) } } sort.Strings(cmdlineArgs) diff --git a/libvirt/utils_domain_def.go b/libvirt/utils_domain_def.go index 40d31a09..90175de1 100644 --- a/libvirt/utils_domain_def.go +++ b/libvirt/utils_domain_def.go @@ -60,8 +60,16 @@ func splitKernelCmdLine(cmdLine string) ([]map[string]string, error) { } currCmdLine := make(map[string]string) + keylessCmdLineArgs := []string{} + argVals := strings.Split(cmdLine, " ") for _, argVal := range argVals { + if !strings.Contains(argVal, "=") { + // keyless cmd line (eg: nosplash) + keylessCmdLineArgs = append(keylessCmdLineArgs, argVal) + continue + } + kv := strings.Split(argVal, "=") if len(kv) != 2 { return nil, fmt.Errorf("Can't parse kernel command line: '%s'", cmdLine) @@ -77,5 +85,10 @@ func splitKernelCmdLine(cmdLine string) ([]map[string]string, error) { if len(currCmdLine) > 0 { cmdLines = append(cmdLines, currCmdLine) } + if len(keylessCmdLineArgs) > 0 { + cl := make(map[string]string) + cl["_"] = strings.Join(keylessCmdLineArgs, " ") + cmdLines = append(cmdLines, cl) + } return cmdLines, nil } diff --git a/libvirt/utils_domain_def_test.go b/libvirt/utils_domain_def_test.go index 7ff57203..746c095b 100644 --- a/libvirt/utils_domain_def_test.go +++ b/libvirt/utils_domain_def_test.go @@ -12,8 +12,8 @@ func init() { } func TestSplitKernelCmdLine(t *testing.T) { - e := []map[string]string{{"foo": "bar"}, {"foo": "bar", "key": "val"}} - r, err := splitKernelCmdLine("foo=bar foo=bar key=val") + e := []map[string]string{{"foo": "bar"}, {"foo": "bar", "key": "val"}, {"_": "nosplash rw"}} + r, err := splitKernelCmdLine("foo=bar foo=bar key=val nosplash rw") if !reflect.DeepEqual(r, e) { t.Fatalf("got='%s' expected='%s'", spew.Sdump(r), spew.Sdump(e)) } |