- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Single REST call for creating a host object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2019 01:17 PM
I have to make a generic call to create a record:host in networks with and without DHCP ranges defined.
I can do it with 2 separate calls and error detection like:
newhostname=newhost.test
oldhostname=oldhost.test
# For network WITH DHCP
curl -s --negotiate -u : -H "Content-Type: application/json" -X POST "https://ibx/wapi/v2.10.3/request" -d '[{"method": "GET", "object": "network", "data": {"contains_address":"'"$(dig $oldhostname +short)"'"},"assign_state": {"netw_name": "network"},"discard": true},{"method": "GET", "object": "range", "data": {"network": "##STATE:netw_name:##"},"assign_state": {"range_ref": "_ref"},"discard": true,"enable_substitution": true},{"method": "POST", "object": "##STATE:range_ref:##", "args": {"_function": "next_available_ip"}, "data":{"num":1},"enable_substitution": true,"assign_state": {"next": "ips[0]"},"discard": false},{"method": "POST", "object": "record:host", "data": {"name": "'"$newhostname"'", "ipv4addrs": [{"ipv4addr": "##STATE:next:##"}]}, "enable_substitution": true}]'
#For network WITHOUT DHCP
curl -s --negotiate -u : -H "Content-Type: application/json" -X POST "https://ibx/wapi/v2.10.3/request" -d '[{"method": "GET", "object": "network","data": {"contains_address":"'"$(dig $oldhostname +short)"'"},"assign_state": {"netw_ref": "_ref"},"discard": true},{"method": "POST","object": "##STATE:netw_ref:##","args": {"_function": "next_available_ip"}, "data":{"num":1},"enable_substitution": true,"assign_state": {"next": "ips[0]"},"discard": false},{"method": "POST", "object": "record:host", "data": {"name": "'"$newhostname"'", "ipv4addrs": [{"ipv4addr": "##STATE:next:##"}]}, "enable_substitution": true}]'
So question is, how to combine those calls to pick next available IP on the network where given host exists and make a record:host for it?
Re: Single REST call for creating a host object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 10:05 AM
Is your intention to create the host within the range, when one exists, or to avoid the range?
If you want to avoid the range, the next_available_ip function will already do that for you. No need to look up the range, just run the next_available_ip function against the network.
Re: Single REST call for creating a host object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 10:19 AM
Want to be within the range. Look up the host, provision another one next to it.
Re: Single REST call for creating a host object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2020 12:38 AM
Great post. Thanks for the information
Re: Single REST call for creating a host object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 02:29 AM
Great Information.Thanks for sharing