Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(netbox): don't delete VMs and interfaces that don't have a UUID #7008

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

> Users must be able to say: “Nice enhancement, I'm eager to test it”

- [Netbox] Don't delete VMs that have been created manually in XO-synced cluster [Forum#7639](https://xcp-ng.org/forum/topic/7639) (PR [#7008](https://github.com/vatesfr/xen-orchestra/pull/7008))

### Bug fixes

> Users must be able to say: “I had this issue, happy to know it's fixed”
Expand All @@ -27,4 +29,6 @@

<!--packages-start-->

- xo-server-netbox minor

<!--packages-end-->
14 changes: 6 additions & 8 deletions packages/xo-server-netbox/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,6 @@ class Netbox {
)
const nbClusters = pick(allNbClusters, xoPools)

if (allNbClusters[undefined] !== undefined) {
// Show a warning but never delete clusters automatically
log.warn('Found some clusters with missing UUID custom field', allNbClusters[undefined])
}

const clustersToCreate = []
const clustersToUpdate = []
for (const xoPoolId of xoPools) {
Expand Down Expand Up @@ -418,9 +413,12 @@ class Netbox {
const allNbVms = keyBy(allNbVmsList, 'custom_fields.uuid')
const nbVms = keyBy(nbVmsList, 'custom_fields.uuid')

const usedNames = [] // Used for name deduplication
// Used for name deduplication
// Start by storing the names of the VMs that have been created manually in
// Netbox as we'll need to avoid name conflicts with those too
const usedNames = nbVmsList.filter(nbVm => nbVm.custom_fields.uuid == null).map(nbVm => nbVm.name)
// Build the 3 collections of VMs and perform all the API calls at the end
const vmsToDelete = nbVmsList.filter(nbVm => nbVm.custom_fields.uuid == null).map(nbVm => ({ id: nbVm.id }))
const vmsToDelete = []
const vmsToUpdate = []
const vmsToCreate = []
for (const xoPoolId of xoPools) {
Expand Down Expand Up @@ -532,7 +530,7 @@ class Netbox {
// { ID → Interface }
const nbIfs = keyBy(nbIfsList, 'custom_fields.uuid')

const ifsToDelete = nbIfsList.filter(nbIf => nbIf.custom_fields.uuid == null).map(nbIf => ({ id: nbIf.id }))
const ifsToDelete = []
const ifsToUpdate = []
const ifsToCreate = []
for (const nbVm of Object.values(nbVms)) {
Expand Down