diff options
author | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2017-11-23 14:23:15 +0100 |
---|---|---|
committer | Duncan Mac-Vicar P <dmacvicar@suse.de> | 2017-11-24 17:56:44 +0100 |
commit | a1145d25f878d0fc70229428c8076c27423d5a07 (patch) | |
tree | d1bbc6df6939755902d53f616c6ae7dc06650b9c /libvirt/utils_domain_def.go | |
parent | 06f312e1ca81074d3806816535d3039251691fb4 (diff) | |
download | terraform-provider-libvirt-a1145d25f878d0fc70229428c8076c27423d5a07.tar terraform-provider-libvirt-a1145d25f878d0fc70229428c8076c27423d5a07.tar.gz |
Read back cmdline, initrd and kernel attributes from the resource
Diffstat (limited to 'libvirt/utils_domain_def.go')
-rw-r--r-- | libvirt/utils_domain_def.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libvirt/utils_domain_def.go b/libvirt/utils_domain_def.go index a712f145..4e46cb62 100644 --- a/libvirt/utils_domain_def.go +++ b/libvirt/utils_domain_def.go @@ -4,6 +4,7 @@ import ( "fmt" libvirtxml "github.com/libvirt/libvirt-go-xml" "log" + "strings" ) func getGuestForArchType(caps libvirtxml.Caps, arch string, virttype string) (libvirtxml.CapsGuest, error) { @@ -47,3 +48,29 @@ func getOriginalMachineName(caps libvirtxml.Caps, arch string, virttype string, } return targetmachine, nil // There wasn't a canonical mapping to this } + +// as kernal args allow duplicate keys, we use a list of maps +// we jump to a next map as soon as we find a duplicate +// key +func splitKernelCmdLine(cmdLine string) ([]map[string]string, error) { + var cmdLines []map[string]string + currCmdLine := make(map[string]string) + argVals := strings.Split(cmdLine, " ") + for _, argVal := range argVals { + kv := strings.Split(argVal, "=") + if len(kv) != 2 { + return nil, fmt.Errorf("Can't parse kernel command line: '%s'", cmdLine) + } + k, v := kv[0], kv[1] + // if the key is duplicate, start a new map + if _, ok := currCmdLine[k]; ok { + cmdLines = append(cmdLines, currCmdLine) + currCmdLine = make(map[string]string) + } + currCmdLine[k] = v + } + if len(currCmdLine) > 0 { + cmdLines = append(cmdLines, currCmdLine) + } + return cmdLines, nil +} |