def delete_all(self, folder='Common'): """ Delete Route Entries """ folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + '/net/route/' request_url += '?$select=name,selfLink' request_filter = 'partition eq ' + folder request_url += '&$filter=' + request_filter response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: response_obj = json.loads(response.text) if 'items' in response_obj: for item in response_obj['items']: if item['name'].startswith(self.OBJ_PREFIX): response = self.bigip.icr_session.delete( self.bigip.icr_link(item['selfLink']), timeout=const.CONNECTION_TIMEOUT) if response.status_code > 400 and \ response.status_code != 404: Log.error('route', response.text) raise exceptions.RouteDeleteException( response.text) return True else: Log.error('route', response.text) raise exceptions.RouteQueryException(response.text) return False
def get_vlans_in_domain(self, folder='Common'): """ Get VLANs in Domain """ folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + \ '/net/route-domain?$select=name,partition,vlans' if folder: request_filter = 'partition eq ' + folder request_url += '&$filter=' + request_filter response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: response_obj = json.loads(response.text) if 'items' in response_obj: vlans = [] folder = str(folder).replace('/', '') for route_domain in response_obj['items']: if route_domain['name'] == folder: if 'vlans' in route_domain: for vlan in route_domain['vlans']: vlans.append(vlan) return vlans return [] else: if response.status_code != 404: Log.error('route-domain', response.text) raise exceptions.RouteQueryException(response.text) return []
def _get_next_domain_id(self): """ Get next route domain id """ request_url = self.bigip.icr_url + '/net/route-domain?$select=id' response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) all_identifiers = [] if response.status_code < 400: response_obj = json.loads(response.text) if 'items' in response_obj: for route_domain in response_obj['items']: all_identifiers.append(int(route_domain['id'])) all_identifiers = sorted(all_identifiers) all_identifiers.remove(0) else: raise exceptions.RouteQueryException(response.text) lowest_available_index = 1 for i in range(len(all_identifiers)): if all_identifiers[i] < lowest_available_index: if len(all_identifiers) > (i + 1): if all_identifiers[i + 1] > lowest_available_index: return lowest_available_index else: lowest_available_index = lowest_available_index + 1 elif all_identifiers[i] == lowest_available_index: lowest_available_index = lowest_available_index + 1 else: return lowest_available_index
def exists(self, name=None, folder='Common'): folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + '/net/route/' request_url += '~' + folder + '~' + name request_url += '?$select=name' response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: return True elif response.status_code != 404: Log.error('route', response.text) raise exceptions.RouteQueryException(response.text) return False
def get_domain_names(self, folder='Common'): """ Get route domains """ folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + '/net/route-domain/' request_url += '?$select=partition,name' response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: response_obj = json.loads(response.text) if 'items' in response_obj: route_domains = [] for route_domain in response_obj['items']: if not folder: route_domains.append(route_domain['name']) elif route_domain['partition'] == folder: route_domains.append(route_domain['name']) return route_domains elif response.status_code != 404: Log.error('route-domain', response.text) raise exceptions.RouteQueryException(response.text) return []
def domain_exists(self, folder='Common', route_domain_id=None): """ Does the route domain exist? """ folder = str(folder).replace('/', '') if folder == 'Common': return True request_url = self.bigip.icr_url + '/net/route-domain/' if route_domain_id is None: request_url += '~' + folder + '~' + folder else: request_url += '~' + folder + '~' + \ folder + '_aux_' + str(route_domain_id) request_url += '?$select=name' response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: return True elif response.status_code != 404: Log.error('route', response.text) raise exceptions.RouteQueryException(response.text) return False
def get_domain(self, folder='Common'): folder = str(folder).replace('/', '') if folder == 'Common': return 0 if folder in self.domain_index: return self.domain_index[folder] else: request_url = self.bigip.icr_url + '/net/route-domain/' request_url += '~' + folder + '~' + folder request_url += '?$select=id' response = self.bigip.icr_session.get( request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: response_obj = json.loads(response.text) if 'id' in response_obj: self.domain_index[folder] = int(response_obj['id']) return self.domain_index[folder] elif response.status_code != 404: Log.error('route-domain', response.text) raise exceptions.RouteQueryException(response.text) return 0
def get_domain_by_id(self, folder='/Common', route_domain_id=0): """ Get VLANs in Domain """ folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + \ '/net/route-domain?$select=id,name,partition,vlans' if folder: request_filter = 'partition eq ' + folder request_url += '&$filter=' + request_filter response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: response_obj = json.loads(response.text) if 'items' in response_obj: for route_domain in response_obj['items']: if int(route_domain['id']) == route_domain_id: return route_domain return None else: if response.status_code != 404: Log.error('route-domain', response.text) raise exceptions.RouteQueryException(response.text) return None