| 20 | |
| 21 | |
| 22 | class InfobloxHelper(object): |
| 23 | MC = MongoConnector.MongoConnector() |
| 24 | |
| 25 | IC = InfobloxConnector.InfobloxConnector() |
| 26 | jobs_collection = MC.get_jobs_connection() |
| 27 | |
| 28 | IBLOX_HOST = IC.HOST |
| 29 | IBLOX_UNAME = IC.UNAME |
| 30 | IBLOX_PASSWD = IC.PASSWD |
| 31 | IBLOX_VERSION = IC.VERSION |
| 32 | |
| 33 | IBLOX_COLLECTIONS = { |
| 34 | "a": "get_infoblox_address_connection", |
| 35 | "cname": "get_infoblox_cname_connection", |
| 36 | "host": "get_infoblox_host_connection", |
| 37 | "mx": "get_infoblox_mx_connection", |
| 38 | "txt": "get_infoblox_txt_connection", |
| 39 | "aaaa": "get_infoblox_aaaa_connection", |
| 40 | } |
| 41 | |
| 42 | @staticmethod |
| 43 | def __convert_zone_to_regex(zone_queried): |
| 44 | """ |
| 45 | Converts the zone value into the regex which retrieves name/fqdn which |
| 46 | end with the zone value. This hence fetches values for sub-zones also. |
| 47 | :return: regex object |
| 48 | """ |
| 49 | regex_string = "^(.*\\.)*" + re.escape(zone_queried) + "$" |
| 50 | return re.compile(regex_string) |
| 51 | |
| 52 | @staticmethod |
| 53 | def get_pagination_params(next_page_id): |
| 54 | """ |
| 55 | The paging format for Infoblox expects _paging and _return_as_object to be set as 1 |
| 56 | for the first call. Post this, _next_page_id is used to retrieve the subsequent page |
| 57 | data. |
| 58 | """ |
| 59 | paging_info = "&_paging=1&_return_as_object=1&_max_results=1500" |
| 60 | if next_page_id: |
| 61 | paging_info = "&_page_id=" + next_page_id |
| 62 | return paging_info |
| 63 | |
| 64 | def get_infoblox_base_url(self, zone, record_type): |
| 65 | """ |
| 66 | Returns the base url to be queried for Infoblox. |
| 67 | :param zone: Zone value to be queried |
| 68 | :param record_type: Record type(host, a, cname, zone, mx, txt) to be queried. |
| 69 | :return: string: Base URL. |
| 70 | """ |
| 71 | zone_regex = self.__convert_zone_to_regex(zone) |
| 72 | url = ( |
| 73 | "https://" |
| 74 | + self.IBLOX_HOST |
| 75 | + "/wapi/v" |
| 76 | + self.IBLOX_VERSION |
| 77 | + "/record:" |
| 78 | + record_type |
| 79 | + "?view=External&name~=" |
nothing calls this directly
no test coverage detected