Skip to content

Commit

Permalink
incusd/network/ovn: Port LogicalSwitchPortIPs to OVSDB
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Dec 22, 2023
1 parent 1ac37dd commit 62ee302
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions internal/server/network/ovn/ovn_nb_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,14 +1115,28 @@ func (o *NB) LogicalSwitchPortAdd(switchName OVNSwitch, portName OVNSwitchPort,

// LogicalSwitchPortIPs returns a list of IPs for a switch port.
func (o *NB) LogicalSwitchPortIPs(portName OVNSwitchPort) ([]net.IP, error) {
addressesRaw, err := o.nbctl("--format=csv", "--no-headings", "--data=bare", "--column=addresses,dynamic_addresses", "find", "logical_switch_port", fmt.Sprintf("name=%s", string(portName)))
ctx := context.TODO()

lsp := ovnNB.LogicalSwitchPort{
Name: string(portName),
}

err := o.client.Get(ctx, &lsp)
if err != nil {
if err == ovsClient.ErrNotFound {
// Don't fail on missing port.
return []net.IP{}, nil
}

return nil, err
}

addresses := strings.Split(strings.Replace(strings.TrimSpace(addressesRaw), ",", " ", 1), " ")
ips := make([]net.IP, 0)
addresses := lsp.Addresses
if lsp.DynamicAddresses != nil {
addresses = append(addresses, strings.Split(*lsp.DynamicAddresses, " ")...)
}

ips := make([]net.IP, 0)
for _, address := range addresses {
ip := net.ParseIP(address)
if ip != nil {
Expand Down

0 comments on commit 62ee302

Please sign in to comment.