diff --git a/internal/virt/domain/domain.go b/internal/virt/domain/domain.go index 6f1f761..cde9ca0 100644 --- a/internal/virt/domain/domain.go +++ b/internal/virt/domain/domain.go @@ -402,12 +402,17 @@ func (d *VirtDomain) render() ([]byte, error) { return nil, err } } + hostDirs, err := d.hostDirs() + if err != nil { + return nil, err + } var args = map[string]any{ "name": d.guest.ID, "uuid": uuid, "memory": d.guest.MemoryInMiB(), "cpu": d.guest.CPU, "gpus": gpus, + "host_dirs": hostDirs, "sysvol": string(sysVolXML), "datavols": dataVols, "interface": d.getInterfaceType(), @@ -555,6 +560,29 @@ func (d *VirtDomain) gpus() ([]map[string]string, error) { return allocGPUs(d.guest.GPUEngineParams) } +func (d *VirtDomain) hostDirs() ([]map[string]string, error) { + ss, ok := d.guest.JSONLabels["instance/host-dirs"] + if !ok { + return nil, nil + } + parts := strings.FieldsFunc(ss, func(r rune) bool { + return r == ',' || r == ' ' || r == ';' + }) + ans := make([]map[string]string, 0, len(parts)) + for _, p := range parts { + switch parts2 := strings.Split(p, ":"); len(parts2) { + case 2: + ans = append(ans, map[string]string{ + "src": parts2[0], + "dst": parts2[1], + }) + default: + return nil, fmt.Errorf("invalid host dir: %s", p) + } + } + return ans, nil +} + type vncConfig struct { Port int `json:"port"` Password string `json:"password"` diff --git a/internal/virt/domain/templates/guest.xml b/internal/virt/domain/templates/guest.xml index fbe3960..b62bbde 100644 --- a/internal/virt/domain/templates/guest.xml +++ b/internal/virt/domain/templates/guest.xml @@ -42,6 +42,14 @@ + + {{if .host_dirs }} + + + + + {{end}} + {{ .sysvol }} @@ -56,6 +64,15 @@
+ + {{range .host_dirs}} + + + + + + {{end}} +