Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pkg/cloud/services/networking/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"
"time"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
Expand Down Expand Up @@ -58,6 +59,19 @@ func (s *Service) GetPortFromInstanceIP(instanceID string, ip string) ([]ports.P
return s.client.ListPort(portOpts)
}

type PortListOpts struct {
DeviceOwner []string `q:"device_owner"`
NetworkID string `q:"network_id"`
}
Comment on lines +62 to +65

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.

@pierreprinetti: I know you've been looking at this from Gophercloud perspective. Is this the way to go here?

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.

Eventually hopefully not, but I think this is the only way to go currently.


func (p *PortListOpts) ToPortListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(p)
if err != nil {
return "", err
}
return q.String(), nil
}

func (s *Service) GetPortForExternalNetwork(instanceID string, externalNetworkID string) (*ports.Port, error) {
instancePortsOpts := ports.ListOpts{
DeviceID: instanceID,
Expand All @@ -68,9 +82,9 @@ func (s *Service) GetPortForExternalNetwork(instanceID string, externalNetworkID
}

for _, instancePort := range instancePorts {
networkPortsOpts := ports.ListOpts{
networkPortsOpts := &PortListOpts{
NetworkID: instancePort.NetworkID,
DeviceOwner: "network:router_interface",
DeviceOwner: []string{"network:router_interface", "network:router_interface_distributed", "network:ha_router_replicated_interface", "network:router_ha_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.

This is the stuff I'd really like to push into the domain of gophercloud.

}

networkPorts, err := s.client.ListPort(networkPortsOpts)
Expand Down