feat(xo-server-ipmi-sensors) : Created the plugin#9724
Conversation
07394cb to
22e797a
Compare
| const callIpmiPlugin = async function <T>(fn: string): Promise<T> { | ||
| return await xApiHost.$call<T>('call_plugin', 'ipmitool.py', fn, {}) | ||
| } |
There was a problem hiding this comment.
This is some complicated code to be able call ipmi plugin functions, I understand this is the existing solution but since there are not a lot of functions I think it would be better to either call them directly without this intermediary function:
await (xApiHost.$call('call_plugin', 'ipmitool.py`, 'is_ipmi_device_available, {})) as string
0r externalize them in a separate ipmi-tool.mts file:
function isIpmiDeviceAvailable(): Promise<string>{
return xApiHost.$call('call_plugin', 'ipmitool.py`, 'is_ipmi_device_available, {})
}
Maybe this is outside of the card scope.
There was a problem hiding this comment.
I'd think that the best would be an external util across all XO rather than a file specific one, agree with the idea though i'd say out of scope
There was a problem hiding this comment.
Fair enough, I just want to get the opinion of Florent before resolving.
There was a problem hiding this comment.
this would also need arguments , for example in another part of the codebase
const result = await this.call('host.call_plugin', this.pool.master, 'trim', 'do_trim', {
sr_uuid: await this.getField('SR', srRef, 'uuid'),
})
```
it will be tricky to type though, since we can be connected to multiple host/pools, and they can have different versions of the plugin
There was a problem hiding this comment.
I guess that's an issue for another day then, and might not be worth it since it's not used a lot across the codebase
105774b to
17e496d
Compare
|
Do a MAJ+CTRL+F search for "IMPI", there are still some not fixed. |
|
I think you are also missing some function return types. |
| * Load and start the plugin. | ||
| */ | ||
| async load(): Promise<void> { | ||
| this.#removeApiMethod = (this.#xo as any).addApiMethod( |
There was a problem hiding this comment.
Why as any?
this.#xo type is correct
| } | ||
|
|
||
| addIpmiSensorDataType(ipmiSensor, productName, this.#configuredRulesByProduct) | ||
| const dataType = ipmiSensor.dataType as IMPI_SENSOR_DATA_TYPE_STRINGS |
There was a problem hiding this comment.
Avoid to use as as much as possible.
Here, addIpmiSensorDataType always injects the dataType property into your ipmiSensor object.
You can type addIpmiSensorDataType correctly to reflect what the function does.
export const addIpmiSensorDataType: (
data: ReturnedSensorData,
productName: string,
configuredRules: SensorRegexByProduct[]
) => asserts data is ReturnedSensorData & { dataType: IMPI_SENSOR_DATA_TYPE_STRINGS } = (
data,
productName,
configuredRules
) => {. .. }Or using function instead anonymous function
export function addIpmiSensorDataType(
data: ReturnedSensorData,
productName: string,
configuredRules: SensorRegexByProduct[]
): asserts data is ReturnedSensorData & { dataType: IMPI_SENSOR_DATA_TYPE_STRINGS } {...}so, when you do addIpmiSensorDataType(foo, ...)
then foo.dataType will no longer be considered undefined
| }, | ||
| } | ||
|
|
||
| export const addCustomIpmiSensors = (ipmiSensorsByDataType: any, productName: string) => { |
There was a problem hiding this comment.
No any.
At least unknown if you can't type it. (or any but with a comment explaining why)
But based on the parameter name, I think it's possible to type it.
0e719b4 to
4f063fc
Compare
4f063fc to
1feb8b6
Compare
| - [i18n] Update Chinese (Simplified Han script), Czech, Danish, Dutch, Finnish, German, Italian, Korean, Norwegian, Persian, Polish, Portuguese, Portuguese (Brasil), Russian, Slovak and Spanish translations (PR [#9649](https://github.com/vatesfr/xen-orchestra/pull/9649)) | ||
| - [OpenMetrics] Add 9 missing host RRD metrics: `hostload`, `memory_reclaimed`, `memory_reclaimed_max`, `running_vcpus`, `pif_aggr_rx`, `pif_aggr_tx`, `iops_total`, `io_throughput_total`, `latency` per SR (PR [#9696](https://github.com/vatesfr/xen-orchestra/pull/9696)) | ||
| - [Netbox] Use platform hierarchy to assign versioned OS names (e.g. "Debian 12" instead of "Debian") when the major version is known (requires Netbox >= 4.4) #7773 (PR [#9644](https://github.com/vatesfr/xen-orchestra/pull/9644)) | ||
| - [IPMI] Add a plugin for configuration of ipmi rules and vendors [#9724] (https://github.com/vatesfr/xen-orchestra/pull/9724) |
There was a problem hiding this comment.
| - [IPMI] Add a plugin for configuration of ipmi rules and vendors [#9724] (https://github.com/vatesfr/xen-orchestra/pull/9724) | |
| - [IPMI] Add a plugin for configuration of ipmi rules and vendors ( PR [#9724] (https://github.com/vatesfr/xen-orchestra/pull/9724)) |
fbeauchamp
left a comment
There was a problem hiding this comment.
nice work, that's a very good first PR. Additionnally to my comments, there is a unknown at the bottom of the fields list. I don't understand what is its goal ?
| result[key] = propSchema.default | ||
| hasDefaults = true | ||
| } else if (propSchema.type === 'object') { | ||
| const nested = getSchemaDefaults(propSchema) |
There was a problem hiding this comment.
I think we need this
| const nested = getSchemaDefaults(propSchema) | |
| const nested = this.getSchemaDefaults(propSchema) |
| this.getIpmiSensors.bind(this) | ||
| ), | ||
| // replacement for the method in packages/xo-server/src/api/host.mjs | ||
| this.#xo.addApiMethod<[{ id: XoHost | Branded<'host'> }], FinalSensorData>( |
There was a problem hiding this comment.
the original method had a permission check and a resolve property
this is important to keep them
| const match = str.match(/^\/(.+)\/([a-z]*)$/i) | ||
| if (!match) return undefined | ||
| const [, pattern, flags] = match | ||
| if (pattern === undefined) return undefined |
There was a problem hiding this comment.
I think a failed regexp compilation shouldn't fail silently. Since it will make the plugin unusable, I am ok with throwing an error here
| const customSensorsByDataType = IPMI_SENSOR_CUSTOM_BY_DATA_TYPE_BY_SUPPORTED_PRODUCT_NAME[productName] | ||
| for (const dataType in customSensorsByDataType) { | ||
| const dataTypeKey = dataType as IMPI_SENSOR_DATA_TYPE_STRINGS | ||
| const fn = customSensorsByDataType[dataTypeKey]!! // we know this exists since we're iterating over the keys of customSensorsByDataType |
There was a problem hiding this comment.
I think we only need on !
| const fn = customSensorsByDataType[dataTypeKey]!! // we know this exists since we're iterating over the keys of customSensorsByDataType | |
| const fn = customSensorsByDataType[dataTypeKey]! // we know this exists since we're iterating over the keys of customSensorsByDataType |
| if (systemManufacturer.includes('dell')) productName = 'dell' | ||
| if (systemManufacturer.includes('lenovo')) productName = 'lenovo' | ||
|
|
||
| const data = this.#configuredRulesByProduct || [] |
There was a problem hiding this comment.
I don't think #configuredRulesByProduct can be undefined, since it's instantiated in the constructor and not accessible by exterior code
| const data = this.#configuredRulesByProduct || [] | |
| const data = this.#configuredRulesByProduct |
| getIpmiSensors.resolve = { | ||
| host: ['id', 'host', 'administrate'], | ||
| } | ||
| // host.getApiMethod moved to packages/xo-server-ipmi-sensors/src/index.mts |
There was a problem hiding this comment.
| // host.getApiMethod moved to packages/xo-server-ipmi-sensors/src/index.mts | |
| // host.getIpmiSensors moved to packages/xo-server-ipmi-sensors/src/index.mts |
| // ============================================================================ | ||
|
|
||
| class IpmiSensorsPlugin { | ||
| #configuration: PluginConfiguration | undefined |
There was a problem hiding this comment.
this looks unused, is it intended ?
There was a problem hiding this comment.
I wasnt sure if configuration is a required parameter or not, i thought it was automatically set by the framework
Description
Move ipmi sensor discovery to it's own plugin and removed old logic, ships with a default configuration with the same behaviour as the old system.
The plugin can be configured via the UI, accepts an exact match for the vendor and regexes for the ipmi matching.
Tested via unit tests.
Tested with R620-L1 host on xo-lab by adding and removing Dell from configured vendors
Screenshots
Checklist
Fixes #007,See xoa-support#42,See https://...)Introduced byCHANGELOG.unreleased.mdReview process
If you are an external contributor, you can skip this part. Simply create the pull request, and we'll get back to you as soon as possible.
Notes: