Skip to content

Add Nova interface-list support - #430

Merged
jtopjian merged 1 commit into
gophercloud:masterfrom
FengyunPan:add-interface-list
Jul 28, 2017
Merged

jtopjian merged 1 commit into
gophercloud:masterfrom
FengyunPan:add-interface-list

Conversation

@FengyunPan

@FengyunPan FengyunPan commented Jul 22, 2017 •

Copy link
Copy Markdown

Add support to list interface for a server
through a GET on: /v2.1/{tenant_id}/servers/{server_id}/os-interface

The same operation with OpenStack CLI is done with:
nova interface-list <server_id>

Fix gophercloud issue:
#431

Fix kubernetes issue:

kubernetes/kubernetes#43909

@FengyunPan
FengyunPan force-pushed the add-interface-list branch from 52223c6 to 7c33e5b Compare July 22, 2017 08:04
@coveralls

coveralls commented Jul 22, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 71.252% when pulling 7c33e5b on FengyunPan:add-interface-list into 2804b72 on gophercloud:master.

@FengyunPan

FengyunPan commented Jul 22, 2017 •

Copy link
Copy Markdown
Author

@jtopjian Hi jtopjian, I'd like you to do a code review, thank you.
Currently the openstack cloud provider of kubernetes can't get port by ip, so we need support nova interface-list for it, then openstack cloud provider can get port by interface and ip.

@jtopjian

Copy link
Copy Markdown
Contributor

@FengyunPan Thank you for submitting this. Per the PR template and the STYLEGUIDE you'll need to provide links to the python source code which implements this feature in the OpenStack service. Also, a corresponding Gophercloud issue needs to be opened. Please let me know if you have any questions.

@FengyunPan

Copy link
Copy Markdown
Author

@jtopjian I have added it, need other information?

@jtopjian

Copy link
Copy Markdown
Contributor

@FengyunPan I had some time to look into this in more detail.

It looks like the ability to "get" interfaces is part of the os-interface-attachment. This can be seen in the Nova routes here and here. That ends up linking to the attach_interfaces.py file you linked to earlier:

https://github.com/openstack/nova/blob/4f91ed3a547965ed96a22520edcfb783e7936e95/nova/api/openstack/compute/attach_interfaces.py

This is actually utterly confusing because I had no idea this ability existed hidden in the os-attach-interface extension -- I could have used this a long time ago, so thank you for submitting it.

Since it's an extension, it needs to be packaged under the compute/v2/extensions directory, titled attachinterfaces. It's relatively easy to bundle this code as an extension. See the newly added pauseunpause package as a template.

As for the code itself, you'll need to modify the field names to use "camel case" rather than the current format which is using underscores. For example, Fixed_id needs renamed to FixedID, Port_state needs changed to PortState, etc.

Once all of that is done, I can do another review.

Let me know if you have any questions or need any help.

@FengyunPan

Copy link
Copy Markdown
Author

@jtopjian Thank for your comment, I will update it soon.

@FengyunPan
FengyunPan force-pushed the add-interface-list branch 2 times, most recently from c991229 to 2a59bd5 Compare July 27, 2017 09:01
@coveralls

coveralls commented Jul 27, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 71.252% when pulling 2a59bd5 on FengyunPan:add-interface-list into 2804b72 on gophercloud:master.

@jtopjian jtopjian left a comment

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.

@FengyunPan This looks really good. Thank you for both your patience and your work on this.

Please see the request for changes. They're all quite simple -- just renaming and rewording.

@@ -0,0 +1,3 @@
// Package attachinterfaces provides the ability to manage attach interfaces through

@jtopjian jtopjian Jul 28, 2017 •

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.

How about:

"the ability to manage network interfaces"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, thank you. Done.

)

// ListInterfaces makes a request against the nova API to list the servers interfaces.
func ListInterfaces(client *gophercloud.ServiceClient, id string) pagination.Pager {

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.

The attach-interfaces extension only lists one type of resource (interfaces), so this can be renamed to just List.

In addition, the id is the id of the server, so let's rename id to serverID so it's not mistaken as an "interface id".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

// Interface represents an interface.
type FixedID struct {
SubnetID string `json:"subnet_id"`
IpAddress string `json:"ip_address"`

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.

IPAddress

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

"github.com/gophercloud/gophercloud/pagination"
)

// Interface represents an interface.

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.

// FixedIP represents a Fixed IP Address.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

)

// Interface represents an interface.
type FixedID struct {

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.

FixedIP

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

IpAddress string `json:"ip_address"`
}

// Interface represents an interface.

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.

How about:

// Interface represents a network interface on an instance.

Just so it's not confused as a golang interface.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

// Interface represents an interface.
type Interface struct {
PortState string `json:"port_state"`
FixedIPs []FixedID `json:"fixed_ips"`

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.

FixedIPs []FixedIP `json:"fixed_ips"`

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

MacAddr string `json:"mac_addr"`
}

// InterfacePage abstracts the raw results of making a ListInterfaces() request against the API.

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.

List()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

t.Logf("Addresses on %s: %+v", network, address)
}

allInterfacePages, err := attachinterfaces.ListInterfaces(client, server.ID).AllPages()

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.

List

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

@coveralls

coveralls commented Jul 28, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 71.281% when pulling 8c294ef on FengyunPan:add-interface-list into 574cf4f on gophercloud:master.

@jtopjian jtopjian left a comment

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.

one more change. I apologize.

FixedIPs []FixedIP `json:"fixed_ips"`
PortID string `json:"port_id"`
NetID string `json:"net_id"`
MacAddr string `json:"mac_addr"`

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.

@FengyunPan I'm sorry, I just noticed this.

This should be MACAddr. There are several other areas in Gophercloud where MAC is used, so this will be consistent. It's better to change this now than later.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, my mistake, I update it soon, thank you very much.

Add support to list interface for a server
through a GET on: /v2.1/{tenant_id}/servers/{server_id}/os-interface

The same operation with OpenStack CLI is done with:
  nova interface-list <server_id>
@FengyunPan
FengyunPan force-pushed the add-interface-list branch from 8c294ef to d1f42e8 Compare July 28, 2017 04:52
@coveralls

coveralls commented Jul 28, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 71.281% when pulling d1f42e8 on FengyunPan:add-interface-list into 574cf4f on gophercloud:master.

@jtopjian

Copy link
Copy Markdown
Contributor

Looks good to me! Thank you again for your patience and for contributing this!

@jtopjian
jtopjian merged commit ec29b8a into gophercloud:master Jul 28, 2017
msheikh-wind pushed a commit to msheikh-wind/gophercloud that referenced this pull request May 19, 2025
This commit increases the Gomago Eventuall timeout to 30 seconds in
all tests cases to avoid tests failures by timeout [1].

[1]: https://github.com/Wind-River/cloud-platform-deployment-manager/pull/429/checks?check_run_id=33619644827

Test Case:
PASS - make test

Signed-off-by: Wallysson Silva <[email protected]>
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.

3 participants