-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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 <[email protected]>
- Loading branch information
Showing
2 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/usr/bin/python3 | ||
"""XAPI plugin to manage Kalray DPU.""" | ||
|
||
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: | ||
"""Describe a command to be ran on the Kalray DPU.""" | ||
|
||
def __init__(self, rpc_name: str, updates: dict): | ||
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 | ||
if self.username is None: | ||
raise XenAPIPlugin.Failure("-1", ["'username' is required"]) | ||
if self.password is None: | ||
raise XenAPIPlugin.Failure("-1", ["'password' is required"]) | ||
|
||
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.""" | ||
try: | ||
client = rpc.client.HTTPJSONRPCClient( | ||
self.server, | ||
self.port, | ||
self.timeout, | ||
self.username, | ||
self.password, | ||
log_level="ERROR") | ||
message = client.call(self.rpc_name, self.rpc_params) | ||
except rpc.client.JSONRPCException as exc: | ||
raise XenAPIPlugin.Failure("-1", [exc.message]) | ||
|
||
return json.dumps(message) | ||
|
||
@error_wrapped | ||
def get_devices(_session, args): | ||
"""Get the list of devices available on the Kalray DPU.""" | ||
kc = KalrayCmd('bdev_get_bdevs', args) | ||
return kc.call_rpc() | ||
|
||
@error_wrapped | ||
def create_raid(_session, args): | ||
"""Create a raid.""" | ||
kc = KalrayCmd('bdev_raid_create', args) | ||
kc.add_rpc_params('name', 'raid0') | ||
kc.add_rpc_params('raid_level', 'raid0') | ||
kc.add_rpc_params('strip_size_kb', 128) | ||
kc.add_rpc_params('persist', True) | ||
kc.add_rpc_params('split_dp', True) | ||
kc.add_rpc_params('base_bdevs', | ||
["HotInNvmeWDS500AFY0-22050C800415n1", | ||
"HotInNvmeWDS500AFY0-22050C800378n1"]) | ||
return 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 kc.call_rpc() | ||
|
||
@error_wrapped | ||
def create_lvs(_session, args): | ||
"""Create a logical volume store.""" | ||
kc = KalrayCmd('bdev_lvol_create_lvstore', args) | ||
kc.add_rpc_params('bdev_name', 'raid0') | ||
kc.add_rpc_params('lvs_name', 'lvs') | ||
return 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 kc.call_rpc() | ||
|
||
@error_wrapped | ||
def create_lvol(_session, args): | ||
"""Create a new lvol on the Kalray DPU.""" | ||
kc = KalrayCmd('bdev_lvol_create', args) | ||
kc.add_rpc_params('lvol_name', 'volume_09') | ||
kc.add_rpc_params('size', 1048576000) | ||
kc.add_rpc_params('lvs_name', 'lvs') | ||
return kc.call_rpc() | ||
|
||
@error_wrapped | ||
def delete_lvol(_session, args): | ||
"""Delete the lvol passed as parameter on the Kalray DPU if exists.""" | ||
try: | ||
lvol_name = args["name"] | ||
raise XenAPIPlugin.Failure("-1", [f"Deletion of lvol {lvol_name} is not yet implemented"]) | ||
except KeyError as exc: | ||
raise XenAPIPlugin.Failure("-1", ["No argument found with key 'name'."]) from exc | ||
|
||
if __name__ == "__main__": | ||
XenAPIPlugin.dispatch({ | ||
"get_devices": get_devices, | ||
"create_raid": create_raid, | ||
"get_raids": get_raids, | ||
"create_lvs": create_lvs, | ||
"get_lvs": get_lvs, | ||
"create_lvol": create_lvol, | ||
"delete_lvol": delete_lvol, | ||
}) |