Conversation
This commit add the Ports API calls according to [1] - List Ports (GET) - Create Port (POST) - List Detailed Ports (GET) - Show Port Details (GET) - Update a Port (PATCH) - Delete Port (DELETE) [1] https://developer.openstack.org/api-ref/baremetal/?expanded=#ports-ports
|
Build failed.
|
dtantsur
left a comment
There was a problem hiding this comment.
A few comments inline, but nothing stands out as blocking.
openstack/baremetal/v1/ports/doc.go
Outdated
| // Example to Create a Port | ||
| createPort, err := ports.Create(client, ports.CreateOpts{ | ||
| NodeUUID: "e8920409-e07e-41bb-8cc1-72acb103e2dd", | ||
| Address: "00-1B-63-84-45-E6", |
There was a problem hiding this comment.
I think ironic accepts addresses only separated by colon. I may be wrong though, needs double-checking.
There was a problem hiding this comment.
yeah I will update
| Node string `q:"node"` | ||
|
|
||
| // Filter the list by the Node uuid | ||
| NodeUUID string `q:"node_uuid"` |
There was a problem hiding this comment.
This is unfortunate, node_uuid is so ancient (API 1.6, Liberty era?), I'd love to avoid it. I wonder if we can default to microversion 1.6 and get rid of this..
There was a problem hiding this comment.
Is it not supported on 1.6 or later? It's still listed in the most current API docs
There was a problem hiding this comment.
Well, was in the documentation .-.
There was a problem hiding this comment.
I think Dmitry might be thinking of /v1/nodes/$uuid/ports/, although that is not how the API is documented.. and I think we should conform to how the API is documented.
| Links []string `json:"links"` | ||
|
|
||
| // Indicates whether the Port is a Smart NIC port. | ||
| IsSmartnic bool `json:"is_smartnic"` |
There was a problem hiding this comment.
I wonder if it should be IsSmartNIC, depending on the Go rules.
There was a problem hiding this comment.
IsSmartNIC looks best to me
There was a problem hiding this comment.
Tks I will update!
stbenjam
left a comment
There was a problem hiding this comment.
To me this looks pretty good, a couple comments below
| // List request. | ||
| type ListOptsBuilder interface { | ||
| ToPortListQuery() (string, error) | ||
| ToPortListDetailQuery() (string, error) |
There was a problem hiding this comment.
Indentation is off here and elsewhere, I would run gofmt on all your files. go is rather opinionated, there's "one" way to format the code, I use this in vim: https://github.com/stbenjam/dotfiles/blob/master/vimrc#L73. GoLand IDE also does it. There's git hooks out there too to run the CLI before commit.
| Node string `q:"node"` | ||
|
|
||
| // Filter the list by the Node uuid | ||
| NodeUUID string `q:"node_uuid"` |
There was a problem hiding this comment.
Is it not supported on 1.6 or later? It's still listed in the most current API docs
|
@iurygregory Also can you update the description, so it references #1429 without the brackets so GitHub makes the link automagically? |
|
@stbenjam going to update |
- Fix Address in doc - Renamed IsSmartnic to IsSmartNIC - Fixed Indentation using go fmt - Fixed acceptance test
- Fix acceptance for noauth and v1 to use correct field - Fix undefined field for Port in requests_test
|
Build failed.
|
| }) | ||
| } | ||
|
|
||
| // HandlePortListSuccessfully sets up the test server to respond to a server List request. |
There was a problem hiding this comment.
nit: should change comment based on the actual function HandlePortListDetailSuccessfully
-Fixed acceptance tests (validated using DevStack - Stein on Ubuntu) -Fixed unnit tests -Fixed Links variable type
- Missing v1 before the functions to create fake node and delete
|
Build failed.
|
jtopjian
left a comment
There was a problem hiding this comment.
Hi all,
I'm not sure if this is ready for an official review yet (when ready, please leave a comment of something like "ready for review"), but figured I would look it over.
First, thank you for the collaborative effort on this. All comments and changes were relevant.
I've left two general comments, possibly requiring no actions.
As I've mentioned before, I'm not familiar with Ironic so I can't comment on the functionality, but the code itself looks good to me. I can merge this when it's ready.
Also, the acceptance test failure can be ignored - I'm in the process of fixing that now.
| LocalLinkConnection map[string]interface{} `json:"local_link_connection,omitempty"` | ||
|
|
||
| // Indicates whether PXE is enabled or disabled on the Port. | ||
| PXEEnabled bool `json:"pxe_enabled,omitempty"` |
There was a problem hiding this comment.
Having bool and omitempty together will never allow a value of false to be sent to the API service. This is because false is bool's zero-value and omitempty omits zero-values.
If it is acceptable for a value of false to never be sent, then this is fine as-is. But if you want the ability to send both true and false, then change this to *bool and keep omitempty.
Alternatively, use bool but remove omitempty to cause false to always be sent as default - but that's rarely the desired behavior.
There was a problem hiding this comment.
Updated PXEEnabled and IsSmartNIC
There was a problem hiding this comment.
Hmm, the default for pxe_enabled is true, so we must be able to send false.
| type UpdateOperation struct { | ||
| Op UpdateOp `json:"op,required"` | ||
| Path string `json:"path,required"` | ||
| Value string `json:"value,omitempty"` |
There was a problem hiding this comment.
A recent issue that was reported is: #1458
I'm not sure if this is applicable here, but wanted to mention it in case.
There was a problem hiding this comment.
I will setup a env with Python3 for Ironic and check if this will be a problem
jtopjian
left a comment
There was a problem hiding this comment.
Oops - actually I just spotted two minor changes.
These changes allow the acceptance tests to only run when explicitly triggered.
| @@ -0,0 +1,71 @@ | |||
| package noauth | |||
There was a problem hiding this comment.
There needs to be the following two lines before the package statement:
// +build acceptance baremetal ports
The newline is required.
| @@ -0,0 +1,70 @@ | |||
| package v1 | |||
-Added header for acceptance tests
-Change `bool` to `*bool` to allow true and false for
PXEEnabled and IsSmartNIC
-Change UpdateOperation Value to `interface{}` to avoid problems
when not using string (e.g, booleans, jsons)
|
Build failed.
|
|
@iurygregory with the change from port, err := ports.Create(client, ports.CreateOpts{
NodeUUID: node.UUID,
Address: mac,
PXEEnabled: true,
}).Extract()It'll now need to be: iTrue := true
port, err := ports.Create(client, ports.CreateOpts{
NodeUUID: node.UUID,
Address: mac,
PXEEnabled: &iTrue,
}).Extract() |
Type `*bool` requires the pointer for a variable with `bool` value
- `itrue` is undefined, change to `iTrue` that is defined on line 71.
|
Build succeeded.
|
Don't set bool value directly to PXEEnabled since it's `*bool` type
|
Build succeeded.
|
|
@iurygregory This looks good to me. Let me know if it's ready to be merged? |
|
@jtopjian Yeah it's =) |
For #1429
This PR covers the Ports API calls according to the Baremetal API reference
You can view the source code here