Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ip-reservation with help of fixed-address #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions infoblox.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,45 @@ def create_host_record(self, address, fqdn):
except Exception:
raise

def reserve_ip_addr(self, address, name, comment):
""" Implements IBA REST API call to reserve IBA IPv4 address
Returns None
:param address: IP v4 address in CIDR format without subnet
:param name: reservation name
:param comment: context
"""
attr= lambda key, val: '"' + key + '":' + '"' + val + '"'
extattr = lambda key, val: '"' + key + '":' + '{"value":"' + val + '"}'

rest_url = 'https://' + self.iba_host + '/wapi/v' + self.iba_wapi_version + '/fixedaddress'
payload = '{' + attr("ipv4addr", address) + ',' + \
attr("mac", "00:00:00:00:00:00") + ',' + \
attr("name", name) + ',' + \
attr("comment", comment) + \

# example extattrs

#'"extattrs": {' + \
#extattr("Editor", editor) + "," + \
'}'

print payload
r = requests.post(url=rest_url, auth=(self.iba_user, self.iba_password), verify=self.iba_verify_ssl, data=str(payload))
r_json = r.json()
try:
if r.status_code == 200 or r.status_code == 201:
return
else:
if 'text' in r_json:
raise InfobloxGeneralException(r_json['text'])
else:
r.raise_for_status()
except ValueError:
raise Exception(r)
except Exception:
raise


def create_txt_record(self, text, fqdn):
""" Implements IBA REST API call to create IBA txt record
Returns IP v4 address assigned to the host
Expand Down