Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
28e65ce1
authored
Mar 11, 2015
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
request: add resource request
parent
d99970c2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
165 additions
and
13 deletions
+165
-13
circle/dashboard/static/dashboard/dashboard.less
+16
-1
circle/dashboard/static/dashboard/vm-details.js
+16
-0
circle/dashboard/templates/dashboard/vm-detail/resources.html
+28
-8
circle/request/forms.py
+4
-0
circle/request/templates/request/request-resource.html
+37
-0
circle/request/urls.py
+4
-2
circle/request/views.py
+60
-2
No files found.
circle/dashboard/static/dashboard/dashboard.less
View file @
28e65ce1
...
...
@@ -1270,6 +1270,21 @@ textarea[name="new_members"] {
margin-top: 20px;
}
#vm-renew-request-lease {
#vm-renew-request-lease
, #vm-request-resource-form
{
display: none;
}
.label-100 {
display: block;
width: 100%;
}
#modify-the-resources {
font-size: 18px;
display: none;
}
#vm-request-resource-form textarea {
max-width: 500px;
height: 150px;
}
circle/dashboard/static/dashboard/vm-details.js
View file @
28e65ce1
...
...
@@ -228,4 +228,20 @@ $(function() {
e
.
preventDefault
();
});
$
(
"#vm-request-resource"
).
click
(
function
(
e
)
{
$
(
".cpu-priority-slider, .cpu-count-slider, .ram-slider"
).
simpleSlider
(
"setDisabled"
,
false
);
$
(
".ram-input, .cpu-count-input, .cpu-priority-input"
).
prop
(
"disabled"
,
false
);
$
(
"#vm-details-resources-form"
).
prop
(
"action"
,
$
(
this
).
prop
(
"href"
));
$
(
"#vm-request-resource-form"
).
show
();
$
(
"#modify-the-resources"
).
show
();
$
(
this
).
hide
();
$
(
"html, body"
).
animate
({
scrollTop
:
$
(
"#modify-the-resources"
).
offset
().
top
-
60
});
return
e
.
preventDefault
();
});
});
circle/dashboard/templates/dashboard/vm-detail/resources.html
View file @
28e65ce1
...
...
@@ -2,19 +2,39 @@
{% load sizefieldtags %}
{% load crispy_forms_tags %}
<div
class=
"label label-info label-100"
id=
"modify-the-resources"
>
{% trans "Modify the resources" %}
</div>
<form
method=
"POST"
action=
"{{ op.resources_change.get_url }}"
id=
"vm-details-resources-form"
>
{% csrf_token %}
{% include "dashboard/_resources-sliders.html" with field_priority=resources_form.priority field_num_cores=resources_form.num_cores field_ram_size=resources_form.ram_size %}
{% if op.resources_change %}
<button
type=
"submit"
class=
"btn btn-success btn-sm change-resources-button"
id=
"vm-details-resources-save"
data-vm=
"{{ instance.pk }}"
{%
if
op
.
resources_change
.
disabled
%}
disabled
{%
endif
%}
>
<i
class=
"fa fa-floppy-o"
></i>
{% trans "Save resources" %}
</button>
<span
class=
"change-resources-help"
{%
if
not
op
.
resources_change
.
disabled
%}
style=
"display: none;"
{%
endif
%}
>
{% trans "Stop your VM to change resources." %}
</span>
<button
type=
"submit"
class=
"btn btn-success btn-sm change-resources-button"
id=
"vm-details-resources-save"
data-vm=
"{{ instance.pk }}"
{%
if
op
.
resources_change
.
disabled
%}
disabled
{%
endif
%}
>
<i
class=
"fa fa-floppy-o"
></i>
{% trans "Save resources" %}
</button>
<span
class=
"change-resources-help"
{%
if
not
op
.
resources_change
.
disabled
%}
style=
"display: none;"
{%
endif
%}
>
{% trans "Stop your VM to change resources." %}
</span>
{% else %}
<div
id=
"vm-request-resource-form"
>
<div
class=
"form-group"
>
<label>
{% trans "Reason" %}*
</label>
<textarea
class=
"form-control"
name=
"reason"
></textarea>
</div>
<input
type=
"submit"
class=
"btn btn-success btn-sm"
/>
</div>
<a
href=
"{% url "
request
.
views
.
request-resource
"
vm_pk=
object.pk
%}"
class=
"btn btn-primary btn-sm"
id=
"vm-request-resource"
>
<i
class=
"fa fa-tasks"
></i>
{% trans "Request more resource" %}
</a>
{% endif %}
</form>
...
...
circle/request/forms.py
View file @
28e65ce1
...
...
@@ -10,6 +10,7 @@ from crispy_forms.layout import Submit
from
request.models
import
(
LeaseType
,
TemplateAccessType
,
TemplateAccessAction
,
)
from
dashboard.forms
import
VmResourcesForm
class
LeaseTypeForm
(
ModelForm
):
...
...
@@ -54,3 +55,6 @@ class LeaseRequestForm(Form):
lease
=
ModelChoiceField
(
LeaseType
.
objects
.
all
(),
label
=
_
(
"Lease"
))
reason
=
CharField
(
widget
=
forms
.
Textarea
)
class
ResourceRequestForm
(
VmResourcesForm
):
reason
=
CharField
(
widget
=
forms
.
Textarea
)
circle/request/templates/request/request-resource.html
0 → 100644
View file @
28e65ce1
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
<div
class=
"row"
>
<div
class=
"col-md-12"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h3
class=
"no-margin"
>
<i
class=
"fa fa-tasks"
></i>
{% trans "Request new resources" %}
</h3>
</div>
<div
class=
"panel-body"
>
<form
action=
"{% url "
request
.
views
.
request-resource
"
vm_pk=
vm.pk
%}"
method=
"POST"
>
{% csrf_token %}
<div
class=
"form-group"
>
<label>
{% trans "Virtual machine" %}
</label>
<div
class=
"controls"
>
<a
href=
"{{ vm.get_absolute_url }}"
>
{{ vm.name }}
</a>
</div>
</div>
{% include "display-form-errors.html" %}
{% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %}
{{ form.reason|as_crispy_field }}
<button
type=
"submit"
class=
"btn btn-success"
>
{% trans "Request new resources" %}
</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
circle/request/urls.py
View file @
28e65ce1
...
...
@@ -22,7 +22,7 @@ from .views import (
RequestList
,
RequestDetail
,
RequestTypeList
,
LeaseTypeCreate
,
LeaseTypeDetail
,
TemplateAccessTypeCreate
,
TemplateAccessTypeDetail
,
TemplateRequestView
,
LeaseRequestView
,
TemplateRequestView
,
LeaseRequestView
,
ResourceRequestView
,
)
urlpatterns
=
patterns
(
...
...
@@ -49,5 +49,7 @@ urlpatterns = patterns(
url
(
r'template/$'
,
TemplateRequestView
.
as_view
(),
name
=
"request.views.request-template"
),
url
(
r'lease/(?P<vm_pk>\d+)/$'
,
LeaseRequestView
.
as_view
(),
name
=
"request.views.request-lease"
)
name
=
"request.views.request-lease"
),
url
(
r'resource/(?P<vm_pk>\d+)/$'
,
ResourceRequestView
.
as_view
(),
name
=
"request.views.request-resource"
),
)
circle/request/views.py
View file @
28e65ce1
...
...
@@ -11,7 +11,7 @@ from django_tables2 import SingleTableView
from
request.models
import
(
Request
,
TemplateAccessType
,
LeaseType
,
TemplateAccessAction
,
ExtendLeaseAction
,
ExtendLeaseAction
,
ResourceChangeAction
,
)
from
vm.models
import
Instance
from
request.tables
import
(
...
...
@@ -19,8 +19,9 @@ from request.tables import (
)
from
request.forms
import
(
LeaseTypeForm
,
TemplateAccessTypeForm
,
TemplateRequestForm
,
LeaseRequestForm
,
LeaseRequestForm
,
ResourceRequestForm
,
)
from
dashboard.forms
import
VmResourcesForm
class
RequestList
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SingleTableView
):
...
...
@@ -153,3 +154,60 @@ class LeaseRequestView(FormView):
req
.
save
()
return
redirect
(
vm
.
get_absolute_url
())
class
ResourceRequestView
(
FormView
):
form_class
=
ResourceRequestForm
template_name
=
"request/request-resource.html"
def
get_vm
(
self
):
return
get_object_or_404
(
Instance
,
pk
=
self
.
kwargs
[
'vm_pk'
])
def
dispatch
(
self
,
*
args
,
**
kwargs
):
vm
=
self
.
get_vm
()
user
=
self
.
request
.
user
if
not
vm
.
has_level
(
user
,
"user"
):
raise
PermissionDenied
()
return
super
(
ResourceRequestView
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
ResourceRequestView
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'vm'
]
=
self
.
get_vm
()
return
context
def
get_form_kwargs
(
self
):
kwargs
=
super
(
ResourceRequestView
,
self
)
.
get_form_kwargs
()
kwargs
[
'can_edit'
]
=
True
kwargs
[
'instance'
]
=
self
.
get_vm
()
return
kwargs
def
get_initial
(
self
):
vm
=
self
.
get_vm
()
initial
=
super
(
ResourceRequestView
,
self
)
.
get_initial
()
initial
[
'num_cores'
]
=
vm
.
num_cores
initial
[
'priority'
]
=
vm
.
priority
initial
[
'ram_size'
]
=
vm
.
ram_size
return
initial
def
form_valid
(
self
,
form
):
vm
=
self
.
get_vm
()
data
=
form
.
cleaned_data
user
=
self
.
request
.
user
rc
=
ResourceChangeAction
(
instance
=
vm
,
num_cores
=
data
[
'num_cores'
],
priority
=
data
[
'priority'
],
ram_size
=
data
[
'ram_size'
],
)
rc
.
save
()
req
=
Request
(
user
=
user
,
reason
=
data
[
'reason'
],
type
=
Request
.
TYPES
.
resource
,
action
=
rc
)
req
.
save
()
return
redirect
(
vm
.
get_absolute_url
())
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