Skip to content

Commit d65df4d

Browse files
author
Martin Belanger
committed
python bindings: redesign Phase 2 — API surface polish
- Convert connected() and is_registration_supported() to read-only Python properties (connected, registration_supported) - Delete set_symname(); host.hostsymname is already writable via the generated SWIG field descriptor - Rename registration_ctrl() to registration_control() to reflect that the method is a multi-action control interface (register, deregister, update via NVMF_DIM_TAS_*), not a single register operation - Update test-objects.py to match the new API Signed-off-by: Martin Belanger <[email protected]> Assisted-by: Claude Sonnet <[email protected]>
1 parent 84dd0d9 commit d65df4d

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

libnvme/libnvme/nvme.i

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,6 @@ struct libnvme_ns * libnvme_ctrl_next_ns(struct libnvme_ctrl * c, struct libnvme
887887
}
888888

889889

890-
%define SET_SYMNAME_DOCSTRING
891-
"Set or clear the host's symbolic name.
892-
893-
Args:
894-
hostsymname: Symbolic name string, or None to clear it."
895-
%enddef
896890

897891
%pythonappend libnvme_host::libnvme_host(struct libnvme_global_ctx *ctx,
898892
const char *hostnqn,
@@ -938,11 +932,6 @@ Args:
938932
struct libnvme_host* __exit__(PyObject *type, PyObject *value, PyObject *traceback) {
939933
return $self;
940934
}
941-
%feature("autodoc", SET_SYMNAME_DOCSTRING) set_symname;
942-
void set_symname(const char *hostsymname) {
943-
libnvme_host_set_hostsymname($self, hostsymname);
944-
}
945-
946935
PyObject* __str__() {
947936
return PyUnicode_FromFormat("nvme.Host(%s,%s)", STR_OR_NONE($self->hostnqn), STR_OR_NONE($self->hostid));
948937
}
@@ -1161,10 +1150,6 @@ Args:
11611150
return;
11621151
}
11631152
}
1164-
%feature("autodoc", "Return True if this controller is currently connected.") connected;
1165-
bool connected() {
1166-
return libnvme_ctrl_get_name($self) != NULL;
1167-
}
11681153
%feature("autodoc", "Rescan this controller and refresh its namespace list.") rescan;
11691154
void rescan() {
11701155
libnvme_rescan_ctrl($self);
@@ -1190,16 +1175,28 @@ Args:
11901175
connect_err = 2;
11911176
}
11921177

1193-
%feature("autodoc", "Return True if this controller supports explicit host registration.") is_registration_supported;
1194-
bool is_registration_supported() {
1178+
bool _registration_supported() {
11951179
return libnvmf_is_registration_supported($self);
11961180
}
1181+
bool _connected() {
1182+
return libnvme_ctrl_get_name($self) != NULL;
1183+
}
1184+
%pythoncode %{
1185+
@property
1186+
def connected(self):
1187+
"""True if this controller is currently connected."""
1188+
return self._connected()
1189+
@property
1190+
def registration_supported(self):
1191+
"""True if this controller supports explicit host registration."""
1192+
return self._registration_supported()
1193+
%}
11971194

11981195
%feature("autodoc", "Register this controller with the NVMe-oF DIM service.\n"
11991196
"\n"
12001197
"Returns:\n"
1201-
" None on success, or an error string describing the failure.") registration_ctrl;
1202-
PyObject *registration_ctrl(enum nvmf_dim_tas tas) {
1198+
" None on success, or an error string describing the failure.") registration_control;
1199+
PyObject *registration_control(enum nvmf_dim_tas tas) {
12031200
__u32 result;
12041201
int status;
12051202

libnvme/libnvme/tests/test-objects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ def test_creation_with_hostsymname(self):
8282
host = nvme.Host(self.ctx, hostnqn=hostnqn, hostsymname=symname)
8383
self.assertEqual(host.hostsymname, symname)
8484

85-
def test_set_symname(self):
85+
def test_set_hostsymname(self):
8686
hostnqn = 'nqn.2014-08.com.example:test-host-set-symname'
8787
host = nvme.Host(self.ctx, hostnqn=hostnqn)
88-
host.set_symname('updated-symname')
88+
host.hostsymname = 'updated-symname'
8989
self.assertEqual(host.hostsymname, 'updated-symname')
9090

9191
def test_dhchap_host_key_is_none_by_default(self):
@@ -163,7 +163,7 @@ def test_trsvcid_property(self):
163163

164164
def test_connected_returns_false_before_connect(self):
165165
ctrl = self._make_loop_ctrl()
166-
self.assertFalse(ctrl.connected())
166+
self.assertFalse(ctrl.connected)
167167

168168
def test_name_is_none_before_connect(self):
169169
ctrl = self._make_loop_ctrl()
@@ -216,7 +216,7 @@ def test_multiple_ctrls_same_ctx(self):
216216
ctrls = [self._make_loop_ctrl() for _ in range(5)]
217217
self.assertEqual(len(ctrls), 5)
218218
for c in ctrls:
219-
self.assertFalse(c.connected())
219+
self.assertFalse(c.connected)
220220

221221

222222
class TestCtrlErrorHandling(unittest.TestCase):

0 commit comments

Comments
 (0)