fix(xo-server-netbox): fix site property null/undefined cases (#7145)

Introduced by 1d7559ded2
This commit is contained in:
Pierre Donias
2023-10-31 16:16:38 +01:00
committed by GitHub
parent ae0f3b4fe0
commit a3ea70c61c
2 changed files with 7 additions and 1 deletions

View File

@@ -11,6 +11,8 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Netbox] Fix VMs' `site` property being unnecessarily updated on some versions of Netbox (PR [#7145](https://github.com/vatesfr/xen-orchestra/pull/7145))
### Packages to release
> When modifying a package, add it here with its release type.
@@ -27,4 +29,6 @@
<!--packages-start-->
- xo-server-netbox patch
<!--packages-end-->

View File

@@ -402,7 +402,9 @@ class Netbox {
cluster: nbVm.cluster?.id ?? null,
status: nbVm.status?.value ?? null,
platform: nbVm.platform?.id ?? null,
site: nbVm.site?.id,
// If site is not supported by Netbox, its value is undefined
// If site is supported by Netbox but empty, its value is null
site: nbVm.site == null ? nbVm.site : nbVm.site.id,
// Sort them so that they can be compared by diff()
tags: nbVm.tags.map(nbTag => ({ id: nbTag.id })).sort(({ id: id1 }, { id: id2 }) => (id1 < id2 ? -1 : 1)),
})