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
2dea86ba
authored
Feb 11, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: Added Share quota
parent
82dccc14
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
5 deletions
+11
-5
one/models.py
+8
-2
one/templates/home.html
+2
-2
one/views.py
+1
-1
No files found.
one/models.py
View file @
2dea86ba
...
...
@@ -169,6 +169,12 @@ class Share(models.Model):
per_user_limit
=
models
.
IntegerField
(
verbose_name
=
_
(
'per user limit'
),
help_text
=
_
(
'Maximal count of instances launchable by a single user.'
))
def
get_running_or_stopped
(
self
):
return
Instance
.
objects
.
all
()
.
exclude
(
state
=
'DONE'
)
.
filter
(
share
=
self
)
.
count
()
def
get_running
(
self
):
return
Instance
.
objects
.
all
()
.
exclude
(
state
=
'DONE'
)
.
exclude
(
state
=
'STOPPED'
)
.
filter
(
share
=
self
)
.
count
()
def
get_instance_pc
(
self
):
return
float
(
self
.
get_running
())
/
self
.
instance_limit
*
100
"""
Virtual disks automatically synchronized with OpenNebula.
"""
...
...
@@ -417,10 +423,10 @@ class Instance(models.Model):
Submit a new instance to OpenNebula.
"""
@classmethod
def
submit
(
cls
,
template
,
owner
,
extra
=
""
):
def
submit
(
cls
,
template
,
owner
,
extra
=
""
,
share
=
None
):
from
django.template.defaultfilters
import
escape
out
=
""
inst
=
Instance
(
pw
=
pwgen
(),
template
=
template
,
owner
=
owner
)
inst
=
Instance
(
pw
=
pwgen
(),
template
=
template
,
owner
=
owner
,
share
=
share
)
inst
.
save
()
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
as
f
:
os
.
chmod
(
f
.
name
,
stat
.
S_IRUSR
|
stat
.
S_IWUSR
|
stat
.
S_IRGRP
|
stat
.
S_IROTH
)
...
...
one/templates/home.html
View file @
2dea86ba
...
...
@@ -26,11 +26,11 @@
<li
class=
"wm"
>
<div
class=
"summary"
>
<div
class=
"quota"
>
<div
class=
"used"
style=
"width:
40
%"
></div>
<div
class=
"used"
style=
"width:
{{ s.get_instance_pc }}
%"
></div>
</div>
<div
class=
"name wm-on"
>
{{s.name}}
</div>
<div
class=
"status"
>
3/10
{{s.get_running}}/{{s.instance_limit}}
</div>
<div
class=
"clear"
></div>
</div>
...
...
one/views.py
View file @
2dea86ba
...
...
@@ -210,7 +210,7 @@ def vm_new(request, template=None, share=None):
t
.
save
()
base
=
t
try
:
i
=
Instance
.
submit
(
base
,
request
.
user
,
extra
=
"<RECONTEXT>YES</RECONTEXT>"
)
i
=
Instance
.
submit
(
base
,
request
.
user
,
extra
=
"<RECONTEXT>YES</RECONTEXT>"
,
share
=
share
)
return
redirect
(
i
)
except
Exception
as
e
:
logger
.
error
(
'Failed to create virtual machine.'
+
unicode
(
e
))
...
...
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