feat(xo-server/host): implement smartctl api call
This commit is contained in:
parent
7659d9c0be
commit
eb69234a8e
@ -34,7 +34,7 @@
|
||||
- @xen-orchestra/xapi minor
|
||||
- vhd-lib patch
|
||||
- xo-server-backup-reports patch
|
||||
- xo-server patch
|
||||
- xo-server minor
|
||||
- xo-web patch
|
||||
|
||||
<!--packages-end-->
|
||||
|
@ -456,3 +456,52 @@ setControlDomainMemory.params = {
|
||||
setControlDomainMemory.resolve = {
|
||||
host: ['id', 'host', 'administrate'],
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/**
|
||||
*
|
||||
* @param {{host:HOST}} params
|
||||
* @returns null if plugin is not installed or don't have the method
|
||||
* an object device: status on success
|
||||
*/
|
||||
export function getSmartctlHealth({ host }) {
|
||||
return this.getXapi(host).getSmartctlHealth(host._xapiId)
|
||||
}
|
||||
|
||||
getSmartctlHealth.description = 'get smartctl health status'
|
||||
|
||||
getSmartctlHealth.params = {
|
||||
id: { type: 'string' },
|
||||
}
|
||||
|
||||
getSmartctlHealth.resolve = {
|
||||
host: ['id', 'host', 'view'],
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {{host:HOST}} params
|
||||
* @returns null if plugin is not installed or don't have the method
|
||||
* an object device: full device information on success
|
||||
*/
|
||||
export function getSmartctlInformation({ host, deviceNames }) {
|
||||
return this.getXapi(host).getSmartctlInformation(host._xapiId, deviceNames)
|
||||
}
|
||||
|
||||
getSmartctlInformation.description = 'get smartctl information'
|
||||
|
||||
getSmartctlInformation.params = {
|
||||
id: { type: 'string' },
|
||||
|
||||
deviceNames: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
optional: true,
|
||||
},
|
||||
}
|
||||
|
||||
getSmartctlInformation.resolve = {
|
||||
host: ['id', 'host', 'view'],
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import mixin from '@xen-orchestra/mixin/legacy.js'
|
||||
import ms from 'ms'
|
||||
import noop from 'lodash/noop.js'
|
||||
import once from 'lodash/once.js'
|
||||
import pick from 'lodash/pick.js'
|
||||
import tarStream from 'tar-stream'
|
||||
import uniq from 'lodash/uniq.js'
|
||||
import { asyncMap } from '@xen-orchestra/async-map'
|
||||
@ -1428,4 +1429,34 @@ export default class Xapi extends XapiBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getSmartctlHealth(hostId) {
|
||||
try {
|
||||
return JSON.parse(await this.call('host.call_plugin', this.getObject(hostId).$ref, 'smartctl.py', 'health', {}))
|
||||
} catch (error) {
|
||||
if (error.code === 'XENAPI_MISSING_PLUGIN' || error.code === 'UNKNOWN_XENAPI_PLUGIN_FUNCTION') {
|
||||
return null
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getSmartctlInformation(hostId, deviceNames) {
|
||||
try {
|
||||
const informations = JSON.parse(
|
||||
await this.call('host.call_plugin', this.getObject(hostId).$ref, 'smartctl.py', 'information', {})
|
||||
)
|
||||
if (deviceNames === undefined) {
|
||||
return informations
|
||||
}
|
||||
return pick(informations, deviceNames)
|
||||
} catch (error) {
|
||||
if (error.code === 'XENAPI_MISSING_PLUGIN' || error.code === 'UNKNOWN_XENAPI_PLUGIN_FUNCTION') {
|
||||
return null
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user