@@ -36,6 +36,8 @@ class Infoblox(object):
36
36
create_networkcontainer
37
37
delete_networkcontainer
38
38
create_host_record
39
+ create_txt_record
40
+ delete_txt_record
39
41
delete_host_record
40
42
add_host_alias
41
43
delete_host_alias
@@ -48,6 +50,7 @@ class Infoblox(object):
48
50
get_host_by_ip
49
51
get_ip_by_host
50
52
get_host_by_regexp
53
+ get_txt_by_regexp
51
54
get_host_by_extattrs
52
55
get_host_extattrs
53
56
get_network
@@ -58,7 +61,7 @@ class Infoblox(object):
58
61
delete_network_extattrs
59
62
"""
60
63
61
- def __init__ (self , iba_ipaddr , iba_user , iba_password , iba_wapi_version , iba_dns_view , iba_network_view , iba_verify_ssl = True ):
64
+ def __init__ (self , iba_ipaddr , iba_user , iba_password , iba_wapi_version , iba_dns_view , iba_network_view , iba_verify_ssl = False ):
62
65
""" Class initialization method
63
66
:param iba_ipaddr: IBA IP address of management interface
64
67
:param iba_user: IBA user name
@@ -75,7 +78,7 @@ def __init__(self, iba_ipaddr, iba_user, iba_password, iba_wapi_version, iba_dns
75
78
self .iba_dns_view = iba_dns_view
76
79
self .iba_network_view = iba_network_view
77
80
self .iba_verify_ssl = iba_verify_ssl
78
-
81
+
79
82
def get_next_available_ip (self , network ):
80
83
""" Implements IBA next_available_ip REST API call
81
84
Returns IP v4 address
@@ -144,6 +147,29 @@ def create_host_record(self, address, fqdn):
144
147
except Exception :
145
148
raise
146
149
150
+ def create_txt_record (self , text , fqdn ):
151
+ """ Implements IBA REST API call to create IBA txt record
152
+ Returns IP v4 address assigned to the host
153
+ :param text: free text to be added to the record
154
+ :param fqdn: hostname in FQDN
155
+ """
156
+ rest_url = 'https://' + self .iba_host + '/wapi/v' + self .iba_wapi_version + '/record:txt'
157
+ payload = '{"text": "' + text + '","name": "' + fqdn + '","view": "' + self .iba_dns_view + '"}'
158
+ try :
159
+ r = requests .post (url = rest_url , auth = (self .iba_user , self .iba_password ), verify = self .iba_verify_ssl , data = payload )
160
+ r_json = r .json ()
161
+ if r .status_code == 200 or r .status_code == 201 :
162
+ return
163
+ else :
164
+ if 'text' in r_json :
165
+ raise InfobloxGeneralException (r_json ['text' ])
166
+ else :
167
+ r .raise_for_status ()
168
+ except ValueError :
169
+ raise Exception (r )
170
+ except Exception :
171
+ raise
172
+
147
173
def delete_host_record (self , fqdn ):
148
174
""" Implements IBA REST API call to delete IBA host record
149
175
:param fqdn: hostname in FQDN
@@ -179,6 +205,41 @@ def delete_host_record(self, fqdn):
179
205
except Exception :
180
206
raise
181
207
208
+ def delete_txt_record (self , fqdn ):
209
+ """ Implements IBA REST API call to delete IBA TXT record
210
+ :param fqdn: hostname in FQDN
211
+ """
212
+ rest_url = 'https://' + self .iba_host + '/wapi/v' + self .iba_wapi_version + '/record:txt?name=' + fqdn + '&view=' + self .iba_dns_view
213
+ try :
214
+ r = requests .get (url = rest_url , auth = (self .iba_user , self .iba_password ), verify = self .iba_verify_ssl )
215
+ r_json = r .json ()
216
+ if r .status_code == 200 :
217
+ if len (r_json ) > 0 :
218
+ host_ref = r_json [0 ]['_ref' ]
219
+ if host_ref and re .match ("record:txt\/[^:]+:([^\/]+)\/" , host_ref ).group (1 ) == fqdn :
220
+ rest_url = 'https://' + self .iba_host + '/wapi/v' + self .iba_wapi_version + '/' + host_ref
221
+ r = requests .delete (url = rest_url , auth = (self .iba_user , self .iba_password ), verify = self .iba_verify_ssl )
222
+ if r .status_code == 200 :
223
+ return
224
+ else :
225
+ if 'text' in r_json :
226
+ raise InfobloxGeneralException (r_json ['text' ])
227
+ else :
228
+ r .raise_for_status ()
229
+ else :
230
+ raise InfobloxGeneralException ("Received unexpected host reference: " + host_ref )
231
+ else :
232
+ raise InfobloxNotFoundException ("No requested host found: " + fqdn )
233
+ else :
234
+ if 'text' in r_json :
235
+ raise InfobloxGeneralException (r_json ['text' ])
236
+ else :
237
+ r .raise_for_status ()
238
+ except ValueError :
239
+ raise Exception (r )
240
+ except Exception :
241
+ raise
242
+
182
243
def add_host_alias (self , host_fqdn , alias_fqdn ):
183
244
""" Implements IBA REST API call to add an alias to IBA host record
184
245
:param host_fqdn: host record name in FQDN
@@ -433,6 +494,33 @@ def get_host_by_regexp(self, fqdn):
433
494
except Exception :
434
495
raise
435
496
497
+ def get_txt_by_regexp (self , fqdn ):
498
+ """ Implements IBA REST API call to retrieve TXT records by fqdn regexp filter
499
+ Returns dictonary of host names in FQDN matched to given regexp filter with the TXT value
500
+ :param fqdn: hostname in FQDN or FQDN regexp filter
501
+ """
502
+ rest_url = 'https://' + self .iba_host + '/wapi/v' + self .iba_wapi_version + '/record:txt?name~=' + fqdn + '&view=' + self .iba_dns_view
503
+ hosts = {}
504
+ try :
505
+ r = requests .get (url = rest_url , auth = (self .iba_user , self .iba_password ), verify = self .iba_verify_ssl )
506
+ r_json = r .json ()
507
+ if r .status_code == 200 :
508
+ if len (r_json ) > 0 :
509
+ for host in r_json :
510
+ hosts [host ['name' ]] = host ['text' ]
511
+ return hosts
512
+ else :
513
+ raise InfobloxNotFoundException ("No txt records found for regexp filter: " + fqdn )
514
+ else :
515
+ if 'text' in r_json :
516
+ raise InfobloxGeneralException (r_json ['text' ])
517
+ else :
518
+ r .raise_for_status ()
519
+ except ValueError :
520
+ raise Exception (r )
521
+ except Exception :
522
+ raise
523
+
436
524
def get_host_by_ip (self , ip_v4 ):
437
525
""" Implements IBA REST API call to find hostname by IP address
438
526
Returns array of host names in FQDN associated with given IP address
0 commit comments