Skip to content

Commit b345b55

Browse files
committed
incusd/scriptlet/qemu: Remove legacy wrapper
Signed-off-by: Benjamin Somers <[email protected]>
1 parent 3de0c54 commit b345b55

File tree

1 file changed

+6
-39
lines changed

1 file changed

+6
-39
lines changed

internal/server/scriptlet/qemu.go

+6-39
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ import (
1717
"github.com/lxc/incus/v6/shared/logger"
1818
)
1919

20-
// qemuCfgSection is a temporary struct to hold QEMU configuration sections with Entries of type
21-
// map[string]string instead of []cfg.Entry. This type should be moved to the cfg package in the
22-
// future.
23-
type qemuCfgSection struct {
24-
Name string `json:"name"`
25-
Comment string `json:"comment"`
26-
Entries map[string]string `json:"entries"`
27-
}
28-
2920
// marshalQEMUConf marshals a configuration into a []map[string]any.
3021
func marshalQEMUConf(conf any) ([]map[string]any, error) {
3122
jsonConf, err := json.Marshal(conf)
@@ -42,14 +33,14 @@ func marshalQEMUConf(conf any) ([]map[string]any, error) {
4233
return newConf, nil
4334
}
4435

45-
// unmarshalQEMUConf unmarshals a configuration into a []qemuCfgSection.
46-
func unmarshalQEMUConf(conf any) ([]qemuCfgSection, error) {
36+
// unmarshalQEMUConf unmarshals a configuration into a []cfg.Section.
37+
func unmarshalQEMUConf(conf any) ([]cfg.Section, error) {
4738
jsonConf, err := json.Marshal(conf)
4839
if err != nil {
4940
return nil, err
5041
}
5142

52-
var newConf []qemuCfgSection
43+
var newConf []cfg.Section
5344
err = json.Unmarshal(jsonConf, &newConf)
5445
if err != nil {
5546
return nil, err
@@ -62,19 +53,8 @@ func unmarshalQEMUConf(conf any) ([]qemuCfgSection, error) {
6253
func QEMURun(l logger.Logger, instance *api.Instance, cmdArgs *[]string, conf *[]cfg.Section, m *qmp.Monitor, stage string) error {
6354
logFunc := log.CreateLogger(l, "QEMU scriptlet ("+stage+")")
6455

65-
// We first convert from []cfg.Section to []qemuCfgSection. This conversion is temporary.
66-
var cfgSectionMaps []qemuCfgSection
67-
for _, section := range *conf {
68-
entries := map[string]string{}
69-
for _, entry := range section.Entries {
70-
entries[entry.Key] = entry.Value
71-
}
72-
73-
cfgSectionMaps = append(cfgSectionMaps, qemuCfgSection{Name: section.Name, Comment: section.Comment, Entries: entries})
74-
}
75-
7656
// We do not want to handle a qemuCfgSection object within our scriptlet, for simplicity.
77-
cfgSections, err := marshalQEMUConf(cfgSectionMaps)
57+
cfgSections, err := marshalQEMUConf(conf)
7858
if err != nil {
7959
return err
8060
}
@@ -347,7 +327,7 @@ func QEMURun(l logger.Logger, instance *api.Instance, cmdArgs *[]string, conf *[
347327
}
348328

349329
// We want to further check the configuration structure, by trying to unmarshal it to a
350-
// []qemuCfgSection.
330+
// []cfg.Section.
351331
_, err = unmarshalQEMUConf(confAny)
352332
if err != nil {
353333
return nil, fmt.Errorf("%s requires a valid configuration", b.Name())
@@ -430,23 +410,10 @@ func QEMURun(l logger.Logger, instance *api.Instance, cmdArgs *[]string, conf *[
430410
}
431411

432412
// We need to convert the configuration back to a suitable format
433-
cfgSectionMaps, err = unmarshalQEMUConf(cfgSections)
413+
*conf, err = unmarshalQEMUConf(cfgSections)
434414
if err != nil {
435415
return err
436416
}
437417

438-
// We convert back from []qemuCfgSection to []cfg.Section. This conversion is temporary.
439-
var newConf []cfg.Section
440-
for _, section := range cfgSectionMaps {
441-
entries := []cfg.Entry{}
442-
for key, value := range section.Entries {
443-
entries = append(entries, cfg.Entry{Key: key, Value: value})
444-
}
445-
446-
newConf = append(newConf, cfg.Section{Name: section.Name, Comment: section.Comment, Entries: entries})
447-
}
448-
449-
*conf = newConf
450-
451418
return nil
452419
}

0 commit comments

Comments
 (0)