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(xo-server-netbox): rewrite #6950

Merged
merged 13 commits into from Jul 27, 2023
8 changes: 8 additions & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -8,6 +8,13 @@
> Users must be able to say: “Nice enhancement, I'm eager to test it”

- [Backup/Restore] Button to open the raw log in the REST API (PR [#6936](https://github.com/vatesfr/xen-orchestra/pull/6936))
- [Netbox] New major version. BREAKING: in order for this new version to work, you need to assign the type `virtualization > vminterface` to the custom field `UUID` in your Netbox instance. [See documentation](https://xen-orchestra.com/docs/advanced.html#netbox). [#6038](https://github.com/vatesfr/xen-orchestra/issues/6038) [#6135](https://github.com/vatesfr/xen-orchestra/issues/6135) [#6024](https://github.com/vatesfr/xen-orchestra/issues/6024) [#6036](https://github.com/vatesfr/xen-orchestra/issues/6036) [Forum#6070](https://xcp-ng.org/forum/topic/6070) [Forum#6149](https://xcp-ng.org/forum/topic/6149) [Forum#6332](https://xcp-ng.org/forum/topic/6332) (PR [#6950](https://github.com/vatesfr/xen-orchestra/pull/6950))
- Synchronize VM description
- Fix duplicated VMs in Netbox after disconnecting one pool
- Migrating a VM from one pool to another keeps VM data added manually
- Fix largest IP prefix being picked instead of smallest
- Fix synchronization not working if some pools are unavailable
- Better error messages

### Bug fixes

Expand Down Expand Up @@ -48,6 +55,7 @@
- xo-server patch
- xo-server-transport-xmpp patch
- xo-server-audit patch
- xo-server-netbox major
- xo-web minor

<!--packages-end-->
2 changes: 1 addition & 1 deletion docs/advanced.md
Expand Up @@ -354,7 +354,7 @@ XO will try to find the right prefix for each IP address. If it can't find a pre
- Add a UUID custom field:
- Go to Other > Custom fields > Add
- Create a custom field called "uuid" (lower case!)
- Assign it to object types `virtualization > cluster` and `virtualization > virtual machine`
- Assign it to object types `virtualization > cluster`, `virtualization > virtual machine` and `virtualization > vminterface`

![](./assets/customfield.png)

Expand Down
1 change: 1 addition & 0 deletions packages/xo-server-netbox/package.json
Expand Up @@ -37,6 +37,7 @@
"devDependencies": {
"@babel/cli": "^7.13.16",
"@babel/core": "^7.14.0",
"@babel/plugin-proposal-export-default-from": "^7.18.10",
"@babel/preset-env": "^7.14.1",
"cross-env": "^7.0.3"
},
Expand Down
39 changes: 39 additions & 0 deletions packages/xo-server-netbox/src/configuration-schema.js
@@ -0,0 +1,39 @@
const configurationSchema = {
description:
'Synchronize pools managed by Xen Orchestra with Netbox. Configuration steps: https://xen-orchestra.com/docs/advanced.html#netbox.',
type: 'object',
properties: {
endpoint: {
type: 'string',
title: 'Endpoint',
description: 'Netbox URI',
},
allowUnauthorized: {
type: 'boolean',
title: 'Unauthorized certificates',
description: 'Enable this if your Netbox instance uses a self-signed SSL certificate',
},
token: {
type: 'string',
title: 'Token',
description: 'Generate a token with write permissions from your Netbox interface',
},
pools: {
type: 'array',
title: 'Pools',
description: 'Pools to synchronize with Netbox',
items: {
type: 'string',
$type: 'pool',
},
},
syncInterval: {
type: 'number',
title: 'Interval',
description: 'Synchronization interval in hours - leave empty to disable auto-sync',
},
},
required: ['endpoint', 'token', 'pools'],
}

export { configurationSchema as default }
31 changes: 31 additions & 0 deletions packages/xo-server-netbox/src/diff.js
@@ -0,0 +1,31 @@
import isEmpty from 'lodash/isEmpty'

import { compareNames } from './name-dedup'

/**
* Deeply compares 2 objects and returns an object representing the difference
* between the 2 objects. Returns undefined if the 2 objects are equal.
* In Netbox context: properly ignores differences found in names that could be
* due to name deduplication. e.g.: "foo" and "foo (2)" are considered equal.
* @param {any} newer
* @param {any} older
* @returns {Object|undefined} The patch that needs to be applied to older to get newer
*/
export default function diff(newer, older) {
if (typeof newer !== 'object') {
return newer === older ? undefined : newer
}

newer = { ...newer }
Object.keys(newer).forEach(key => {
if ((key === 'name' && compareNames(newer[key], older[key])) || diff(newer[key], older?.[key]) === undefined) {
delete newer[key]
}
})

if (isEmpty(newer)) {
return
}

return { ...newer, id: older.id }
}