ctdb client python bindings

Andrew Walker awalker at ixsystems.com
Wed Apr 27 17:25:37 UTC 2022


Hey all,

I threw together some quick python bindings for a ctdb client. WIP, but any
feedback would be appreciated (either in-list or direct email to this
address).

I've currently thrown together

https://gitlab.com/samba-team/devel/samba/-/commits/anodos325-ctdb_python_bindings

below are some basic operations
* initializing client
* getting cluster status
* creating a new persistent ctdb file (if that's your thing)
* listing current nodes
* getting pnn0 object and printing its current status

```
>>> import ctdb
>>> cl = ctdb.Client()
>>> cl.status()
{'nodemap': {'node_count': 1, 'deleted_node_count': 0, 'nodes': [{'pnn': 0,
'address': {'type': 'INET', 'address': '192.168.0.92'}, 'flags': [],
'flags_raw': 0, 'partially_online': False, 'this_node': True}]}, 'vnnmap':
{'size': 1, 'generation': 705683446, 'entries': [{'hash': 0, 'lmaster':
0}]}, 'recovery_mode_raw': 0, 'recovery_mode_str': 'NORMAL'}
>>> import os
>>> db = ctdb.Ctdb(cl, "curly.tdb", os.O_CREAT)
>>> db.exists
False
>>> db.attach(ctdb.DB_PERSISTENT)
>>> db.exists
True
>>> db.status()
{'dbid': '0x3c05769c', 'dbid_raw': 1006991004, 'name': 'curly.tdb', 'path':
'/usr/local/samba/var/lib/ctdb/persistent/curly.tdb.0', 'persistent': True,
'replicated': False, 'sticky': False, 'readonly': False, 'flags_raw': 1,
'health': 'OK'}
>>> cl.listnodes()
{'node_count': 1, 'deleted_node_count': 0, 'nodes': [<ctdb.CtdbNode object
at 0x7f013deb95a0>]}
>>> my_node = cl.listnodes()['nodes'][0]
>>> my_node.
my_node.ban(             my_node.disable(         my_node.flags
 my_node.private_address  my_node.unban(
my_node.current_node     my_node.enable(          my_node.pnn
 my_node.rebalance(
>>> my_node.pnn
0
>>> my_node.flags
{'parsed': [], 'raw': 0}
```


More information about the samba-technical mailing list