Skip to content

Commit

Permalink
Update ocaml/xapi/xapi_pif_helpers.ml
Browse files Browse the repository at this point in the history
Co-authored-by: Pau Ruiz Safont <[email protected]>
Signed-off-by: BenjiReis <[email protected]>
  • Loading branch information
benjamreis and psafont committed Feb 21, 2024
1 parent 6cc2339 commit 944e700
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions ocaml/xapi/xapi_pif_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,16 @@ let is_device_underneath_same_type ~__context pif1 pif2 =
get_device_info pif1 = get_device_info pif2

let get_non_link_ipv6 ~__context ~pif =
let non_link_ip6s =
List.map
(fun ip6 ->
match Ipaddr.V6.Prefix.of_string ip6 with
| Error _ ->
None
| Ok ip6 ->
let ip6 = Ipaddr.V6.Prefix.address ip6 in
if Ipaddr.V6.scope ip6 = Ipaddr.Link then
None
else
Some (Ipaddr.V6.to_string ip6)
)
(Db.PIF.get_IPv6 ~__context ~self:pif)
let valid_nonlink ipv6 =
let open Ipaddr.V6 in
ipv6
|> Prefix.of_string
|> Result.to_option
|> Fun.flip Option.bind @@ fun cidr ->
let addr = Prefix.address cidr in
match scope addr with Ipaddr.Link -> None | _ -> Some (to_string addr)
in
List.map (Option.fold ~none:"" ~some:Fun.id) non_link_ip6s
|> List.filter (( <> ) "")
List.filter_map valid_nonlink (Db.PIF.get_IPv6 ~__context ~self:pif)

let get_primary_address ~__context ~pif =
match Db.PIF.get_primary_address_type ~__context ~self:pif with
Expand Down

0 comments on commit 944e700

Please sign in to comment.