def delete_like(self, match=None, folder='Common'): if match: folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + '/ltm/rule/' 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'].find(match) > -1: 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('rule', response.text) raise exceptions.RuleDeleteException( response.text) return True elif response.status_code != 404: Log.error('rule', response.text) raise exceptions.RuleQueryException(response.text) return False
def exists(self, name=None, folder='Common'): folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + '/ltm/rule/' 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('rule', response.text) raise exceptions.RuleQueryException(response.text) return False
def get_rule(self, name=None, folder='Common'): if name: folder = str(folder).replace('/', '') request_url = self.bigip.icr_url + '/ltm/rule/' request_url += '~' + folder + '~' + name request_url += '?$select=apiAnonymous' response = self.bigip.icr_session.get(request_url, timeout=const.CONNECTION_TIMEOUT) if response.status_code < 400: response_obj = json.loads(response.text) if 'apiAnonymous' in response_obj: return response_obj['apiAnonymous'] elif response.status_code != 404: Log.error('rule', response.text) raise exceptions.RuleQueryException(response.text) return None