fix(xo-server-netbox): support older versions of Netbox (#5946)
Fixes #5898 See https://netbox.readthedocs.io/en/stable/release-notes/version-2.7/#api-choice-fields-now-use-string-values-3569
This commit is contained in:
parent
9c83e70a28
commit
d19a748f0c
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
> Users must be able to say: “I had this issue, happy to know it's fixed”
|
> Users must be able to say: “I had this issue, happy to know it's fixed”
|
||||||
|
|
||||||
|
- [Netbox] Support older versions of Netbox and prevent "active is not a valid choice" error [#5898](https://github.com/vatesfr/xen-orchestra/issues/5898) (PR [#5946](https://github.com/vatesfr/xen-orchestra/pull/5946))
|
||||||
|
|
||||||
### Packages to release
|
### Packages to release
|
||||||
|
|
||||||
> Packages will be released in the order they are here, therefore, they should
|
> Packages will be released in the order they are here, therefore, they should
|
||||||
@ -30,6 +32,7 @@
|
|||||||
>
|
>
|
||||||
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
||||||
|
|
||||||
|
- xo-server-netbox patch
|
||||||
- @xen-orchestra/backups minor
|
- @xen-orchestra/backups minor
|
||||||
- @xen-orchestra/proxy minor
|
- @xen-orchestra/proxy minor
|
||||||
- xo-server patch
|
- xo-server patch
|
||||||
|
@ -31,7 +31,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xen-orchestra/log": "^0.3.0",
|
"@xen-orchestra/log": "^0.3.0",
|
||||||
"ipaddr.js": "^2.0.1",
|
"ipaddr.js": "^2.0.1",
|
||||||
"lodash": "^4.17.21"
|
"lodash": "^4.17.21",
|
||||||
|
"semver": "^7.3.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.13.16",
|
"@babel/cli": "^7.13.16",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import ipaddr from 'ipaddr.js'
|
import ipaddr from 'ipaddr.js'
|
||||||
|
import semver from 'semver'
|
||||||
import { createLogger } from '@xen-orchestra/log'
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
import { find, flatten, forEach, groupBy, isEmpty, keyBy, mapValues, omit, trimEnd, zipObject } from 'lodash'
|
import { find, flatten, forEach, groupBy, isEmpty, keyBy, mapValues, omit, trimEnd, zipObject } from 'lodash'
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ class Netbox {
|
|||||||
#endpoint
|
#endpoint
|
||||||
#intervalToken
|
#intervalToken
|
||||||
#loaded
|
#loaded
|
||||||
|
#netboxApiVersion
|
||||||
#pools
|
#pools
|
||||||
#removeApiMethods
|
#removeApiMethods
|
||||||
#syncInterval
|
#syncInterval
|
||||||
@ -113,6 +115,7 @@ class Netbox {
|
|||||||
const httpRequest = async () => {
|
const httpRequest = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await this.#xo.httpRequest(url, options)
|
const response = await this.#xo.httpRequest(url, options)
|
||||||
|
this.#netboxApiVersion = response.headers['api-version']
|
||||||
const body = await response.readAll()
|
const body = await response.readAll()
|
||||||
if (body.length > 0) {
|
if (body.length > 0) {
|
||||||
return JSON.parse(body)
|
return JSON.parse(body)
|
||||||
@ -332,10 +335,18 @@ class Netbox {
|
|||||||
vcpus: vm.CPUs.number,
|
vcpus: vm.CPUs.number,
|
||||||
disk,
|
disk,
|
||||||
memory: Math.floor(vm.memory.dynamic[1] / M),
|
memory: Math.floor(vm.memory.dynamic[1] / M),
|
||||||
status: vm.power_state === 'Running' ? 'active' : 'offline',
|
|
||||||
custom_fields: { uuid: vm.uuid },
|
custom_fields: { uuid: vm.uuid },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.#netboxApiVersion !== undefined) {
|
||||||
|
// https://netbox.readthedocs.io/en/stable/release-notes/version-2.7/#api-choice-fields-now-use-string-values-3569
|
||||||
|
if (semver.satisfies(semver.coerce(this.#netboxApiVersion).version, '>=2.7.0')) {
|
||||||
|
updatedVm.status = vm.power_state === 'Running' ? 'active' : 'offline'
|
||||||
|
} else {
|
||||||
|
updatedVm.status = vm.power_state === 'Running' ? 1 : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (oldNetboxVm === undefined) {
|
if (oldNetboxVm === undefined) {
|
||||||
vmsToCreate.push(updatedVm)
|
vmsToCreate.push(updatedVm)
|
||||||
} else {
|
} else {
|
||||||
|
@ -14667,7 +14667,7 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semve
|
|||||||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
|
||||||
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
|
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
|
||||||
|
|
||||||
semver@^7.2.1, semver@^7.3.2, semver@^7.3.4:
|
semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
|
||||||
version "7.3.5"
|
version "7.3.5"
|
||||||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
|
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
|
||||||
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
|
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
|
||||||
|
Loading…
Reference in New Issue
Block a user