lxd/db/profiles.go
func (c *Cluster) ProfileContainersGet(project, profile string) (map[string][]string, error) {
	err := c.Transaction(func(tx *ClusterTx) error {
		enabled, err := tx.ProjectHasProfiles(project)
		if err != nil {
			return errors.Wrap(err, "Check if project has profiles")
		}
		if !enabled {
			project = "default"
		}
		return nil
	})
	if err != nil {
		return nil, err
	}

	q := `SELECT containers.name, projects.name FROM containers
		JOIN containers_profiles ON containers.id == containers_profiles.container_id
		JOIN projects ON projects.id == containers.project_id
		WHERE containers_profiles.profile_id ==
		  (SELECT profiles.id FROM profiles
		   JOIN projects ON projects.id == profiles.project_id
		   WHERE profiles.name=? AND projects.name=?)
		AND containers.type == 0`

	results := map[string][]string{}
	inargs := []interface{}{profile, project}
	var name string
	outfmt := []interface{}{name, name}

	output, err := queryScan(c.db, q, inargs, outfmt)
	if err != nil {
		return nil, err
	}

	for _, r := range output {
		if results[r[1].(string)] == nil {
			results[r[1].(string)] = []string{}
		}

		results[r[1].(string)] = append(results[r[1].(string)], r[0].(string))
	}

	return results, nil
}
func (c *Cluster) ProfileContainersGet(project, profile string) (map[string][]string, error) {
	err := c.Transaction(func(tx *ClusterTx) error {
		enabled, err := tx.ProjectHasProfiles(project)
		if err != nil {
			return errors.Wrap(err, "Check if project has profiles")
		}
		if !enabled {
			project = "default"
		}
		return nil
	})
	if err != nil {
		return nil, err
	}

	q := `SELECT containers.name, projects.name FROM containers
		JOIN containers_profiles ON containers.id == containers_profiles.container_id
		JOIN projects ON projects.id == containers.project_id
		WHERE containers_profiles.profile_id ==
		  (SELECT profiles.id FROM profiles
		   JOIN projects ON projects.id == profiles.project_id
		   WHERE profiles.name=? AND projects.name=?)
		AND containers.type == 0`

	results := map[string][]string{}
	inargs := []interface{}{profile, project}
	var name string
	outfmt := []interface{}{name, name}

	output, err := queryScan(c.db, q, inargs, outfmt)
	if err != nil {
		return nil, err
	}

	for _, r := range output {
		if results[r[1].(string)] == nil {
			results[r[1].(string)] = []string{}
		}

		results[r[1].(string)] = append(results[r[1].(string)], r[0].(string))
	}

	return results, nil
}
func ( c * Cluster ) ProfileContainersGet ( project , profile string ) ( map [ string ] [ ] string , error ) { err := c . Transaction ( func ( tx * ClusterTx ) error { enabled , err := tx . ProjectHasProfiles ( project ) if err != nil { return errors . Wrap ( err , " " ) } if ! enabled { project = " " } return nil } ) if err != nil { return nil , err } q := `SELECT containers.name, projects.name FROM containers
		JOIN containers_profiles ON containers.id == containers_profiles.container_id
		JOIN projects ON projects.id == containers.project_id
		WHERE containers_profiles.profile_id ==
		  (SELECT profiles.id FROM profiles
		   JOIN projects ON projects.id == profiles.project_id
		   WHERE profiles.name=? AND projects.name=?)
		AND containers.type == 0` results := map [ string ] [ ] string { } inargs := [ ] interface { } { profile , project } var name string outfmt := [ ] interface { } { name , name } output , err := queryScan ( c . db , q , inargs , outfmt ) if err != nil { return nil , err } for _ , r := range output { if results [ r [ 1 ] . ( string ) ] == nil { results [ r [ 1 ] . ( string ) ] = [ ] string { } } results [ r [ 1 ] . ( string ) ] = append ( results [ r [ 1 ] . ( string ) ] , r [ 0 ] . ( string ) ) } return results , nil }
// ProfileContainersGet gets the names of the containers associated with the
// profile with the given name.
ProfileContainersGet gets the names of the containers associated with the profile with the given name .