summaryrefslogtreecommitdiff
path: root/kpov_judge
diff options
context:
space:
mode:
Diffstat (limited to 'kpov_judge')
-rwxr-xr-xkpov_judge/add_task.py8
-rwxr-xr-xkpov_judge/create_disk_images.py8
-rw-r--r--kpov_judge/create_opstack.py10
-rw-r--r--kpov_judge/finalize_opstack.py7
-rwxr-xr-xkpov_judge/rm_task.py7
-rw-r--r--kpov_judge/settings-example.py5
-rwxr-xr-xkpov_judge/web/kpov_judge/kpov_judge.py8
7 files changed, 11 insertions, 42 deletions
diff --git a/kpov_judge/add_task.py b/kpov_judge/add_task.py
index 8294a33..76eb2ae 100755
--- a/kpov_judge/add_task.py
+++ b/kpov_judge/add_task.py
@@ -43,12 +43,8 @@ if __name__ == '__main__':
class_id = os.path.split(os.path.dirname(normpath))[-1]
task_id = os.path.basename(normpath)
print((class_id, task_id))
- db = pymongo.MongoClient(settings.DB_HOST).kpov
- try:
- db.authenticate(settings.USERNAME, settings.PASSWORD)
- except Exception as e:
- print("Not authenticated:"+str(e))
- #no auth or auth config?
+
+ db = pymongo.MongoClient(settings.DB_URI).get_default_database()
source = open(fname).read()
d = {}
diff --git a/kpov_judge/create_disk_images.py b/kpov_judge/create_disk_images.py
index 16bbcab..9073538 100755
--- a/kpov_judge/create_disk_images.py
+++ b/kpov_judge/create_disk_images.py
@@ -61,11 +61,9 @@ if __name__ == '__main__':
if len(sys.argv) != 1:
print("Usage: {0}")
print("Create the pending disk images")
- db = pymongo.MongoClient(settings.DB_HOST).kpov
- try:
- db.authenticate(settings.USERNAME, settings.PASSWORD)
- except Exception as e:
- print(str(e))
+
+ db = pymongo.MongoClient(settings.DB_URI).get_default_database()
+
dev_prefix = settings.GUESTFS_DEV_PREFIX
l = db.student_computers.find({"disk_urls": {"$exists": False}})
computers_by_class_task_student = dict()
diff --git a/kpov_judge/create_opstack.py b/kpov_judge/create_opstack.py
index 4b3742a..a7fa699 100644
--- a/kpov_judge/create_opstack.py
+++ b/kpov_judge/create_opstack.py
@@ -31,14 +31,8 @@ def main():
kc = ksclient.Client(endpoint=settings.OS_ADMIN_AUTH_URL, token=settings.OS_ADMIN_TOKEN)
admin_role = kc.roles.find(name='admin')
member_role = kc.roles.find(name='Member')
-
- db = pymongo.MongoClient(settings.DB_HOST).kpov
- try:
- db.authenticate(settings.USERNAME, settings.PASSWORD)
- except Exception, e:
- print str(e)
- #no auth or auth config?
-
+
+ db = pymongo.MongoClient(settings.DB_URI).get_default_database()
l = db.student_tasks.find({'create_openstack': True})
projects = list()
for project in l:
diff --git a/kpov_judge/finalize_opstack.py b/kpov_judge/finalize_opstack.py
index 7938bda..9f3d959 100644
--- a/kpov_judge/finalize_opstack.py
+++ b/kpov_judge/finalize_opstack.py
@@ -38,12 +38,7 @@ def get_quantum_client(tenant_name):
kc = ksclient.Client(endpoint=settings.OS_ADMIN_AUTH_URL, token=settings.OS_ADMIN_TOKEN)
member_role = kc.roles.find(name='Member')
-db = pymongo.MongoClient(settings.DB_HOST).kpov
-try:
- db.authenticate(settings.USERNAME, settings.PASSWORD)
-except Exception, e:
- print str(e)
- #no auth or auth config?
+db = pymongo.MongoClient(settings.DB_URI).get_default_database()
l = db.student_tasks.find({'create_openstack': True})
projects = list()
diff --git a/kpov_judge/rm_task.py b/kpov_judge/rm_task.py
index 0856a5d..8433f29 100755
--- a/kpov_judge/rm_task.py
+++ b/kpov_judge/rm_task.py
@@ -16,12 +16,7 @@ if __name__ == '__main__':
print("Usage: {0} [task_name]".format(sys.argv[0]))
exit(1)
task_id = sys.argv[1]
- db = pymongo.MongoClient(settings.DB_HOST).kpov
- try:
- db.authenticate(settings.USERNAME, settings.PASSWORD)
- except Exception as e:
- print("Not authenticated:"+str(e))
- #no auth or auth config?
+ db = pymongo.MongoClient(settings.DB_URI).get_default_database()
db.computers_meta.remove({'task_id': task_id})
db.networks.remove({'task_id': task_id})
db.task_checkers.remove({'task_id': task_id})
diff --git a/kpov_judge/settings-example.py b/kpov_judge/settings-example.py
index 9bfde58..3128a54 100644
--- a/kpov_judge/settings-example.py
+++ b/kpov_judge/settings-example.py
@@ -1,9 +1,6 @@
DEBUG=True
-DB_HOST='kpov.fri.uni-lj.si'
-DB_PORT=27017
-USERNAME='kpov'
-PASSWORD='SomeSuperSecretPassword'
+DB_URI='mongodb://kpov:SomeSuperSecretPassword@kpov.fri.uni-lj.si:27017/kpov'
# SNAPSHOTS_ROOT='/home/andrejtolic/kpov/snapshots/'
DISK_TEMPLATE_PATH = '/home/kpov/disks/templates'
STUDENT_DISK_PATH='/home/kpov/disks/students'
diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py
index 6e94f05..b832007 100755
--- a/kpov_judge/web/kpov_judge/kpov_judge.py
+++ b/kpov_judge/web/kpov_judge/kpov_judge.py
@@ -32,13 +32,7 @@ params_meta = {'neznano_ime_naloge': {'opis':'NEZNANA NALOGA', 'w': False}}
@app.before_request
def before_request():
- g.db = pymongo.MongoClient(app.config['DB_HOST']).kpov
- try:
- user = app.config['USERNAME']
- password = app.config['PASSWORD']
- g.db.authenticate(user, password)
- except Exception as e:
- raise e #no auth or auth config?
+ g.db = pymongo.MongoClient(app.config['DB_URI']).get_default_database()
@app.route('/')