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
1 change: 1 addition & 0 deletions packages/xo-server-netbox/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const configurationSchema = ({ xo: { apiMethods } }) => ({
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 }
22 changes: 22 additions & 0 deletions packages/xo-server-netbox/src/diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { isEmpty } from 'lodash'

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

// Deeply compares 2 objects and returns an object representing the difference
julien-f marked this conversation as resolved.
Show resolved Hide resolved
// 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.
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]
}
})

return isEmpty(newer) ? undefined : newer
}
Loading