Skip to content

Commit

Permalink
Looks for more device_owners when looking for a port for external
Browse files Browse the repository at this point in the history
network #1985
  • Loading branch information
bilbobrovall committed Apr 3, 2024
1 parent acc680d commit ce38e8b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 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,7 +59,22 @@ 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"`
}

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 +84,10 @@ 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"},
}

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

0 comments on commit ce38e8b

Please sign in to comment.