Skip to content

Commit

Permalink
fetch only user projects in order to expand flavor attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rplevka authored and srebhan committed Jun 10, 2024
1 parent e147904 commit c911e90
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/inputs/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack/identity/v3/projects"
"github.com/gophercloud/gophercloud/v2/openstack/identity/v3/services"
"github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens"
"github.com/gophercloud/gophercloud/v2/openstack/identity/v3/users"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/agents"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/ports"
Expand Down Expand Up @@ -250,7 +251,17 @@ func (o *OpenStack) Start(telegraf.Accumulator) error {
}

// We need the project to deliver a human readable name in servers
page, err = projects.List(o.identity, nil).AllPages(ctx)

// Get session token details and extract the user id in order to fetch their projects
// FIXME?: the provider object might already contain the user info - i haven't managed to find it
token := tokens.Get(context.TODO(), o.identity, provider.TokenID)
user, err := token.ExtractUser()
if err != nil {
return fmt.Errorf("unable to extract user from the obtained token: %w", err)
}
o.Log.Debug("obtained user: %+v", user)

page, err = users.ListProjects(o.identity, user.ID).AllPages(ctx)
if err != nil {
return fmt.Errorf("unable to list projects: %w", err)
}
Expand Down

0 comments on commit c911e90

Please sign in to comment.