Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
d4aef292
authored
May 22, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: started refactoring model
parent
41694da4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
one/models.py
+8
-11
No files found.
one/models.py
View file @
d4aef292
...
@@ -53,9 +53,9 @@ class UserCloudDetails(models.Model):
...
@@ -53,9 +53,9 @@ class UserCloudDetails(models.Model):
'accessing store from Linux.'
))
'accessing store from Linux.'
))
ssh_private_key
=
models
.
TextField
(
verbose_name
=
_
(
'SSH key (private)'
),
ssh_private_key
=
models
.
TextField
(
verbose_name
=
_
(
'SSH key (private)'
),
blank
=
True
,
blank
=
True
,
help_text
=
_
(
'Generated SSH private
key
'
help_text
=
_
(
'Generated SSH private '
'
for accessing store from
'
'
key for accessing
'
'Linux.'
))
'
store from
Linux.'
))
share_quota
=
models
.
IntegerField
(
verbose_name
=
_
(
'share quota'
),
share_quota
=
models
.
IntegerField
(
verbose_name
=
_
(
'share quota'
),
default
=
0
)
default
=
0
)
instance_quota
=
models
.
IntegerField
(
verbose_name
=
_
(
'instance quota'
),
instance_quota
=
models
.
IntegerField
(
verbose_name
=
_
(
'instance quota'
),
...
@@ -82,11 +82,10 @@ class UserCloudDetails(models.Model):
...
@@ -82,11 +82,10 @@ class UserCloudDetails(models.Model):
self
.
smb_password
=
pwgen
()
self
.
smb_password
=
pwgen
()
def
get_weighted_instance_count
(
self
):
def
get_weighted_instance_count
(
self
):
c
=
0
credits
=
[
i
.
template
.
instance_type
.
credit
for
i
in
self
.
user
.
instance_set
.
all
():
for
i
in
self
.
user
.
instance_set
.
all
()
if
i
.
state
in
(
'ACTIVE'
,
'PENDING'
,
):
if
i
.
state
in
(
'ACTIVE'
,
'PENDING'
,
)]
c
=
c
+
i
.
template
.
instance_type
.
credit
return
sum
(
credits
)
return
c
def
get_instance_pc
(
self
):
def
get_instance_pc
(
self
):
return
100
*
self
.
get_weighted_instance_count
()
/
self
.
instance_quota
return
100
*
self
.
get_weighted_instance_count
()
/
self
.
instance_quota
...
@@ -106,9 +105,7 @@ def set_quota(sender, instance, created, **kwargs):
...
@@ -106,9 +105,7 @@ def set_quota(sender, instance, created, **kwargs):
try
:
try
:
password
=
instance
.
smb_password
password
=
instance
.
smb_password
quota
=
instance
.
disk_quota
*
1024
quota
=
instance
.
disk_quota
*
1024
key_list
=
[]
key_list
=
[
key
.
key
for
key
in
instance
.
user
.
sshkey_set
.
all
()]
for
key
in
instance
.
user
.
sshkey_set
.
all
():
key_list
.
append
(
key
.
key
)
except
:
except
:
pass
pass
# Create user
# Create user
...
...
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