From b056e081d265c4eac464cb3426f76dbce1aaddd2 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Thu, 19 Dec 2024 11:06:59 +0000 Subject: [PATCH] lxd/instance/drivers/driver/lxc: Populate structs directly in Render Signed-off-by: Thomas Parrott --- lxd/instance/drivers/driver_lxc.go | 42 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go index 77814c34fee5..f090804800cb 100644 --- a/lxd/instance/drivers/driver_lxc.go +++ b/lxd/instance/drivers/driver_lxc.go @@ -3254,11 +3254,17 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, etag := []any{d.expiryDate} snapState := api.InstanceSnapshot{ - CreatedAt: d.creationDate, + Name: strings.SplitN(d.name, "/", 2)[1], + Architecture: architectureName, + Profiles: profileNames, + Config: d.localConfig, ExpandedConfig: d.expandedConfig, + Devices: d.localDevices.CloneNative(), ExpandedDevices: d.expandedDevices.CloneNative(), + CreatedAt: d.creationDate, LastUsedAt: d.lastUsedDate, - Name: strings.SplitN(d.name, "/", 2)[1], + ExpiresAt: d.expiryDate, + Ephemeral: d.ephemeral, Stateful: d.stateful, // Default to uninitialised/error state (0 means no CoW usage). @@ -3266,13 +3272,6 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, Size: -1, } - snapState.Architecture = architectureName - snapState.Config = d.localConfig - snapState.Devices = d.localDevices.CloneNative() - snapState.Ephemeral = d.ephemeral - snapState.Profiles = profileNames - snapState.ExpiresAt = d.expiryDate - for _, option := range options { err := option(&snapState) if err != nil { @@ -3287,12 +3286,22 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, etag = []any{d.architecture, d.localConfig, d.localDevices, d.ephemeral, d.profiles} instState := api.Instance{ + Name: d.name, + Description: d.description, + Architecture: architectureName, + Profiles: profileNames, + Config: d.localConfig, ExpandedConfig: d.expandedConfig, + Devices: d.LocalDevices().CloneNative(), ExpandedDevices: d.expandedDevices.CloneNative(), - Name: d.name, - StatusCode: api.Error, // Default to error status for remote instances that are unreachable. + CreatedAt: d.creationDate, + LastUsedAt: d.lastUsedDate, + Ephemeral: d.ephemeral, + Stateful: d.stateful, + Project: d.project.Name, Location: d.node, Type: d.Type().String(), + StatusCode: api.Error, // Default to error status for remote instances that are unreachable. } // If instance is local then request status. @@ -3302,17 +3311,6 @@ func (d *lxc) Render(options ...func(response any) error) (state any, etag any, instState.Status = instState.StatusCode.String() - instState.Description = d.description - instState.Architecture = architectureName - instState.Config = d.localConfig - instState.CreatedAt = d.creationDate - instState.Devices = d.localDevices.CloneNative() - instState.Ephemeral = d.ephemeral - instState.LastUsedAt = d.lastUsedDate - instState.Profiles = profileNames - instState.Stateful = d.stateful - instState.Project = d.project.Name - for _, option := range options { err := option(&instState) if err != nil {