@@ -17,15 +17,6 @@ import (
17
17
"github.com/lxc/incus/v6/shared/logger"
18
18
)
19
19
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
-
29
20
// marshalQEMUConf marshals a configuration into a []map[string]any.
30
21
func marshalQEMUConf (conf any ) ([]map [string ]any , error ) {
31
22
jsonConf , err := json .Marshal (conf )
@@ -42,14 +33,14 @@ func marshalQEMUConf(conf any) ([]map[string]any, error) {
42
33
return newConf , nil
43
34
}
44
35
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 ) {
47
38
jsonConf , err := json .Marshal (conf )
48
39
if err != nil {
49
40
return nil , err
50
41
}
51
42
52
- var newConf []qemuCfgSection
43
+ var newConf []cfg. Section
53
44
err = json .Unmarshal (jsonConf , & newConf )
54
45
if err != nil {
55
46
return nil , err
@@ -62,19 +53,8 @@ func unmarshalQEMUConf(conf any) ([]qemuCfgSection, error) {
62
53
func QEMURun (l logger.Logger , instance * api.Instance , cmdArgs * []string , conf * []cfg.Section , m * qmp.Monitor , stage string ) error {
63
54
logFunc := log .CreateLogger (l , "QEMU scriptlet (" + stage + ")" )
64
55
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
-
76
56
// We do not want to handle a qemuCfgSection object within our scriptlet, for simplicity.
77
- cfgSections , err := marshalQEMUConf (cfgSectionMaps )
57
+ cfgSections , err := marshalQEMUConf (conf )
78
58
if err != nil {
79
59
return err
80
60
}
@@ -347,7 +327,7 @@ func QEMURun(l logger.Logger, instance *api.Instance, cmdArgs *[]string, conf *[
347
327
}
348
328
349
329
// We want to further check the configuration structure, by trying to unmarshal it to a
350
- // []qemuCfgSection .
330
+ // []cfg.Section .
351
331
_ , err = unmarshalQEMUConf (confAny )
352
332
if err != nil {
353
333
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 *[
430
410
}
431
411
432
412
// We need to convert the configuration back to a suitable format
433
- cfgSectionMaps , err = unmarshalQEMUConf (cfgSections )
413
+ * conf , err = unmarshalQEMUConf (cfgSections )
434
414
if err != nil {
435
415
return err
436
416
}
437
417
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
-
451
418
return nil
452
419
}
0 commit comments