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
65f3c289
authored
Nov 06, 2020
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check template instance limit of user when creating VM
parent
9cfa0f18
Pipeline
#1358
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
+26
-12
circle/dashboard/views/vm.py
+26
-12
No files found.
circle/dashboard/views/vm.py
View file @
65f3c289
...
...
@@ -1166,24 +1166,28 @@ class VmCreate(LoginRequiredMixin, TemplateView):
# limit chekcs
try
:
limit
=
user
.
profile
.
instance_limit
instance_limit
=
user
.
profile
.
instance_limit
template_instance_limit
=
user
.
profile
.
template_instance_limit
except
Exception
as
e
:
logger
.
debug
(
'No profile or instance limit:
%
s'
,
e
)
else
:
try
:
amount
=
int
(
request
.
POST
.
get
(
"amount"
,
1
))
except
:
amount
=
limit
# TODO this should definitely use a Form
current
=
Instance
.
active
.
filter
(
owner
=
user
)
.
count
()
logger
.
debug
(
'current use:
%
d, limit:
%
d'
,
current
,
limit
)
if
current
+
amount
>
limit
:
messages
.
error
(
request
,
_
(
'Instance limit (
%
d) exceeded.'
)
%
limit
)
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'redirect'
:
'/'
}),
content_type
=
"application/json"
)
else
:
return
redirect
(
'/'
)
# TODO this should definitely use a Form
amount
=
instance_limit
instances
=
Instance
.
active
.
filter
(
owner
=
user
)
.
count
()
template_instances
=
template
.
get_user_instances
(
user
)
.
count
()
logger
.
debug
(
'current instance use:
%
d, limit:
%
d'
,
instances
,
instance_limit
)
logger
.
debug
(
'current template instance use:
%
d, limit:
%
d'
,
template_instances
,
template_instance_limit
)
if
instances
+
amount
>
instance_limit
:
return
self
.
_limit_exceeded
(
instance_limit
,
request
)
if
template_instances
+
amount
>
template_instance_limit
:
return
self
.
_limit_exceeded
(
template_instance_limit
,
request
)
create_func
=
(
self
.
__create_normal
if
request
.
POST
.
get
(
"customized"
)
is
None
else
...
...
@@ -1191,6 +1195,16 @@ class VmCreate(LoginRequiredMixin, TemplateView):
return
create_func
(
request
,
template
,
*
args
,
**
kwargs
)
def
_limit_exceeded
(
self
,
limit
,
request
):
messages
.
error
(
request
,
_
(
'Instance limit (
%
d) exceeded.'
)
%
limit
)
if
request
.
is_ajax
():
return
HttpResponse
(
json
.
dumps
({
'redirect'
:
'/'
}),
content_type
=
"application/json"
)
else
:
return
redirect
(
'/'
)
@require_GET
def
get_vm_screenshot
(
request
,
pk
):
...
...
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