chore(netbox): remove null-indexed entries from keyed-by collections (#7156)

This commit is contained in:
Pierre Donias 2023-11-27 16:26:53 +01:00 committed by GitHub
parent 0f67692be4
commit b0ff2342ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -381,6 +381,7 @@ class Netbox {
await this.#request(`/virtualization/clusters/?type_id=${nbClusterType.id}`),
'custom_fields.uuid'
)
delete allNbClusters.null
const nbClusters = pick(allNbClusters, xoPools)
const clustersToCreate = []
@ -549,7 +550,9 @@ class Netbox {
// Then make them objects to map the Netbox VMs to their XO VMs
// { VM UUID → Netbox VM }
const allNbVms = keyBy(allNbVmsList, 'custom_fields.uuid')
delete allNbVms.null
const nbVms = keyBy(nbVmsList, 'custom_fields.uuid')
delete nbVms.null
// Used for name deduplication
// Start by storing the names of the VMs that have been created manually in
@ -667,6 +670,7 @@ class Netbox {
const nbIfsList = await this.#request(`/virtualization/interfaces/?${clusterFilter}`)
// { ID → Interface }
const nbIfs = keyBy(nbIfsList, 'custom_fields.uuid')
delete nbIfs.null
const ifsToDelete = []
const ifsToUpdate = []
@ -910,7 +914,10 @@ class Netbox {
}
}
Object.assign(nbVms, keyBy(await this.#request('/virtualization/virtual-machines/', 'PATCH', vmsToUpdate2)))
Object.assign(
nbVms,
keyBy(await this.#request('/virtualization/virtual-machines/', 'PATCH', vmsToUpdate2), 'custom_fields.uuid')
)
log.info(`Done synchronizing ${xoPools.length} pools with Netbox`, { pools: xoPools })
}