Skip to content

Commit

Permalink
lxd/instance/drivers/driver/lxc: Populate structs directly in Render
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Parrott <[email protected]>
  • Loading branch information
tomponline committed Dec 19, 2024
1 parent a374b0b commit b056e08
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions lxd/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3254,25 +3254,24 @@ 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).
// The size can then be populated optionally via the options argument.
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 {
Expand All @@ -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.
Expand All @@ -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 {
Expand Down

0 comments on commit b056e08

Please sign in to comment.