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):
...
@@ -1166,24 +1166,28 @@ class VmCreate(LoginRequiredMixin, TemplateView):
# limit chekcs
# limit chekcs
try
:
try
:
limit
=
user
.
profile
.
instance_limit
instance_limit
=
user
.
profile
.
instance_limit
template_instance_limit
=
user
.
profile
.
template_instance_limit
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
debug
(
'No profile or instance limit:
%
s'
,
e
)
logger
.
debug
(
'No profile or instance limit:
%
s'
,
e
)
else
:
else
:
try
:
try
:
amount
=
int
(
request
.
POST
.
get
(
"amount"
,
1
))
amount
=
int
(
request
.
POST
.
get
(
"amount"
,
1
))
except
:
except
:
amount
=
limit
# TODO this should definitely use a Form
# TODO this should definitely use a Form
current
=
Instance
.
active
.
filter
(
owner
=
user
)
.
count
()
amount
=
instance_limit
logger
.
debug
(
'current use:
%
d, limit:
%
d'
,
current
,
limit
)
instances
=
Instance
.
active
.
filter
(
owner
=
user
)
.
count
()
if
current
+
amount
>
limit
:
template_instances
=
template
.
get_user_instances
(
user
)
.
count
()
messages
.
error
(
request
,
_
(
'Instance limit (
%
d) exceeded.'
)
%
limit
)
logger
.
debug
(
'current instance use:
%
d, limit:
%
d'
,
if
request
.
is_ajax
():
instances
,
instance_limit
)
return
HttpResponse
(
json
.
dumps
({
'redirect'
:
'/'
}),
logger
.
debug
(
'current template instance use:
%
d, limit:
%
d'
,
content_type
=
"application/json"
)
template_instances
,
template_instance_limit
)
else
:
return
redirect
(
'/'
)
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
create_func
=
(
self
.
__create_normal
if
request
.
POST
.
get
(
"customized"
)
is
None
else
request
.
POST
.
get
(
"customized"
)
is
None
else
...
@@ -1191,6 +1195,16 @@ class VmCreate(LoginRequiredMixin, TemplateView):
...
@@ -1191,6 +1195,16 @@ class VmCreate(LoginRequiredMixin, TemplateView):
return
create_func
(
request
,
template
,
*
args
,
**
kwargs
)
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
@require_GET
def
get_vm_screenshot
(
request
,
pk
):
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