def check_for_task(self, task): url = urlparse(task).path for x in range(0, 60): response = self.client.get( url, account_id=self.want.preferred_account_id) if response['code'] == 200: if response['contents']['status'] == 'Completed': return True if response['contents']['status'] == 'Failed': raise F5CollectionError(response['contents']['error']) else: raise F5CollectionError(response['code'], response['contents'])
def remove(self): if self.module.check_mode: return True self.remove_from_device() if self.exists(): raise F5CollectionError("Failed to delete the resource.") return True
def exec_module(self): self.handle_all_keyword() res = self.check_valid_gather_subset(self.want.gather_subset) if res: invalid = ','.join(res) raise F5CollectionError( "The specified 'gather_subset' options are invalid: {0}". format(invalid)) result = self.filter_excluded_facts() managers = [] for name in result: manager = self.get_manager(name) if manager: managers.append(manager) if not managers: result = dict(queried=False) return result result = self.execute_managers(managers) if result: result['queried'] = True else: result['queried'] = False return result
def remove_from_device(self): response = self.client.delete( self.url + '/' + self.want.name, account_id=self.want.preferred_account_id) if response['code'] == 200: return True else: raise F5CollectionError(response['code'], response['contents'])
def remove_from_device(self): payload = { "action": "remove", } try: payload.update(self.want.content) except ValueError: raise F5CollectionError( "The provided 'declaration' could not be converted into valid json. If you " "are using the 'to_nice_json' filter, please remove it.") response = self.client.post(self.url, data=payload, account_id=self.want.preferred_account_id) if response['code'] == 200: task = response['contents']['taskReference'] return self.check_for_task(task) else: raise F5CollectionError(response['code'], response['contents'])
def create_on_device(self): params = self.changes.api_params() response = self.client.post(self.url, data=params, account_id=self.want.preferred_account_id) if response['code'] == 200: return True else: raise F5CollectionError(response['code'], response['contents'])
def exists(self): response = self.client.get(self.url + '/' + self.want.name, account_id=self.want.preferred_account_id) if response['code'] == 404: return False elif response['code'] == 200: return True else: raise F5CollectionError(response['contents'])
def read_collection_from_device(self): uri = '/beacon/v1/sources' response = self.client.get(uri, account_id=self.preferred_account_id) if response['code'] != 200: raise F5CollectionError(response['contents']) if 'sources' not in response['contents'] or len( response['contents']['sources']) == 0: return [] result = response['contents']['sources'] return result
def gather_subset(self): if isinstance(self._values['gather_subset'], string_types): self._values['gather_subset'] = [self._values['gather_subset']] elif not isinstance(self._values['gather_subset'], list): raise F5CollectionError( "The specified gather_subset must be a list.") tmp = list(set(self._values['gather_subset'])) tmp.sort() self._values['gather_subset'] = tmp return self._values['gather_subset']
def to_return(self): result = {} try: for returnable in self.returnables: change = getattr(self, returnable) if isinstance(change, dict) and 'declaration' not in change: result.update(change) else: result[returnable] = change result = self._filter_params(result) except Exception as ex: raise F5CollectionError(str(ex)) return result