Title: Added basic "exclude" range for next_available_ip · Issue #19 · Infoblox-Development/Infoblox-API-Python · GitHub
Open Graph Title: Added basic "exclude" range for next_available_ip · Issue #19 · Infoblox-Development/Infoblox-API-Python
X Title: Added basic "exclude" range for next_available_ip · Issue #19 · Infoblox-Development/Infoblox-API-Python
Description: In my organization, we try to reserve the first 10 IPs in any given network. I modified the "get_next_available_ip" function to include the ability to exclude a range starting at the first address in the network. This could easily be fur...
Open Graph Description: In my organization, we try to reserve the first 10 IPs in any given network. I modified the "get_next_available_ip" function to include the ability to exclude a range starting at the first address ...
X Description: In my organization, we try to reserve the first 10 IPs in any given network. I modified the "get_next_available_ip" function to include the ability to exclude a range starting at the firs...
Opengraph URL: https://github.com/Infoblox-Development/Infoblox-API-Python/issues/19
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Added basic \"exclude\" range for next_available_ip","articleBody":"In my organization, we try to reserve the first 10 IPs in any given network. I modified the \"get_next_available_ip\" function to include the ability to exclude a range starting at the first address in the network. This could easily be further modified for any range. I've named the new function \"get_next_available_ip_long\":\n\n```\ndef get_next_available_ip_long(self, network, num):\n \"\"\" Implements IBA next_available_ip REST API call\n Returns IP v4 address\n :param network: network in CIDR format\n \"\"\"\n\n \"\"\"\n Modified to include param num\n param num is integer, will exclude that many addresses starting at .0\n \"\"\"\n def ip_exclude(start, count):\n \"\"\"\n This sub-function creates a list of excluded IPs for the next_available IP\n Right now it only works to exclude the first x addresses in a range\n \"\"\"\n\n start_addr = start[:-3] #chomps the \"/24\" off the network name\n start_addr_list = start_addr.split(\".\") #splits the network on each dot\n start_oct4 = int(start_addr_list[3]) #changes the 4th octet to an int\n start_oct4_str = start_addr_list[3] #creates a string value for the 4th octet\n\n count = int(count)\n end_oct4 = start_oct4 + count #sets the end of the reserved range\n end_oct4_str = str(end_oct4) #makes a string variable for that\n end_addr = start_addr_list[0] + \".\" + start_addr_list[1] + \".\" + start_addr_list[2] + \".\" + end_oct4_str\n\n\n exclude_range = []\n while start_oct4 \u003c end_oct4:\n start_oct4 = start_oct4 + 1\n temp_oct4 = str(start_oct4)\n temp_addr = start_addr_list[0] + \".\" + start_addr_list[1] + \".\" + start_addr_list[2] + \".\" + temp_oct4\n exclude_range.append(temp_addr)\n\n return exclude_range #returns a list of excluded addresses for post_data\n\n exclude = ip_exclude(network, num)\n\n rest_url = 'https://' + self.iba_host + '/wapi/v' + self.iba_wapi_version + '/network?network=' + network + '\u0026network_view=' + self.iba_network_view\n try:\n r = requests.get(url=rest_url, auth=(self.iba_user, self.iba_password), verify=self.iba_verify_ssl)\n r_json = r.json()\n if r.status_code == 200:\n if len(r_json) \u003e 0:\n net_ref = r_json[0]['_ref']\n rest_url = 'https://' + self.iba_host + '/wapi/v' + self.iba_wapi_version + '/' + net_ref + '?_function=next_available_ip'\n post_data = {\"num\":1,'exclude':exclude}\n #this is the infoblox-approved \"long-form\" version of the \"next available IP\" call\n r = requests.post(url=rest_url, auth=(self.iba_user, self.iba_password), verify=self.iba_verify_ssl, data=json.dumps(post_data))\n r_json = r.json()\n if r.status_code == 200:\n ip_v4 = r_json['ips'][0]\n return ip_v4\n else:\n if 'text' in r_json:\n if 'code' in r_json and r_json['code'] == 'Client.Ibap.Data':\n raise InfobloxNoIPavailableException(r_json['text'])\n else:\n raise InfobloxGeneralException(r_json['text'])\n else:\n r.raise_for_status()\n else:\n raise InfobloxNotFoundException(\"No requested network found: \" + network)\n else:\n if 'text' in r_json:\n raise InfobloxGeneralException(r_json['text'])\n else:\n r.raise_for_status()\n except ValueError:\n raise Exception(r)\n except Exception:\n raise\n\n```\n","author":{"url":"https://github.com/Zamboughnuts","@type":"Person","name":"Zamboughnuts"},"datePublished":"2016-10-18T14:24:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/19/Infoblox-API-Python/issues/19"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1161f88d-9a19-e67d-4304-b74b71b60e4f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8710:13AA49:2AA0C55:37CCF53:697D5B5C |
| html-safe-nonce | e16fe71e76e379b709b7a3d4c802adb5ac2dc783d1efb36da9be332785fbe00a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzEwOjEzQUE0OToyQUEwQzU1OjM3Q0NGNTM6Njk3RDVCNUMiLCJ2aXNpdG9yX2lkIjoiNzIzNDI0MTEyNDcwMzc1NTEwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bbebfd95a4e7522457c834f6eaf4bb5d017a104a34f6253ec818e288fb6570b9 |
| hovercard-subject-tag | issue:183701915 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Infoblox-Development/Infoblox-API-Python/19/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c011de9625e7611dfa0162fa602d6098a7de5a1edc042031999df822eaaa553f/Infoblox-Development/Infoblox-API-Python/issues/19 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c011de9625e7611dfa0162fa602d6098a7de5a1edc042031999df822eaaa553f/Infoblox-Development/Infoblox-API-Python/issues/19 |
| og:image:alt | In my organization, we try to reserve the first 10 IPs in any given network. I modified the "get_next_available_ip" function to include the ability to exclude a range starting at the first address ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Zamboughnuts |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| go-import | github.com/Infoblox-Development/Infoblox-API-Python git https://github.com/Infoblox-Development/Infoblox-API-Python.git |
| octolytics-dimension-user_id | 8240171 |
| octolytics-dimension-user_login | Infoblox-Development |
| octolytics-dimension-repository_id | 22124028 |
| octolytics-dimension-repository_nwo | Infoblox-Development/Infoblox-API-Python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22124028 |
| octolytics-dimension-repository_network_root_nwo | Infoblox-Development/Infoblox-API-Python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width