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
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
Show 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):
...
@@ -70,7 +70,7 @@ class UserCloudDetails(models.Model):
try
:
try
:
self
.
ssh_key
.
key
=
pub
self
.
ssh_key
.
key
=
pub
except
:
except
AttributeError
:
self
.
ssh_key
=
SshKey
(
user
=
self
.
user
,
key
=
pub
)
self
.
ssh_key
=
SshKey
(
user
=
self
.
user
,
key
=
pub
)
self
.
ssh_key
.
save
()
self
.
ssh_key
.
save
()
self
.
ssh_key_id
=
self
.
ssh_key
.
id
self
.
ssh_key_id
=
self
.
ssh_key
.
id
...
@@ -79,25 +79,34 @@ class UserCloudDetails(models.Model):
...
@@ -79,25 +79,34 @@ class UserCloudDetails(models.Model):
def
reset_smb
(
self
):
def
reset_smb
(
self
):
"""Generate new Samba password."""
"""Generate new Samba password."""
self
.
smb_password
=
pwgen
()
self
.
smb_password
=
pwgen
()
self
.
save
()
def
get_weighted_instance_count
(
self
):
def
get_weighted_instance_count
(
self
):
states
=
[
'ACTIVE'
,
'PENDING'
]
credits
=
[
i
.
template
.
instance_type
.
credit
credits
=
[
i
.
template
.
instance_type
.
credit
for
i
in
self
.
user
.
instance_set
.
all
()
for
i
in
self
.
user
.
instance_set
.
filter
(
state__in
=
states
)]
if
i
.
state
in
(
'ACTIVE'
,
'PENDING'
,
)]
return
sum
(
credits
)
return
sum
(
credits
)
def
get_instance_pc
(
self
):
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
):
def
get_weighted_share_count
(
self
):
c
=
0
credits
=
[
i
.
template
.
instance_type
.
credit
*
i
.
instance_limit
for
i
in
Share
.
objects
.
filter
(
owner
=
self
.
user
)
.
all
():
for
i
in
Share
.
objects
.
filter
(
owner
=
self
.
user
)]
c
=
c
+
i
.
template
.
instance_type
.
credit
*
i
.
instance_limit
return
sum
(
credits
)
return
c
def
get_share_pc
(
self
):
def
get_share_pc
(
self
):
assert
self
.
share_quota
>
0
"""Get what percent of the user's share quota is in use."""
return
100
*
self
.
get_weighted_share_count
()
/
self
.
share_quota
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
):
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