lxd/db/containers.go
func (c *ClusterTx) ContainersByNodeName(project string) (map[string]string, error) {
	stmt := `
SELECT containers.name, nodes.name
  FROM containers
  JOIN nodes ON nodes.id = containers.node_id
  JOIN projects ON projects.id = containers.project_id
  WHERE containers.type=?
    AND projects.name = ?
`
	rows, err := c.tx.Query(stmt, CTypeRegular, project)
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	result := map[string]string{}

	for i := 0; rows.Next(); i++ {
		var name string
		var nodeName string
		err := rows.Scan(&name, &nodeName)
		if err != nil {
			return nil, err
		}
		result[name] = nodeName
	}

	err = rows.Err()
	if err != nil {
		return nil, err
	}
	return result, nil
}
func (c *ClusterTx) ContainersByNodeName(project string) (map[string]string, error) {
	stmt := `
SELECT containers.name, nodes.name
  FROM containers
  JOIN nodes ON nodes.id = containers.node_id
  JOIN projects ON projects.id = containers.project_id
  WHERE containers.type=?
    AND projects.name = ?
`
	rows, err := c.tx.Query(stmt, CTypeRegular, project)
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	result := map[string]string{}

	for i := 0; rows.Next(); i++ {
		var name string
		var nodeName string
		err := rows.Scan(&name, &nodeName)
		if err != nil {
			return nil, err
		}
		result[name] = nodeName
	}

	err = rows.Err()
	if err != nil {
		return nil, err
	}
	return result, nil
}
// ContainersByNodeName returns a map associating each container to the name of
// its node.