Skip to content

Add list resource providers API for placement service#1815

Merged
jtopjian merged 4 commits intogophercloud:masterfrom
dkt26111:placement_resource_providers
Jan 14, 2020
Merged

Add list resource providers API for placement service#1815
jtopjian merged 4 commits intogophercloud:masterfrom
dkt26111:placement_resource_providers

Conversation

@dkt26111
Copy link
Copy Markdown
Contributor

For #526

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:

API doc:
https://docs.openstack.org/api-ref/placement/?expanded=#list-resource-providers

API code:
https://github.com/openstack/placement/blob/master/placement/handlers/resource_provider.py#L197

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 10, 2020

Coverage Status

Coverage decreased (-0.005%) to 77.074% when pulling f948e68 on dkt26111:placement_resource_providers into 20a03f8 on gophercloud:master.

Comment on lines +16 to +17
ParentProviderUuid string `json:"parent_provider_uuid"`
RootProviderUuid string `json:"root_provider_uuid"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUID capitalization for variable names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +56 to +57
ParentProviderUuid: "542df8ed-9be2-49b9-b4db-6d3183ff8ec8",
RootProviderUuid: "542df8ed-9be2-49b9-b4db-6d3183ff8ec8",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUID capitalization for variable names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +70 to +71
ParentProviderUuid: "",
RootProviderUuid: "d0b381e9-8761-42de-8e6c-bba99a96d5f5",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUID capitalization for variable names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jan 10, 2020

Build succeeded.

@dkt26111
Copy link
Copy Markdown
Contributor Author

@jtopjian This is ready for review. Thanks.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jan 10, 2020

Build succeeded.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkt26111 Thank you for working on this 🙂

This all looks good. I've left a few minor comments. In addition, the files need slightly reorganized:

  • acceptance/openstack/placement/v1
  • openstack/placement/v1/resourceproviders

Please let me know if you have any questions.

// NewPlacementClient returns a *ServiceClient for making calls
// to the OpenStack Placement API. An error will be returned
// if authentication or client creation was not possible.
func NewPlacementClient() (*gophercloud.ServiceClient, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewPlacementV1Client

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

// NewPlacement creates a ServiceClient that may be used with the placement package.
func NewPlacement(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewPlacementV1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


for _, r := range allResourceProviders {
fmt.Printf("%+v\n", r)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the formatting of the above example code looks a little off. godoc depends on correct formatting or else it wouldn't be a big deal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I'll fix that.

UUID string `q:"uuid"`

// Member_of is a string representing aggregate uuids to filter or exclude from the list
Member_of string `q:"member_of"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MemberOf

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// In_tree is a string that represents a resource provider UUID. The returned resource
// providers will be in the same provider tree as the specified provider.
In_tree string `q:"in_tree"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InTree

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Links []ResourceProviderLinks `json:"links"`
Name string `json:"name"`
ParentProviderUUID string `json:"parent_provider_uuid"`
RootProviderUUID string `json:"root_provider_uuid"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the above two fields are part of a microversion?

https://github.com/openstack/placement/blob/master/placement/handlers/resource_provider.py#L56-L58

According to our microversion rules, these should have their own Extract methods. However, Placement is still a relatively new service and I think 1.14 should be an early enough release that we can consider that part of "base".

It might be worthwhile to add a comment about this, though:

// ParentProviderUUID contains the UUID of the parent provider.
// Requires microversion 1.14 or above.
ParentProviderUUID string `json:"parent_provider_uuid"`

// RootProviderUUID contains the UUID of the root provider.
// Requires microversion 1.14 or above.
ParentProviderUUID string `json:"parent_provider_uuid"`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll add the comments.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci bot commented Jan 13, 2020

Build failed.

@dkt26111
Copy link
Copy Markdown
Contributor Author

@jtopjian Ready for review again.
The acceptance test failure is unrelated to placement.

Copy link
Copy Markdown
Contributor

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thank you!

Please see the comment about the acceptance test, just as a heads up.

th "github.com/gophercloud/gophercloud/testhelper"
)

func TestResourceProviderList(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a 403 error when I try to run this test as a normal user -- I think this requires admin access?

If so, then we need to add:

clients.RequireAdmin(t)

at the very beginning of this test function.

I'll make this change right after I merge this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. In fact all placement APIs appear to be restricted to admin by default:
https://docs.openstack.org/placement/latest/configuration/policy.html

I usually use admin user when running the acceptance tests so I didn't notice it.

@jtopjian jtopjian merged commit 75e9c9c into gophercloud:master Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants