Skip to content

Commit

Permalink
incusd/db: Introduce GetStorageBucketURIs
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Jun 27, 2024
1 parent 0dfa7cc commit 6a42aa1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions internal/server/db/storage_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
dqliteDriver "github.com/cowsql/go-cowsql/driver"

"github.com/lxc/incus/v6/internal/server/db/query"
"github.com/lxc/incus/v6/internal/version"
"github.com/lxc/incus/v6/shared/api"
)

Expand Down Expand Up @@ -633,3 +634,26 @@ WHERE storage_buckets.id = ?

return response, nil
}

// GetStorageBucketURIs returns the URIs of the storage buckets, specifying
// target node if applicable.
func (c *ClusterTx) GetStorageBucketURIs(ctx context.Context, project string) ([]string, error) {
filter := StorageBucketFilter{Project: &project}
bucketInfo, err := c.GetStoragePoolBuckets(ctx, false, filter)
if err != nil {
return nil, err
}

uris := []string{}
for _, info := range bucketInfo {
uri := api.NewURL().Path(version.APIVersion, "storage-pools", info.PoolName, "buckets", info.Name).Project(project)

if info.Location != "" {
uri.Target(info.Location)
}

uris = append(uris, uri.String())
}

return uris, nil
}

0 comments on commit 6a42aa1

Please sign in to comment.