lxd/db/devices.go
func (c *Cluster) Devices(project, qName string, isprofile bool) (types.Devices, error) {
	err := c.Transaction(func(tx *ClusterTx) error {
		enabled, err := tx.ProjectHasProfiles(project)
		if err != nil {
			return err
		}
		if !enabled {
			project = "default"
		}
		return nil
	})
	if err != nil {
		return nil, err
	}

	var q string
	if isprofile {
		q = `SELECT profiles_devices.id, profiles_devices.name, profiles_devices.type
			FROM profiles_devices
                        JOIN profiles ON profiles_devices.profile_id = profiles.id
                        JOIN projects ON projects.id=profiles.project_id
   		WHERE projects.name=? AND profiles.name=?`
	} else {
		q = `SELECT containers_devices.id, containers_devices.name, containers_devices.type
			FROM containers_devices
                        JOIN containers	ON containers_devices.container_id = containers.id
                        JOIN projects ON projects.id=containers.project_id
			WHERE projects.name=? AND containers.name=?`
	}
	var id, dtype int
	var name, stype string
	inargs := []interface{}{project, qName}
	outfmt := []interface{}{id, name, dtype}
	results, err := queryScan(c.db, q, inargs, outfmt)
	if err != nil {
		return nil, err
	}

	devices := types.Devices{}
	for _, r := range results {
		id = r[0].(int)
		name = r[1].(string)
		stype, err = dbDeviceTypeToString(r[2].(int))
		if err != nil {
			return nil, err
		}
		newdev, err := dbDeviceConfig(c.db, id, isprofile)
		if err != nil {
			return nil, err
		}
		newdev["type"] = stype
		devices[name] = newdev
	}

	return devices, nil
}
func (c *Cluster) Devices(project, qName string, isprofile bool) (types.Devices, error) {
	err := c.Transaction(func(tx *ClusterTx) error {
		enabled, err := tx.ProjectHasProfiles(project)
		if err != nil {
			return err
		}
		if !enabled {
			project = "default"
		}
		return nil
	})
	if err != nil {
		return nil, err
	}

	var q string
	if isprofile {
		q = `SELECT profiles_devices.id, profiles_devices.name, profiles_devices.type
			FROM profiles_devices
                        JOIN profiles ON profiles_devices.profile_id = profiles.id
                        JOIN projects ON projects.id=profiles.project_id
   		WHERE projects.name=? AND profiles.name=?`
	} else {
		q = `SELECT containers_devices.id, containers_devices.name, containers_devices.type
			FROM containers_devices
                        JOIN containers	ON containers_devices.container_id = containers.id
                        JOIN projects ON projects.id=containers.project_id
			WHERE projects.name=? AND containers.name=?`
	}
	var id, dtype int
	var name, stype string
	inargs := []interface{}{project, qName}
	outfmt := []interface{}{id, name, dtype}
	results, err := queryScan(c.db, q, inargs, outfmt)
	if err != nil {
		return nil, err
	}

	devices := types.Devices{}
	for _, r := range results {
		id = r[0].(int)
		name = r[1].(string)
		stype, err = dbDeviceTypeToString(r[2].(int))
		if err != nil {
			return nil, err
		}
		newdev, err := dbDeviceConfig(c.db, id, isprofile)
		if err != nil {
			return nil, err
		}
		newdev["type"] = stype
		devices[name] = newdev
	}

	return devices, nil
}
func ( c * Cluster ) Devices ( project , qName string , isprofile bool ) ( types . Devices , error ) { err := c . Transaction ( func ( tx * ClusterTx ) error { enabled , err := tx . ProjectHasProfiles ( project ) if err != nil { return err } if ! enabled { project = " " } return nil } ) if err != nil { return nil , err } var q string if isprofile { q = `SELECT profiles_devices.id, profiles_devices.name, profiles_devices.type
			FROM profiles_devices
                        JOIN profiles ON profiles_devices.profile_id = profiles.id
                        JOIN projects ON projects.id=profiles.project_id
   		WHERE projects.name=? AND profiles.name=?` } else { q = `SELECT containers_devices.id, containers_devices.name, containers_devices.type
			FROM containers_devices
                        JOIN containers	ON containers_devices.container_id = containers.id
                        JOIN projects ON projects.id=containers.project_id
			WHERE projects.name=? AND containers.name=?` } var id , dtype int var name , stype string inargs := [ ] interface { } { project , qName } outfmt := [ ] interface { } { id , name , dtype } results , err := queryScan ( c . db , q , inargs , outfmt ) if err != nil { return nil , err } devices := types . Devices { } for _ , r := range results { id = r [ 0 ] . ( int ) name = r [ 1 ] . ( string ) stype , err = dbDeviceTypeToString ( r [ 2 ] . ( int ) ) if err != nil { return nil , err } newdev , err := dbDeviceConfig ( c . db , id , isprofile ) if err != nil { return nil , err } newdev [ " " ] = stype devices [ name ] = newdev } return devices , nil }
// Devices returns the devices matching the given filters.
Devices returns the devices matching the given filters .