def update(self, *args, **kwargs): """ Implements the update method from the Observer interface. Retrieves the most recent node configuration from the database. :param args: None :param kwargs: None :return: None """ with MongoConnector(constants.DB_CONFIG) as db: data = db.nodes.find() self.nodes = to_list(data)
def _get_backup_details(self, backup_id, limit, offset): with MongoConnector(constants.DB_CONFIG) as db: data = db.backup.find({'id': {'$regex': str(backup_id)}}, {'_id': 0}).sort('creation_date', DESCENDING) \ .skip(offset).limit(limit) if data: payload = { 'data': to_list(data), 'offset': offset, 'limit': limit, 'total': data.count(), } return payload else: return "Requested resource is not available.", 404
def _get_backup_list(self, node_id=None, show_deleted=False, limit=10, offset=0): with MongoConnector(constants.DB_CONFIG) as db: query = {} if not show_deleted: query['deleted'] = False if node_id: query['node'] = node_id data = db.backup.find(query, {'_id': 0}).sort('creation_date', DESCENDING).skip(offset).limit(limit) payload = { 'data': to_list(data), 'offset': offset, 'limit': limit, 'total': data.count() } return payload
def get(self): with MongoConnector(constants.DB_CONFIG) as db: return dumps(to_list(db.nodes.find({}, {'_id': 0})))