summaryrefslogtreecommitdiff
path: root/libvirt/utils_domain_def.go
diff options
context:
space:
mode:
Diffstat (limited to 'libvirt/utils_domain_def.go')
-rw-r--r--libvirt/utils_domain_def.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/libvirt/utils_domain_def.go b/libvirt/utils_domain_def.go
index a712f145..670d8b02 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,33 @@ 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
+ if len(cmdLine) == 0 {
+ return cmdLines, nil
+ }
+
+ 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
+}