diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 154c5e87a..bd1a346f8 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -11,6 +11,8 @@ > Users must be able to say: “I had this issue, happy to know it's fixed” +- [VM/network] Fix an issue where multiple IPs would be displayed in the same tag when using old Xen tools. This also fixes Netbox's IP synchronization for the affected VMs. (PR [#5860](https://github.com/vatesfr/xen-orchestra/pull/5860)) + ### Packages to release > Packages will be released in the order they are here, therefore, they should @@ -27,3 +29,5 @@ > - major: if the change breaks compatibility > > In case of conflict, the highest (lowest in previous list) `$version` wins. + +- xo-server patch diff --git a/packages/xo-server/src/xapi-object-to-xo.mjs b/packages/xo-server/src/xapi-object-to-xo.mjs index 8df3f7f64..eba8914da 100644 --- a/packages/xo-server/src/xapi-object-to-xo.mjs +++ b/packages/xo-server/src/xapi-object-to-xo.mjs @@ -326,18 +326,33 @@ const TRANSFORMS = { // Merge old ipv4 protocol with the new protocol // See: https://github.com/xapi-project/xen-api/blob/324bc6ee6664dd915c0bbe57185f1d6243d9ed7e/ocaml/xapi/xapi_guest_agent.ml#L59-L81 + + // Old protocol: when there's more than 1 IP on an interface, the IPs + // are space-delimited in the same `x/ip` field + // See https://github.com/vatesfr/xen-orchestra/issues/5801#issuecomment-854337568 + + // The `x/ip` field may have a `x/ipv4/0` alias + // e.g: + // { + // '1/ip': ' ', + // '1/ipv4/0': ' ', + // } + // See https://xcp-ng.org/forum/topic/4810 const addresses = {} for (const key in networks) { - const [, device] = /^(\d+)\/ip$/.exec(key) ?? [] - if (device !== undefined) { - // Old protocol: when there's more than 1 IP on an interface, the IPs - // are space-delimited in the same field - // See https://github.com/vatesfr/xen-orchestra/issues/5801#issuecomment-854337568 - networks[key].split(' ').forEach((ip, i) => { + const [, device, index] = /^(\d+)\/ip(?:v[46]\/(\d))?$/.exec(key) ?? [] + const ips = networks[key].split(' ') + if (ips.length === 1 && index !== undefined) { + // New protocol or alias + addresses[key] = networks[key] + } else if (index !== '0' && index !== undefined) { + // Should never happen (alias with index >0) + continue + } else { + // Old protocol + ips.forEach((ip, i) => { addresses[`${device}/ipv4/${i}`] = ip }) - } else { - addresses[key] = networks[key] } }