@@ -43,6 +43,7 @@ class Infoblox(object):
43
43
delete_host_alias
44
44
create_cname_record
45
45
delete_cname_record
46
+ update_cname_record
46
47
create_dhcp_range
47
48
delete_dhcp_range
48
49
get_next_available_ip
@@ -381,6 +382,39 @@ def delete_cname_record(self, fqdn):
381
382
except Exception :
382
383
raise
383
384
385
+ def update_cname_record (self , canonical , name ):
386
+ """ Implements IBA REST API call to update or repoint IBA cname record
387
+ :param canonical: canonical name in FQDN format
388
+ :param name: the name for the new CNAME record in FQDN format
389
+ """
390
+ rest_url = 'https://' + self .iba_host + '/wapi/v' + self .iba_wapi_version + '/record:cname'
391
+ payload = json .dumps ({'name' : name })
392
+ try :
393
+ r = requests .get (url = rest_url , auth = (self .iba_user , self .iba_password ), verify = self .iba_verify_ssl , data = payload )
394
+ r_json = r .json ()
395
+ # RFC1912 - A CNAME can not coexist with any other data, we should expect utmost one entry
396
+ if r .status_code == 200 and len (r_json ) == 1 :
397
+ ibx_cname = r .json ()[0 ]
398
+ cname_ref = ibx_cname ['_ref' ]
399
+ payload = '{"canonical": ' + json .JSONEncoder ().encode (canonical ) + '}'
400
+ rest_url = 'https://' + self .iba_host + '/wapi/v' + self .iba_wapi_version + '/' + cname_ref
401
+ r = requests .put (url = rest_url , auth = (self .iba_user , self .iba_password ), verify = self .iba_verify_ssl , data = payload )
402
+ if r .status_code == 200 or r .status_code == 201 :
403
+ return
404
+ else :
405
+ r .raise_for_status ()
406
+ elif len (r_json ) == 0 :
407
+ raise InfobloxNotFoundException ("CNAME: " + name + " not found." )
408
+ else :
409
+ if 'text' in r_json :
410
+ raise InfobloxGeneralException (r_json ['text' ])
411
+ else :
412
+ r .raise_for_status ()
413
+ except ValueError :
414
+ raise Exception (r )
415
+ except Exception :
416
+ raise
417
+
384
418
def create_dhcp_range (self , start_ip_v4 , end_ip_v4 ):
385
419
""" Implements IBA REST API call to add DHCP range for given start and end addresses
386
420
:param start_ip_v4: IP v4 address
0 commit comments