monkey/monkey_island/cc/database.py

28 lines
536 B
Python
Raw Normal View History

2018-02-28 01:13:28 +08:00
import gridfs
from flask_pymongo import MongoClient, PyMongo
2017-10-31 19:55:29 +08:00
from pymongo.errors import ServerSelectionTimeoutError
2017-08-25 22:47:08 +08:00
__author__ = 'Barak'
mongo = PyMongo()
2017-10-31 19:55:29 +08:00
2018-02-28 01:13:28 +08:00
class Database:
def __init__(self):
self.gridfs = None
def init(self):
self.gridfs = gridfs.GridFS(mongo.db)
database = Database()
2017-10-31 19:55:29 +08:00
def is_db_server_up(mongo_url):
client = MongoClient(mongo_url, serverSelectionTimeoutMS=100)
try:
client.server_info()
return True
except ServerSelectionTimeoutError:
return False