Project

General

Profile

Actions

Cleanup #54001

open

type safe Python mon_command API clients

Added by Sebastian Wagner over 2 years ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
-
Target version:
-
% Done:

0%

Tags:
Backport:
Reviewed:
Affected Versions:
Pull request ID:

Description

like for the last 6 years, I always wondered, why we don't have an type
safe way to use the mon command api. Turns out I never had the time to
actually work on it. But my idea looks more or less like so:

https://pad.ceph.com/p/mon_command_python_api

what do you think? Is there any use for something like this?

# mon_command_api.py

class CommandResult(NamedTuple):
    ret: int
    stdout: str
    stderr: str

def Call(NamedTuple):
    api: MonCommandApi
    prefix: str

    def __call__(self, **kwargs):
        kwargs['prefix'] = prefix
        return CommandResult(self.api._mon_command(kwargs))

class MonCommandApi:

    def __init__(self, rados):
        self.rados = rados

    def _mon_command(self, dict):
        return CommandResult(self.rados.mon_command(dict))

    def __get_attr__(self, aname):
        return Call(self, aname.replace('_', ' '))

# mon_command_api.pyi. Autogenerated by a script, exactly like https://docs.ceph.com/en/latest/api/mon_command_api/

class MonCommandApi:

    def __init__(self, rados): None:
        self.rados = rados

    def _mon_command(self, dict) -> CommandResult:
        ...

    def orch_rm_daemon(name: str) -> CommandResult
        ...

    def osd_create_pool(pool: str, pg_num: int, size: int)
        ...

# example use:

def orch_rm_daemon(daemon_name):
    api = MonCommandApi(...)
    return api.orch_rm_daemon(name=daemon_name)

def other_function(daemon_name):
    api = MonCommandApi(...)
    return api.osd_create_pool(pool='my_pool', pg_num=42, size=3)

No data to display

Actions

Also available in: Atom PDF