lxd/db/storage_volumes.go
func (c *ClusterTx) StorageVolumeNodeAddresses(poolID int64, project, name string, typ int) ([]string, error) {
	nodes := []struct {
		id      int64
		address string
	}{}
	dest := func(i int) []interface{} {
		nodes = append(nodes, struct {
			id      int64
			address string
		}{})
		return []interface{}{&nodes[i].id, &nodes[i].address}

	}
	sql := `
SELECT nodes.id, nodes.address
  FROM nodes
  JOIN storage_volumes ON storage_volumes.node_id=nodes.id
  JOIN projects ON projects.id = storage_volumes.project_id
 WHERE storage_volumes.storage_pool_id=? AND projects.name=? AND storage_volumes.name=? AND storage_volumes.type=?
`
	stmt, err := c.tx.Prepare(sql)
	if err != nil {
		return nil, err
	}
	defer stmt.Close()
	err = query.SelectObjects(stmt, dest, poolID, project, name, typ)
	if err != nil {
		return nil, err
	}

	addresses := []string{}
	for _, node := range nodes {
		address := node.address
		if node.id == c.nodeID {
			address = ""
		}
		addresses = append(addresses, address)
	}

	sort.Strings(addresses)

	if len(addresses) == 0 {
		return nil, ErrNoSuchObject
	}

	return addresses, nil
}
func (c *ClusterTx) StorageVolumeNodeAddresses(poolID int64, project, name string, typ int) ([]string, error) {
	nodes := []struct {
		id      int64
		address string
	}{}
	dest := func(i int) []interface{} {
		nodes = append(nodes, struct {
			id      int64
			address string
		}{})
		return []interface{}{&nodes[i].id, &nodes[i].address}

	}
	sql := `
SELECT nodes.id, nodes.address
  FROM nodes
  JOIN storage_volumes ON storage_volumes.node_id=nodes.id
  JOIN projects ON projects.id = storage_volumes.project_id
 WHERE storage_volumes.storage_pool_id=? AND projects.name=? AND storage_volumes.name=? AND storage_volumes.type=?
`
	stmt, err := c.tx.Prepare(sql)
	if err != nil {
		return nil, err
	}
	defer stmt.Close()
	err = query.SelectObjects(stmt, dest, poolID, project, name, typ)
	if err != nil {
		return nil, err
	}

	addresses := []string{}
	for _, node := range nodes {
		address := node.address
		if node.id == c.nodeID {
			address = ""
		}
		addresses = append(addresses, address)
	}

	sort.Strings(addresses)

	if len(addresses) == 0 {
		return nil, ErrNoSuchObject
	}

	return addresses, nil
}
func ( c * ClusterTx ) StorageVolumeNodeAddresses ( poolID int64 , project , name string , typ int ) ( [ ] string , error ) { nodes := [ ] struct { id int64 address string } { } dest := func ( i int ) [ ] interface { } { nodes = append ( nodes , struct { id int64 address string } { } ) return [ ] interface { } { & nodes [ i ] . id , & nodes [ i ] . address } } sql := `
SELECT nodes.id, nodes.address
  FROM nodes
  JOIN storage_volumes ON storage_volumes.node_id=nodes.id
  JOIN projects ON projects.id = storage_volumes.project_id
 WHERE storage_volumes.storage_pool_id=? AND projects.name=? AND storage_volumes.name=? AND storage_volumes.type=?
` stmt , err := c . tx . Prepare ( sql ) if err != nil { return nil , err } defer stmt . Close ( ) err = query . SelectObjects ( stmt , dest , poolID , project , name , typ ) if err != nil { return nil , err } addresses := [ ] string { } for _ , node := range nodes { address := node . address if node . id == c . nodeID { address = " " } addresses = append ( addresses , address ) } sort . Strings ( addresses ) if len ( addresses ) == 0 { return nil , ErrNoSuchObject } return addresses , nil }
// StorageVolumeNodeAddresses returns the addresses of all nodes on which the
// volume with the given name if defined.
//
// The empty string is used in place of the address of the current node.
StorageVolumeNodeAddresses returns the addresses of all nodes on which the volume with the given name if defined . The empty string is used in place of the address of the current node .