Skip to content

Commit

Permalink
lxd/db: Add function to remove volatile.last_state.ready key
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hipp <[email protected]>
  • Loading branch information
monstermunchkin authored and stgraber committed Jul 29, 2022
1 parent 157cc1a commit ad8f65c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lxd/db/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,27 @@ func (c *Cluster) GetInstancePool(project, instanceName string) (string, error)
return poolName, err
}

// DeleteReadyStateFromLocalInstances deletes the volatile.last_state.ready config key
// from all local instances.
func (c *Cluster) DeleteReadyStateFromLocalInstances() error {
err := c.Transaction(context.TODO(), func(ctx context.Context, tx *ClusterTx) error {
nodeID := tx.GetNodeID()

_, err := tx.Tx().Exec(`
DELETE FROM instances_config
WHERE instances_config.id IN (
SELECT instances_config.id FROM instances_config
JOIN instances ON instances_config.instance_id=instances.id
JOIN nodes ON instances.node_id=nodes.id
WHERE key="volatile.last_state.ready" AND nodes.id=?
)`, nodeID)

return err
})

return err
}

// CreateInstanceConfig inserts a new config for the instance with the given ID.
func CreateInstanceConfig(tx *sql.Tx, id int, config map[string]string) error {
stmt, err := tx.Prepare("INSERT INTO instances_config (instance_id, key, value) values (?, ?, ?)")
Expand Down

0 comments on commit ad8f65c

Please sign in to comment.