-
Notifications
You must be signed in to change notification settings - Fork 909
/
app_python3_admin.xml
292 lines (276 loc) · 8.2 KB
/
app_python3_admin.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
%docentities;
]>
<!-- Module User's Guide -->
<chapter>
<title>&adminguide;</title>
<section>
<title>Overview</title>
<para>
This module is a port of the 'app_python' module to Python 3.
It is based on the work of Maxim Sobolev.
</para>
<para>
<emphasis>This module cannot be loaded together with 'app_python'</emphasis> as global symbols
have not been renamed. To ease transition, the functions, KEMI exports, and
RPC commands have the same names as 'app_python', which also means the two modules cannot coexist.
</para>
<para>
This module allows executing Python scripts from the config file,
exporting functions to access the SIP message from Python.
</para>
<para>
For some basic examples of Python scripts that can be used with
this module, look at the files inside the source tree located at
'modules/app_python3/python_examples/'.
</para>
<para>
Note: if symbols exported to KEMI (module or function names) conflict
with Python's reserved keywords, use the 'getattr()' function or the
'__dict__' attribute for 'KSR' (e.g., 'KSR.__dict__["async"].task_route("myroute")').
</para>
</section>
<section>
<title>Dependencies</title>
<section>
<title>&kamailio; Modules</title>
<para>
The following modules must be loaded before this module:
<itemizedlist>
<listitem>
<para>
<emphasis>none</emphasis>.
</para>
</listitem>
</itemizedlist>
</para>
</section>
<section>
<title>External Libraries or Applications</title>
<para>
The following libraries or applications must be installed before running
&kamailio; with this module loaded:
<itemizedlist>
<listitem>
<para>
<emphasis>python3</emphasis> - Python 3 runtime.
</para>
</listitem>
</itemizedlist>
</para>
<para>
To compile this module the Python 3 development package is needed.
Requirements:
<itemizedlist>
<listitem>
<para>
<emphasis>python3-dev</emphasis> - Python 3 development package.
</para>
</listitem>
<listitem>
<para>
<emphasis>python3-config</emphasis> - (part of python3-dev)
tool to output C includes and library paths.
</para>
</listitem>
</itemizedlist>
</para>
</section>
</section>
<section>
<title>Parameters</title>
<section id="app_python3.p.load">
<title><varname>load</varname> (string)</title>
<para>
The path to the file with Python code to be executed
from configuration file.
</para>
<para>
<emphasis>
Default value is <quote>/usr/local/etc/kamailio/handler.py</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>load</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("app_python3", "load", "/usr/local/etc/kamailio/myscript.py")
...
</programlisting>
</example>
</section>
<section id="app_python3.p.script_name">
<title><varname>script_name</varname> (string)</title>
<para>
This is same as "load" parameter, kept for backward compatibility
with the older versions of the module.
</para>
</section>
<section id="app_python3.p.mod_init_function">
<title><varname>mod_init_function</varname> (string)</title>
<para>
The Python function to be executed by this module when
it is initialized by &kamailio;.
</para>
<para>
<emphasis>
Default value is <quote>mod_init</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>mod_init_function</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("app_python3", "mod_init_function", "my_mod_init")
...
</programlisting>
</example>
</section>
<section id="app_python3.p.child_init_method">
<title><varname>child_init_method</varname> (string)</title>
<para>
The Python function to be executed by this module when
a new worker process (child) is initialized by &kamailio;.
</para>
<para>
<emphasis>
Default value is <quote>child_init</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>child_init_method</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("app_python3", "child_init_method", "my_child_init")
...
</programlisting>
</example>
</section>
</section>
<section>
<title>Functions</title>
<section id="app_python3.f.python_exec">
<title>
<function moreinfo="none">python_exec(method [, args])</function>
</title>
<para>
Execute the Python function with the name given by the parameter 'method'.
Optionally can be provided a second string with parameters to be passed
to the Python function.
</para>
<para>
Both parameters can contain pseudo-variables.
</para>
<example>
<title><function>python_exec</function> usage</title>
<programlisting format="linespecific">
...
python_exec("my_python_function");
python_exec("my_python_function", "my_params");
python_exec("my_python_function", "$rU");
...
</programlisting>
</example>
</section>
</section>
<section>
<title>RPC Commands</title>
<section id="app_python3.r.reload">
<title>
<function moreinfo="none">app_python.reload</function>
</title>
<para>
IMPORTANT: this is not thread-safe. In your Python script
do not use C extensions with threads that call into
<varname>apy_exec()</varname>.
</para>
<para>
Marks the need to reload the Python script.
The actual reload is done in each worker when it next invokes a Python method.
The module uses a worker process lock to prevent recursive reloads.
</para>
<para>
This function only reloads (re-executes) the user script and creates
a new script object. It does not reinitialize the interpreter (references
in the old module remain if not redefined by the new version).
</para>
<para>
Name: <emphasis>app_python.reload</emphasis>
</para>
<para>Parameters: <emphasis>none</emphasis></para>
<para>
Example:
</para>
<programlisting format="linespecific">
...
&kamcmd; app_python.reload
...
</programlisting>
<para>
Note that reload is done for the Python script provided as parameter
to this &kamailio; module. To reload the Python libraries imported
in this script, use something like:
</para>
<programlisting format="linespecific">
...
import mod1
...
import modN
from importlib import reload
def mod_init():
reload(mod1)
...
reload(modN)
return kamailio()
...
</programlisting>
<para>
Where "modX" are the modules imported at the top.
</para>
</section>
<section id="app_python3.r.api_list">
<title>
<function moreinfo="none">app_python.api_list</function>
</title>
<para>
List the functions available via Kemi framework.
</para>
<para>
Name: <emphasis>app_python.api_list</emphasis>
</para>
<para>Parameters: <emphasis>none</emphasis></para>
<para>
Example:
</para>
<programlisting format="linespecific">
...
&kamcmd; app_python.api_list
...
</programlisting>
</section>
</section>
<section id="app_python3.kemi_usage">
<title>KEMI Usage</title>
<para>
The module exports KEMI engine with id "python".
</para>
<para>
Example:
</para>
<programlisting format="linespecific">
...
loadmodule "app_python3.so"
...
cfgengine "python"
...
</programlisting>
<para>
For more details about KEMI, see:
<ulink url="https://www.kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/">https://www.kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/</ulink>
</para>
</section>
</chapter>