Skip to content

Commit

Permalink
feat(netbox): check Netbox version down to minor + allow to bypass check
Browse files Browse the repository at this point in the history
  • Loading branch information
pdonias committed Sep 16, 2024
1 parent 04f3a09 commit ae34055
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 12 additions & 1 deletion docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,18 @@ Synchronize your pools, VMs, network interfaces and IP addresses with your [Netb

- `>= 2.10`
- `3.x`
- `4.x`
- `4.0`

:::tip
For safety, XO will not synchronize your pools if it detects a Netbox version that is not supported. If you wish to change that behavior, edit you `xo-server` configuration like so:

```toml
[netbox]
checkNetboxVersion = false
```

Please be aware that by doing this, a Netbox update might make XO delete some of your data in Netbox.
:::

### Netbox side

Expand Down
8 changes: 6 additions & 2 deletions packages/xo-server-netbox/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import slugify from './slugify'

const log = createLogger('xo:netbox')

const SUPPORTED_VERSION = '>=2.10 <5.0'
const SUPPORTED_VERSION = '>=2.10 <4.1'
const CLUSTER_TYPE = 'XCP-ng Pool'
const TYPES_WITH_UUID = ['virtualization.cluster', 'virtualization.virtualmachine', 'virtualization.vminterface']
const CHUNK_SIZE = 100
Expand Down Expand Up @@ -235,10 +235,14 @@ class Netbox {
}

async #checkNetboxVersion() {
if (!this.#xo.config.getOptional('netbox.checkNetboxVersion')) {
return
}

await this.#fetchNetboxVersion()
if (this.#netboxVersion === undefined || !semver.satisfies(this.#netboxVersion, SUPPORTED_VERSION)) {
throw new Error(
`Netbox version ${this.#netboxVersion ?? '<2.10'} not supported. Please check https://xen-orchestra.com/docs/advanced.html#netbox`
`Netbox version ${this.#netboxVersion ?? '<2.10'} not supported. Please check https://xen-orchestra.com/docs/advanced.html#supported-versions`
)
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/xo-server/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ level = 'info'

[logs.transport.console]

[netbox]
checkNetboxVersion = true

[plugins]
lookupPaths = ['./node_modules', '../', '/usr/local/lib/node_modules']

Expand Down

0 comments on commit ae34055

Please sign in to comment.