summaryrefslogtreecommitdiffstats
path: root/cvp/opnfv_testapi/db/api.py
diff options
context:
space:
mode:
authorhongbo tian <hongbo.tianhongbo@huawei.com>2017-09-28 09:28:41 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-09-28 09:28:41 +0000
commit61820ee85c967d90021e4089c6a7907046685639 (patch)
tree0c3f23e2146f0855fb5be0ff55343d59e3a9c9ab /cvp/opnfv_testapi/db/api.py
parent0cc2fdefa9e6e959e7c69beede736738f339f636 (diff)
parent0cf6b232ac9cf128ee9183a27c08f4f74ab2e2e6 (diff)
Merge "add api&web services for cvp"
Diffstat (limited to 'cvp/opnfv_testapi/db/api.py')
-rw-r--r--cvp/opnfv_testapi/db/api.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/cvp/opnfv_testapi/db/api.py b/cvp/opnfv_testapi/db/api.py
new file mode 100644
index 00000000..c057480d
--- /dev/null
+++ b/cvp/opnfv_testapi/db/api.py
@@ -0,0 +1,38 @@
+import motor
+
+from opnfv_testapi.common.config import CONF
+
+DB = motor.MotorClient(CONF.mongo_url)[CONF.mongo_dbname]
+
+
+def db_update(collection, query, update_req):
+ return _eval_db(collection, 'update', query, update_req, check_keys=False)
+
+
+def db_delete(collection, query):
+ return _eval_db(collection, 'remove', query)
+
+
+def db_aggregate(collection, pipelines):
+ return _eval_db(collection, 'aggregate', pipelines, allowDiskUse=True)
+
+
+def db_list(collection, query):
+ return _eval_db(collection, 'find', query)
+
+
+def db_save(collection, data):
+ return _eval_db(collection, 'insert', data, check_keys=False)
+
+
+def db_find_one(collection, query):
+ return _eval_db(collection, 'find_one', query)
+
+
+def _eval_db(collection, method, *args, **kwargs):
+ exec_collection = DB.__getattr__(collection)
+ return exec_collection.__getattribute__(method)(*args, **kwargs)
+
+
+def _eval_db_find_one(query, table=None):
+ return _eval_db(table, 'find_one', query)