Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c26b7fc1
authored
Jul 06, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: UserCloudDetails refactor
parent
8306ae57
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
10 deletions
+19
-10
one/models.py
+19
-10
No files found.
one/models.py
View file @
c26b7fc1
...
...
@@ -70,7 +70,7 @@ class UserCloudDetails(models.Model):
try
:
self
.
ssh_key
.
key
=
pub
except
:
except
AttributeError
:
self
.
ssh_key
=
SshKey
(
user
=
self
.
user
,
key
=
pub
)
self
.
ssh_key
.
save
()
self
.
ssh_key_id
=
self
.
ssh_key
.
id
...
...
@@ -79,25 +79,34 @@ class UserCloudDetails(models.Model):
def
reset_smb
(
self
):
"""Generate new Samba password."""
self
.
smb_password
=
pwgen
()
self
.
save
()
def
get_weighted_instance_count
(
self
):
states
=
[
'ACTIVE'
,
'PENDING'
]
credits
=
[
i
.
template
.
instance_type
.
credit
for
i
in
self
.
user
.
instance_set
.
all
()
if
i
.
state
in
(
'ACTIVE'
,
'PENDING'
,
)]
for
i
in
self
.
user
.
instance_set
.
filter
(
state__in
=
states
)]
return
sum
(
credits
)
def
get_instance_pc
(
self
):
return
100
*
self
.
get_weighted_instance_count
()
/
self
.
instance_quota
"""Get what percent of the user's instance quota is in use."""
inst_quota
=
self
.
instance_quota
if
inst_quota
<=
0
:
return
100
else
:
return
100
*
self
.
get_weighted_instance_count
()
/
inst_quota
def
get_weighted_share_count
(
self
):
c
=
0
for
i
in
Share
.
objects
.
filter
(
owner
=
self
.
user
)
.
all
():
c
=
c
+
i
.
template
.
instance_type
.
credit
*
i
.
instance_limit
return
c
credits
=
[
i
.
template
.
instance_type
.
credit
*
i
.
instance_limit
for
i
in
Share
.
objects
.
filter
(
owner
=
self
.
user
)]
return
sum
(
credits
)
def
get_share_pc
(
self
):
assert
self
.
share_quota
>
0
return
100
*
self
.
get_weighted_share_count
()
/
self
.
share_quota
"""Get what percent of the user's share quota is in use."""
share_quota
=
self
.
share_quota
if
share_quota
<=
0
:
return
100
else
:
return
100
*
self
.
get_weighted_share_count
()
/
share_quota
def
set_quota
(
sender
,
instance
,
created
,
**
kwargs
):
...
...
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