-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmydns.html
More file actions
233 lines (208 loc) · 19.8 KB
/
mydns.html
File metadata and controls
233 lines (208 loc) · 19.8 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: package mydns</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>mydns</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/rcovarru/git/python-mydns/mydns/__init__.py">/home/rcovarru/git/python-mydns/mydns/__init__.py</a></font></td></tr></table>
<p><tt>Author: Renato Covarrubias <rnt [at] rnt.cl><br>
<br>
Based on Milan Nikolic <gen2brain [at] gmail.com> works.<br>
<br>
This program is free software: you can redistribute it and/or modify<br>
it under the terms of the GNU General Public License as published by<br>
the Free Software Foundation, either version 3 of the License, or<br>
(at your option) any later version.<br>
<br>
This program is distributed in the hope that it will be useful,<br>
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
GNU General Public License for more details.<br>
<br>
You should have received a copy of the GNU General Public License<br>
along with this program. If not, see <<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Package Contents</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="mydns.html#mydns">mydns</a>
</font></dt></dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="mydns">class <strong>mydns</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Interface to the MyDNS DB<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="mydns-__del__"><strong>__del__</strong></a>(self)</dt><dd><tt>When this object die, closes MySQL connection</tt></dd></dl>
<dl><dt><a name="mydns-__init__"><strong>__init__</strong></a>(self, host, db, user, passwd)</dt><dd><tt>Create a new <a href="#mydns">mydns</a> instance and connects to MySQL server.<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(<br>
host='localhost',<br>
db='<a href="#mydns">mydns</a>',<br>
user='username',<br>
passwd='password')<br>
<br>
NOTE:<br>
If passwd is None, we try to connect without password.<br>
Perhaps it seems idiotic, but mysql allows users without password.</tt></dd></dl>
<dl><dt><a name="mydns-create_rr"><strong>create_rr</strong></a>(self, zone, name, data, aux<font color="#909090">=0</font>, ttl<font color="#909090">=3600</font>, rrtype<font color="#909090">='A'</font>)</dt><dd><tt>Creates new RR record<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
<br>
dns.<a href="#mydns-create_rr">create_rr</a>(dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'), 'foobar', '127.0.0.1')<br>
dns.<a href="#mydns-create_rr">create_rr</a>(dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'), 'lala', ['127.0.0.1', '127.0.0.2'])</tt></dd></dl>
<dl><dt><a name="mydns-create_soa"><strong>create_soa</strong></a>(self, origin, ns, mbox, serial<font color="#909090">=1</font>, refresh<font color="#909090">=900</font>, retry<font color="#909090">=600</font>, expire<font color="#909090">=86400</font>, minimum<font color="#909090">=300</font>, ttl<font color="#909090">=3600</font>, xfer<font color="#909090">=None</font>, active<font color="#909090">='Y'</font>)</dt><dd><tt>Creates new SOA record<br>
<br>
import <a href="#mydns">mydns</a><br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
dns.<a href="#mydns-create_soa">create_soa</a>('test1.domain.com.', 'ns1.domain.com.', 'dns-admin.domain.com.')<br>
<br>
NOTE: 'xfer' and 'active' arguments are only used if the columns exists.</tt></dd></dl>
<dl><dt><a name="mydns-delete_rr"><strong>delete_rr</strong></a>(self, rrid<font color="#909090">=None</font>, zone<font color="#909090">=None</font>, name<font color="#909090">=None</font>, data<font color="#909090">=None</font>, aux<font color="#909090">=None</font>, ttl<font color="#909090">=None</font>, rrtype<font color="#909090">=None</font>)</dt><dd><tt>Deletes rr records<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
<br>
# Delete all register from domain test.domain.com<br>
dns.<a href="#mydns-delete_rr">delete_rr</a>(zone=dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'))<br>
<br>
# Delete register with name start with 'dns'<br>
dns.<a href="#mydns-delete_rr">delete_rr</a>(name='dns%')<br>
<br>
# Delete all register with type 'A' or 'AAAA'.<br>
dns.<a href="#mydns-delete_rr">delete_rr</a>(rrtype=['A', 'AAAA'])<br>
<br>
# Delete register from zone=1 and type 'A'<br>
dns.<a href="#mydns-delete_rr">delete_rr</a>(zone=1, rrtype='A')<br>
<br>
# Delete register with id 42<br>
dns.<a href="#mydns-delete_rr">delete_rr</a>(rrid=42)</tt></dd></dl>
<dl><dt><a name="mydns-delete_soa"><strong>delete_soa</strong></a>(self, id_origin)</dt><dd><tt>Deletes soa record<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
dns.<a href="#mydns-delete_soa">delete_soa</a>(dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'))<br>
dns.<a href="#mydns-delete_soa">delete_soa</a>(1)</tt></dd></dl>
<dl><dt><a name="mydns-disable_soa"><strong>disable_soa</strong></a>(self, origin)</dt><dd><tt>Disable SOA, see _set_active_soa()<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
dns.<a href="#mydns-disable_soa">disable_soa</a>('test.domain.com.')</tt></dd></dl>
<dl><dt><a name="mydns-enable_soa"><strong>enable_soa</strong></a>(self, origin)</dt><dd><tt>Enable SOA, see _set_active_soa()<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
dns.<a href="#mydns-enable_soa">enable_soa</a>('test.domain.com.')</tt></dd></dl>
<dl><dt><a name="mydns-get_new_serial"><strong>get_new_serial</strong></a>(self, id_origin, force_increment<font color="#909090">=False</font>, force_date_increment<font color="#909090">=False</font>)</dt><dd><tt>Returns new serial number<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
new_serial = dns.<a href="#mydns-get_new_serial">get_new_serial</a>(1)<br>
new_serial = dns.<a href="#mydns-get_new_serial">get_new_serial</a>(dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'), force_increment=True)<br>
<br>
NOTE 1: If the serial started in 1, after upgrade 1,970,010,100 may want to continue using increments of 1. That's what the argument force_increment exists. :P crazy ah?<br>
NOTE 2: If you want to pass from serial < 1,970,010,100 to using serial from date, set force_date_increment=True ;)</tt></dd></dl>
<dl><dt><a name="mydns-get_next_soa_id"><strong>get_next_soa_id</strong></a>(self)</dt><dd><tt>Returns next SOA id<br>
<br>
import <a href="#mydns">mydns</a><br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
next_soa_id = dns.<a href="#mydns-get_next_soa_id">get_next_soa_id</a>()</tt></dd></dl>
<dl><dt><a name="mydns-get_origins"><strong>get_origins</strong></a>(self)</dt><dd><tt>Returns all origins<br>
<br>
import <a href="#mydns">mydns</a><br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
origins = dns.<a href="#mydns-get_origins">get_origins</a>()</tt></dd></dl>
<dl><dt><a name="mydns-get_rr"><strong>get_rr</strong></a>(self, rrid<font color="#909090">=None</font>, zone<font color="#909090">=None</font>, name<font color="#909090">=None</font>, data<font color="#909090">=None</font>, aux<font color="#909090">=None</font>, ttl<font color="#909090">=None</font>, rrtype<font color="#909090">=None</font>)</dt><dd><tt>Returns data from RR table<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
<br>
# Search all register from domain test.domain.com<br>
dns.<a href="#mydns-get_rr">get_rr</a>(zone=dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'))<br>
<br>
# Search register with name start with 'dns'<br>
dns.<a href="#mydns-get_rr">get_rr</a>(name='dns%')<br>
<br>
# Search register with type 'A' or 'AAAA'.<br>
dns.<a href="#mydns-get_rr">get_rr</a>(rrtype=['A', 'AAAA'])<br>
<br>
# Search regiter from zone=1 and type 'A'<br>
dns.<a href="#mydns-get_rr">get_rr</a>(zone=1, rrtype='A')</tt></dd></dl>
<dl><dt><a name="mydns-get_serial"><strong>get_serial</strong></a>(self, id_origin)</dt><dd><tt>Get the origin serial <br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
serial = dns.<a href="#mydns-get_serial">get_serial</a>(1)<br>
serial = dns.<a href="#mydns-get_serial">get_serial</a>(dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'))</tt></dd></dl>
<dl><dt><a name="mydns-get_soa"><strong>get_soa</strong></a>(self, id_origin)</dt><dd><tt>Returns SOA record<br>
<br>
import <a href="#mydns">mydns</a><br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
origin = dns.<a href="#mydns-get_soa">get_soa</a>(dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'))<br>
origin = dns.<a href="#mydns-get_soa">get_soa</a>(1)</tt></dd></dl>
<dl><dt><a name="mydns-get_soa_id"><strong>get_soa_id</strong></a>(self, origin)</dt><dd><tt>Returns SOA id<br>
<br>
import <a href="#mydns">mydns</a><br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
soa_id = dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.')</tt></dd></dl>
<dl><dt><a name="mydns-origin_exists"><strong>origin_exists</strong></a>(self, origin)</dt><dd><tt>Returns True if origin already exists<br>
<br>
import <a href="#mydns">mydns</a><br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
if dns.<a href="#mydns-origin_exists">origin_exists</a>('test.domain.com.'):<br>
print "test.domain.com exists :)"<br>
else:<br>
print "test.domain.com not exists :('"</tt></dd></dl>
<dl><dt><a name="mydns-update_rr"><strong>update_rr</strong></a>(self, rrid, zone<font color="#909090">=None</font>, name<font color="#909090">=None</font>, data<font color="#909090">=None</font>, aux<font color="#909090">=None</font>, ttl<font color="#909090">=None</font>, rrtype<font color="#909090">=None</font>)</dt><dd><tt>Updates records in RR table<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
<br>
In [1]: dns.<a href="#mydns-get_rr">get_rr</a>(4)[0]['id']<br>
Out[1]: 4L<br>
<br>
In [2]: dns.<a href="#mydns-update_rr">update_rr</a>(4, data='10.80.12.50')<br>
Out[2]: True</tt></dd></dl>
<dl><dt><a name="mydns-update_serial"><strong>update_serial</strong></a>(self, id_origin, force_increment<font color="#909090">=False</font>, force_date_increment<font color="#909090">=False</font>)</dt><dd><tt>Updates serial number in SOA table<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
dns.<a href="#mydns-update_serial">update_serial</a>(1)<br>
dns.<a href="#mydns-update_serial">update_serial</a>(1, force_increment=True, force_date_increment=False)<br>
<br>
NOTE: For an explanation of the attribute force_increment or force_date_increment, please see <a href="#mydns-get_new_serial">get_new_serial</a>()</tt></dd></dl>
<dl><dt><a name="mydns-update_soa"><strong>update_soa</strong></a>(self, id_origin, origin<font color="#909090">=None</font>, ns<font color="#909090">=None</font>, mbox<font color="#909090">=None</font>, serial<font color="#909090">=None</font>, refresh<font color="#909090">=None</font>, retry<font color="#909090">=None</font>, expire<font color="#909090">=None</font>, minimum<font color="#909090">=None</font>, force_increment<font color="#909090">=False</font>, force_date_increment<font color="#909090">=False</font>, ttl<font color="#909090">=None</font>, xfer<font color="#909090">=None</font>, active<font color="#909090">='Y'</font>)</dt><dd><tt>Updates record in SOA table<br>
<br>
import <a href="#mydns">mydns</a> <br>
dns = <a href="#mydns">mydns</a>.<a href="#mydns">mydns</a>(host='localhost', db='<a href="#mydns">mydns</a>', user='username', passwd='password')<br>
dns.<a href="#mydns-update_soa">update_soa</a>(dns.<a href="#mydns-get_soa_id">get_soa_id</a>('test.domain.com.'), origin='foobar.domain.com.')<br>
<br>
NOTE: 'xfer' and 'active' arguments are only used if the columns exists.</tt></dd></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-stderr"><strong>stderr</strong></a> = write(...)</dt><dd><tt>write(str) -> None. Write string str to file.<br>
<br>
Note that due to buffering, flush() or close() may be needed before<br>
the file on disk reflects the data written.</tt></dd></dl>
</td></tr></table>
</body></html>