def make_request(module): # Create client and authenticate. api_client = ingate_create_client(**module.params) # Get unit information. response = api_client.unit_information() return response
def make_request(module): # Create client and authenticate. api_client = ingate_create_client(**module.params) if module.params.get('add'): # Add a row to a table. table = module.params['table'] columns = module.params['columns'] response = api_client.add_row(table, **columns) return True, 'add', response elif module.params.get('delete'): # Delete a row/table. changed = False table = module.params['table'] rowid = module.params.get('rowid') if rowid: response = api_client.delete_row(table, rowid=rowid) else: response = api_client.delete_table(table) if response: changed = True return changed, 'delete', response elif module.params.get('get'): # Get the contents of a table/row. table = module.params['table'] rowid = module.params.get('rowid') if rowid: response = api_client.dump_row(table, rowid=rowid) else: response = api_client.dump_table(table) if response: changed = True return changed, 'get', response elif module.params.get('modify'): # Modify a table row. table = module.params['table'] columns = module.params['columns'] rowid = module.params.get('rowid') if rowid: response = api_client.modify_row(table, rowid=rowid, **columns) else: response = api_client.modify_single_row(table, **columns) if response: changed = True return changed, 'modify', response elif module.params.get('revert'): # Revert edits. response = api_client.revert_edits() if response: response = response[0]['revert-edits'] return True, 'revert', response elif module.params.get('factory'): # Load factory defaults. response = api_client.load_factory() if response: response = response[0]['load-factory'] return True, 'factory', response elif module.params.get('store'): # Store edit. no_response = module.params.get('no_response') response = api_client.store_edit(no_response=no_response) if response: response = response[0]['store-edit'] return True, 'store', response elif module.params.get('return_rowid'): # Find matching rowid(s) in a table. table = module.params['table'] columns = module.params['columns'] response = api_client.dump_table(table) rowids = [] for row in response: match = False for (name, value) in columns.items(): if name not in row['data']: continue if not row['data'][name] == value: match = False break else: match = True if match: rowids.append(row['id']) return False, 'return_rowid', rowids elif module.params.get('download'): # Download the configuration database. store = module.params.get('store_download') path = module.params.get('path') filename = module.params.get('filename') response = api_client.download_config(store=store, path=path, filename=filename) if response: response = response[0]['download-config'] return False, 'download', response return False, '', {}