summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2011-09-21 22:45:17 -0700
committerRuss Allbery <rra@stanford.edu>2011-09-21 22:45:17 -0700
commit8523f65fef3213e9e2f23dcf89151b654a1a64b7 (patch)
tree1b6187d8be269e14845f15eb452716d554078407 /python
parentc221eaac6dbc285f819c9bc14e9b90607a3061fd (diff)
Add Python bindings for remctl_set_source_ip
Diffstat (limited to 'python')
-rw-r--r--python/README14
-rw-r--r--python/_remctlmodule.c33
-rw-r--r--python/remctl.py.in4
-rw-r--r--python/test_remctl.py.in12
4 files changed, 55 insertions, 8 deletions
diff --git a/python/README b/python/README
index d9afbbe..e3e2e7c 100644
--- a/python/README
+++ b/python/README
@@ -98,6 +98,20 @@ FULL INTERFACE
All further methods below must be called on a Remctl object as returned
by the constructor.
+ Remctl.set_source_ip(source)
+ Sets the source IP for outgoing connections. This method must be
+ called prior to calling open() and will affect all subsequent open()
+ calls on the same object.
+
+ Arguments:
+ * source (required): string, the source IP address
+
+ The source may be either an IPv4 or an IPv6 address (if IPv6 is
+ supported). It must be an IP address, not a host name.
+
+ Exceptions:
+ * RemctlError: a memory allocation failure occurred
+
Remctl.open(host, port, principal)
Open a connection to a remote server and authenticate. There is no
return value; an exception is thrown on any error.
diff --git a/python/_remctlmodule.c b/python/_remctlmodule.c
index e07f6c2..48a662b 100644
--- a/python/_remctlmodule.c
+++ b/python/_remctlmodule.c
@@ -137,6 +137,22 @@ py_remctl_new(PyObject *self, PyObject *args)
static PyObject *
+py_remctl_set_source_ip(PyObject *self, PyObject *args)
+{
+ PyObject *object = NULL;
+ struct remctl *r;
+ char *source = NULL;
+ int status;
+
+ if (!PyArg_ParseTuple(args, "Os", &object, &source))
+ return NULL;
+ r = PyCObject_AsVoidPtr(object);
+ status = remctl_set_source_ip(r, source);
+ return Py_BuildValue("i", status);
+}
+
+
+static PyObject *
py_remctl_open(PyObject *self, PyObject *args)
{
PyObject *object = NULL;
@@ -264,14 +280,15 @@ py_remctl_output(PyObject *self, PyObject *args)
static PyMethodDef methods[] = {
- { "remctl", py_remctl, METH_VARARGS, NULL },
- { "remctl_new", py_remctl_new, METH_VARARGS, NULL },
- { "remctl_open", py_remctl_open, METH_VARARGS, NULL },
- { "remctl_close", py_remctl_close, METH_VARARGS, NULL },
- { "remctl_error", py_remctl_error, METH_VARARGS, NULL },
- { "remctl_commandv", py_remctl_commandv, METH_VARARGS, NULL },
- { "remctl_output", py_remctl_output, METH_VARARGS, NULL },
- { NULL, NULL, 0, NULL },
+ { "remctl", py_remctl, METH_VARARGS, NULL },
+ { "remctl_new", py_remctl_new, METH_VARARGS, NULL },
+ { "remctl_set_source_ip", py_remctl_set_source_ip, METH_VARARGS, NULL },
+ { "remctl_open", py_remctl_open, METH_VARARGS, NULL },
+ { "remctl_close", py_remctl_close, METH_VARARGS, NULL },
+ { "remctl_error", py_remctl_error, METH_VARARGS, NULL },
+ { "remctl_commandv", py_remctl_commandv, METH_VARARGS, NULL },
+ { "remctl_output", py_remctl_output, METH_VARARGS, NULL },
+ { NULL, NULL, 0, NULL },
};
diff --git a/python/remctl.py.in b/python/remctl.py.in
index 0f88d00..5d76405 100644
--- a/python/remctl.py.in
+++ b/python/remctl.py.in
@@ -112,6 +112,10 @@ class Remctl:
if host != None:
self.open(host, port, principal)
+ def set_source_ip(self, source):
+ if not _remctl.remctl_set_source_ip(self.r, source):
+ raise RemctlError, self.error()
+
def open(self, host, port = None, principal = None):
if port == None:
port = 0
diff --git a/python/test_remctl.py.in b/python/test_remctl.py.in
index 09756db..787ce32 100644
--- a/python/test_remctl.py.in
+++ b/python/test_remctl.py.in
@@ -178,6 +178,18 @@ class TestRemctlFull(TestRemctl):
self.assertEqual(error, 5)
@needs_kerberos
+ def test_source_ip(self):
+ r = remctl.Remctl()
+ r.set_source_ip('127.0.0.1')
+ r.open('127.0.0.1', 14373, self.principal)
+ r.set_source_ip('::1')
+ pattern = '(cannot connect to|unknown host) .*'
+ try:
+ r.open('127.0.0.1', 14373, self.principal)
+ except remctl.RemctlError, error:
+ self.assert_(re.compile(pattern).match(str(error)))
+
+ @needs_kerberos
def test_full_errors(self):
r = remctl.Remctl()
try: