Commit f978bdee by tarokkk

store-server: fixed quota

parent aedd2a46
......@@ -229,7 +229,7 @@ def set_quota(neptun):
quota = request.json['QUOTA']
except:
abort(400, 'Wrong syntax!')
result = subprocess.call([ROOT_BIN_FOLDER+'/'+USER_MANAGER, 'setquota', neptun, quota, hard_quota(quota)])
result = subprocess.call([ROOT_BIN_FOLDER+'/'+USER_MANAGER, 'setquota', neptun, str(quota), hard_quota(quota)])
if result == 0:
return
elif result == 2:
......@@ -240,25 +240,30 @@ def set_quota(neptun):
@force_ssl
def new_user(neptun):
key_list = []
smbpasswd=''
smbpasswd = ''
quota = ''
try:
smbpasswd = request.json['SMBPASSWD']
quota = request.josn['QUOTA']
quota = request.json['QUOTA']
except:
print "Invalid syntax"
abort(400, 'Invalid syntax')
# Call user creator script
result = subprocess.call([ROOT_BIN_FOLDER+'/'+USER_MANAGER, 'add', neptun, smbpasswd, quota, hard_quota(quota)])
print smbpasswd+" "+str(quota)
result = subprocess.call([ROOT_BIN_FOLDER+'/'+USER_MANAGER, 'add', neptun, smbpasswd, str(quota), hard_quota(quota)])
if result == 0:
try:
for key in request.json['KEYS']:
key_list.append(key)
updateSSHAuthorizedKeys(neptun, key_list)
except:
print "SSH error"
abort(400, 'SSH')
return
elif result == 2:
abort(403, 'User already exist!')
else:
print "Error"
abort(400, 'An error occured!')
......@@ -326,7 +331,7 @@ def upload(hash_num):
# Return hard quota from quota
def hard_quota(quota):
return str(int(quota)*1.25)
return str(int(quota*1.25))
# Define filebuffer for big uploads
def fbuffer(f, chunk_size=4096):
......
......@@ -82,6 +82,10 @@ case $COMMAND in
# echo $(quota -w ${USER_NAME} 2>/dev/null | tail -1 | awk '{ print $2" "$3" "$4 }')
echo "1916 2097152 2621440"
;;
'setquota')
echo "$1 $2 $3 $4" > /tmp/asd
exit 0
;;
*)
echo "Usage: UserManager.sh COMMAND USER PASSWORD"
exit 1
......
......@@ -13,7 +13,7 @@ from one.util import keygen
from school.models import Person, Group
from datetime import timedelta as td
from django.db.models.signals import post_delete, pre_delete
from store.api import StoreApi
import subprocess, tempfile, os, stat, re, base64, struct
......@@ -68,6 +68,23 @@ class UserCloudDetails(models.Model):
def reset_smb(self):
self.smb_password = pwgen()
def set_quota(sender, instance, created, **kwargs):
if not StoreApi.userexist(instance.user.username):
try:
password = instance.smb_password
quota = instance.disk_quota * 1024
key_list = []
for key in instance.user.sshkey_set.all():
key_list.append(key.key)
except:
pass
#Create user
if not StoreApi.createuser(instance.user.username, password, key_list, quota):
pass
else:
StoreApi.set_quota(instance.user.username, instance.disk_quota)
post_save.connect(set_quota, sender=UserCloudDetails)
def reset_keys(sender, instance, created, **kwargs):
if created:
instance.reset_smb()
......
......@@ -162,7 +162,14 @@ $(function() {
$.ajax({
type: 'POST',
url: '/vm/' + state + '/' + id + '/',
success: function(data) {}
success: function(data, b, c) {
if ( state == "resume" ){
window.location.href = '/vm/show/'+id+"/";
}
else {
window.location.reload();
}
}
})
}
$('#new-member').click(function() {
......
......@@ -146,6 +146,15 @@ class StoreApi:
else:
return False
@staticmethod
def set_quota(neptun, quota):
url = settings['store_url']+'/quota/'+neptun
payload = json.dumps({ 'QUOTA' : quota })
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def userexist(neptun):
url = settings['store_url']+'/'+neptun
r = StoreApi.get_request(url)
......@@ -154,9 +163,9 @@ class StoreApi:
else:
return False
@staticmethod
def createuser(neptun, password, key_list):
def createuser(neptun, password, key_list, quota):
url = settings['store_url']+'/new/'+neptun
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list })
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list, 'QUOTA' : quota })
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
return True
......
......@@ -15,13 +15,14 @@ def estabilish_store_user(user):
try:
details = request.user.userclouddetails_set.all()[0]
password = details.smb_password
quota = details.disk_quota
key_list = []
for key in request.user.sshkey_set.all():
key_list.append(key.key)
except:
return HttpResponse('Can not acces to django database!', status_code=404)
#Create user
if not StoreApi.createuser(user,password,key_list):
if not StoreApi.createuser(user, password, key_list, str(quota)):
return HttpResponse('User does not exist on store! And could not create!')
@login_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment