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
5b503e39
authored
Aug 31, 2016
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard, vm: rework boot menu toggling
parent
1bb04667
Pipeline
#186
failed with stage
in 0 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
35 deletions
+37
-35
circle/dashboard/forms.py
+9
-4
circle/dashboard/static/dashboard/vm-details.js
+2
-0
circle/dashboard/templates/dashboard/vm-detail/resources.html
+9
-2
circle/dashboard/views/vm.py
+15
-27
circle/vm/operations.py
+2
-2
No files found.
circle/dashboard/forms.py
View file @
5b503e39
...
...
@@ -1440,13 +1440,18 @@ class ToggleBootMenuForm(forms.ModelForm):
'data-off'
:
_
(
'Off'
)})
}
def
__init__
(
self
,
*
args
,
**
kwargs
):
disabled
=
kwargs
.
pop
(
'disabled'
)
super
(
ToggleBootMenuForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
if
disabled
:
self
.
fields
[
'boot_menu'
]
.
widget
.
attrs
[
'disabled'
]
=
'disabled'
@property
def
helper
(
self
):
helper
=
FormHelper
()
helper
.
form_show_labels
=
True
helper
.
form_action
=
\
reverse_lazy
(
"dashboard.instance.op.toggle_bootmenu"
,
kwargs
=
{
'pk'
:
self
.
instance
.
pk
})
helper
.
form_action
=
(
reverse_lazy
(
"dashboard.instance.op.toggle_boot_menu"
,
kwargs
=
{
'pk'
:
self
.
instance
.
pk
}))
return
helper
...
...
circle/dashboard/static/dashboard/vm-details.js
View file @
5b503e39
...
...
@@ -256,4 +256,6 @@ $(function() {
$
(
this
).
parents
(
"form"
).
submit
();
});
$
(
'#boot-menu-save-btn'
).
hide
();
});
circle/dashboard/templates/dashboard/vm-detail/resources.html
View file @
5b503e39
...
...
@@ -103,11 +103,18 @@
{% endif %}
{% if
toggle_boot_menu_form
%}
{% if
op.toggle_boot_menu
%}
<hr
/>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
{% crispy toggle_boot_menu_form %}
<form
action=
"{{ op.toggle_boot_menu.get_url }}"
method=
"POST"
>
{% csrf_token %}
{{ toggle_boot_menu_form.boot_menu|as_crispy_field }}
<input
type=
"submit"
id=
"boot-menu-save-btn"
class=
"btn btn-success"
value=
"{% trans "
Save
"
%}"
{%
if
op
.
toggle_boot_menu
.
disabled
%}
disabled
{%
endif
%}
/>
</form>
</div>
</div>
{% endif %}
...
...
circle/dashboard/views/vm.py
View file @
5b503e39
...
...
@@ -175,9 +175,10 @@ class VmDetailView(GraphMixin, CheckedDetailView):
context
[
'traits_form'
]
=
TraitsForm
(
instance
=
instance
)
context
[
'raw_data_form'
]
=
RawDataForm
(
instance
=
instance
)
if
is_owner
and
user
.
has_perm
(
"vm.toggle_boot_menu"
):
context
[
'toggle_boot_menu_form'
]
=
\
ToggleBootMenuForm
(
instance
=
instance
)
context
[
'toggle_boot_menu_form'
]
=
ToggleBootMenuForm
(
instance
=
instance
,
disabled
=
hasattr
(
context
[
'op'
][
'toggle_boot_menu'
],
'disabled'
))
# resources change perm
context
[
'can_change_resources'
]
=
self
.
request
.
user
.
has_perm
(
...
...
@@ -592,33 +593,20 @@ class VmResourcesChangeView(VmOperationView):
*
args
,
**
kwargs
)
class
VmToggleBootMenuUpdate
(
VmOperationView
):
op
=
'toggle_bootmenu'
class
VmToggleBootMenuUpdate
(
FormOperationMixin
,
VmOperationView
):
op
=
'toggle_boot
_
menu'
icon
=
"wrench"
show_in_toolbar
=
False
wait_for_result
=
0.5
form_class
=
ToggleBootMenuForm
def
post
(
self
,
request
,
extra
=
None
,
*
args
,
**
kwargs
):
instance
=
get_object_or_404
(
Instance
,
pk
=
kwargs
[
'pk'
])
form
=
ToggleBootMenuForm
(
request
.
POST
,
instance
=
instance
)
if
not
form
.
is_valid
():
for
f
in
form
.
errors
:
messages
.
error
(
request
,
"<strong>
%
s</strong>:
%
s"
%
(
f
,
form
.
errors
[
f
]
.
as_text
()
))
if
request
.
is_ajax
():
# this is not too nice
store
=
messages
.
get_messages
(
request
)
store
.
used
=
True
return
JsonResponse
({
'success'
:
False
,
'messages'
:
[
unicode
(
m
)
for
m
in
store
]})
else
:
return
HttpResponseRedirect
(
instance
.
get_absolute_url
()
+
"#resources"
)
else
:
extra
=
form
.
cleaned_data
return
super
(
VmToggleBootMenuUpdate
,
self
)
.
post
(
request
,
extra
,
*
args
,
**
kwargs
)
def
get_form_kwargs
(
self
):
instance
=
self
.
get_op
()
.
instance
disabled
=
hasattr
(
self
,
'disabled'
)
val
=
super
(
VmToggleBootMenuUpdate
,
self
)
.
get_form_kwargs
()
val
[
'instance'
]
=
instance
val
[
'disabled'
]
=
disabled
return
val
class
TokenOperationView
(
OperationView
):
...
...
@@ -814,7 +802,7 @@ vm_ops = OrderedDict([
(
'add_port'
,
VmPortAddView
),
(
'renew'
,
VmRenewView
),
(
'resources_change'
,
VmResourcesChangeView
),
(
'toggle_bootmenu'
,
VmToggleBootMenuUpdate
),
(
'toggle_boot
_
menu'
,
VmToggleBootMenuUpdate
),
(
'password_reset'
,
VmOperationView
.
factory
(
op
=
'password_reset'
,
icon
=
'unlock'
,
effect
=
'warning'
,
show_in_toolbar
=
False
,
wait_for_result
=
0.5
,
with_reload
=
True
)),
...
...
circle/vm/operations.py
View file @
5b503e39
...
...
@@ -1404,12 +1404,12 @@ class ResourcesOperation(InstanceOperation):
@register_operation
class
ToggleBootMenuOperation
(
InstanceOperation
):
id
=
'toggle_bootmenu'
id
=
'toggle_boot
_
menu'
name
=
_
(
"toggle boot menu"
)
description
=
_
(
"Turn on/off boot menu."
)
acl_level
=
"owner"
required_perms
=
(
'vm.toggle_boot_menu'
,
)
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
accept_states
=
(
'STOPPED'
,
)
def
_operation
(
self
,
user
,
activity
,
boot_menu
):
self
.
instance
.
boot_menu
=
boot_menu
...
...
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