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]>
Sponsored-by: Luizalabs (https://luizalabs.com)
  • Loading branch information
stgraber committed Dec 22, 2023
1 parent 77f1b61 commit 607dc9d
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 607dc9d

Please sign in to comment.