Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f978bdee
authored
Feb 09, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store-server: fixed quota
parent
aedd2a46
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
10 deletions
+53
-10
miscellaneous/store-server/CloudStore.py
+10
-5
miscellaneous/store-server/FAKEUserManager.sh
+4
-0
one/models.py
+18
-1
one/static/cloud.js
+8
-1
store/api.py
+11
-2
store/views.py
+2
-1
No files found.
miscellaneous/store-server/CloudStore.py
View file @
f978bdee
...
...
@@ -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
.
j
os
n
[
'QUOTA'
]
quota
=
request
.
j
so
n
[
'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
):
...
...
miscellaneous/store-server/FAKEUserManager.sh
View file @
f978bdee
...
...
@@ -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
...
...
one/models.py
View file @
f978bdee
...
...
@@ -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
()
...
...
one/static/cloud.js
View file @
f978bdee
...
...
@@ -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
()
{
...
...
store/api.py
View file @
f978bdee
...
...
@@ -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
...
...
store/views.py
View file @
f978bdee
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment