From 79b0d6d0fbba9e483d7150e95f71b3a52a661f48 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 11 Sep 2023 15:02:00 +0200 Subject: [PATCH] Add kalray plugin to configure DPU - Work is in progress and not ready for reviewing... - Just add three functions to check that we can do the RPC - Need to add creation of lvols Signed-off-by: Guillaume --- README.md | 50 ++++++++++++ SOURCES/etc/xapi.d/plugins/kalray_dpu.py | 96 ++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100755 SOURCES/etc/xapi.d/plugins/kalray_dpu.py diff --git a/README.md b/README.md index a8e8385..cd4c288 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,56 @@ $ xe host-call-plugin host-uuid= plugin=zfs.py fn=list_zfs_pools ``` (the most pertinent parameter is `mountpoint`) +## XCP-ng Kalray DPU + +A xapi plugin to get information about raids, logical volume store (LVS) and +devices that are present on the Kalray DPU. It also allow the management of +logical volumes (LV): creation and deletion. Parameters depends of the name of +the command some are always available: + - *username*: username to use to connect to DPU (required) + - *password*: password to connect to DPU (required) + - *server*: IP of the server for configuring the DPU (default: localhost) + - *port*: Port to use (default: 8080) + - *timeout*: timeout in second (default: 60.0) + +## Command details + +### Get the list of raids on the Kalray DPU +``` +$ xe host-call-plugin host-uuid= plugin=kalray_dpu.py fn=get_raids \ + args:username= args:password= +{"status": "ok", "output": [{"name": "HotInNvmeWDS500AFY0-22050C800415n1", "aliases": [], "product_name": "NVMe disk", "block_size": 512, "num_blocks": 976773168, "uuid": "e8238fa6-bf53-0001-001b-448b45afa6a7", "assigned_rate_limits": {"rw_ios_per_sec": 0, "rw_mbytes_per_sec": 0, "r_mbytes_per_sec": 0, "w_mbytes_per_sec": 0}, "claimed": false, "zoned": false, "supported_io_types": {"read": true, "write": true, "unmap": true, "write_zeroes": true, "flush": true, "reset": true, "nvme_admin": true, "nvme_io": true}, "driver_specific": {"nvme": [{"pci_address": "0000:00:00.0", "trid": {"trtype": "PCIe", "traddr": "0000:00:00.0"}, "ctrlr_data": {"cntlid": 8224, "vendor_id": "0x15b7", "model_number": "WDS500G1X0E-00AFY0", "serial_number": "22050C800415", "firmware_revision": "614900WD", "subnqn": "nqn.2018-01.com.wdc:nguid:E8238FA6BF53-0001-001B448B45AFA6A7", "oacs": {"security": 1, "format": 1, "firmware": 1, "ns_manage": 0}, "multi_ctrlr": false, "ana_reporting": false}, "vs": {"nvme_version": "1.4"}, "ns_data": {"id": 1, "can_share": false}, "security": {"opal": false}}], "mp_policy": "active_passive"}}]} + +``` + +### Get the list of LVS on the Kalray DPU +``` +$ xe host-call-plugin host-uuid= plugin=kalray_dpu.py fn=get_lvs \ + args:username= args:password= +[...] +``` + +### Get the list of devices on the Kalray DPU +``` +$ xe host-call-plugin host-uuid= plugin=kalray_dpu.py fn=get_devices \ + args:username= args:password= +[...] +``` + +### Create a new logical volume +``` +$ xe host-call-plugin host-uuid= plugin=kalray_dpu.py fn=create_lvol \ + args:username= args:password= +[...] +``` +### Delete a logical volume +``` +$ xe host-call-plugin host-uuid= plugin=kalray_dpu.py fn=delete_lvol \ + args:username= args:password= \ + args:name= +[...] +``` + ## XCP-ng LVM A xapi plugin to list, create and destroy PVs, VGs and LVMs on a host. diff --git a/SOURCES/etc/xapi.d/plugins/kalray_dpu.py b/SOURCES/etc/xapi.d/plugins/kalray_dpu.py new file mode 100755 index 0000000..9bbf9d7 --- /dev/null +++ b/SOURCES/etc/xapi.d/plugins/kalray_dpu.py @@ -0,0 +1,96 @@ +#!/usr/bin/python3 +""" +This module implements a xapi plugin to get information from Kalray DPU and it +allows its management. +""" + +import json +import XenAPIPlugin # pylint: disable=import-error + +from kalray.acs.spdk import rpc # pylint: disable=import-error +from xcpngutils import error_wrapped + +class KalrayCmd: + """This class allows to run a command on the Kalray DPU. + A command is an RPC. + """ + def __init__(self, rpc_name, updates): + self.server = 'localhost' + self.port = 8080 + self.username = None + self.password = None + self.timeout = 60.0 + self.rpc_name = rpc_name + self.rpc_params = {} + + for k,v in updates.items(): + if hasattr(self, k): + setattr(self, k, v) + + # Check that username & password are well set + assert self.username is not None + assert self.password is not None + + def add_rpc_params(self, key, value): + """Adds a parameter that will be passed to the RPC""" + self.rpc_params[key] = value + + def call_rpc(self): + """Do the RPC call""" + client = rpc.client.HTTPJSONRPCClient( + self.server, + self.port, + self.timeout, + self.username, + self.password, + log_level="ERROR") + return client.call(self.rpc_name, self.rpc_params) + +def to_json(status, string): + """Return the status and the string as a json string""" + return json.dumps({ + 'status': status, + 'output': string, + }) + +@error_wrapped +def get_devices(_session, args): + """Get the list of devices available on the Kalray DPU""" + kc = KalrayCmd('bdev_get_bdevs', args) + return to_json('ok', kc.call_rpc()) + +@error_wrapped +def get_raids(_session, args): + """Get the list of raids available on the Kalray DPU""" + kc = KalrayCmd('bdev_raid_get_bdevs', args) + kc.add_rpc_params('category', 'all') + return to_json('ok', kc.call_rpc()) + +@error_wrapped +def get_lvs(_session, args): + """Get the list of logical volume stores available on the Kalray DPU""" + kc = KalrayCmd('bdev_lvol_get_lvstores', args) + return to_json('ok', kc.call_rpc()) + +@error_wrapped +def create_lvol(_session, _args): + """Create a new lvol on the Kalray DPU""" + return to_json('failed', "Creation of lvol is not yet implemented") + +@error_wrapped +def delete_lvol(_session, args): + """Delete the lvol passed as parameter on the Kalray DPU if exists""" + try: + lvol_name = args["name"] + return to_json('failed', f"Deletion of lvol {lvol_name} is not yet implemented") + except KeyError as exc: + raise RuntimeError("No argument found with key 'name'.") from exc + +if __name__ == "__main__": + XenAPIPlugin.dispatch({ + "get_devices": get_devices, + "get_raids": get_raids, + "get_lvs": get_lvs, + "create_lvol": create_lvol, + "delete_lvol": delete_lvol, + })