Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5bf0da3b
authored
Jul 15, 2016
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add ToggleBootMenuOperation and VmToggleBootMenuUpdate morph to VmOperationView
parent
01f0294e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
20 deletions
+53
-20
circle/dashboard/views/vm.py
+32
-20
circle/vm/operations.py
+21
-0
No files found.
circle/dashboard/views/vm.py
View file @
5bf0da3b
...
@@ -328,26 +328,6 @@ class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView):
...
@@ -328,26 +328,6 @@ class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView):
return
self
.
get_object
()
.
get_absolute_url
()
+
"#resources"
return
self
.
get_object
()
.
get_absolute_url
()
+
"#resources"
class
VmToggleBootMenuUpdate
(
LoginRequiredMixin
,
UpdateView
):
form_class
=
ToggleBootMenuForm
model
=
Instance
def
get
(
self
,
*
args
,
**
kwargs
):
raise
Http404
()
def
form_valid
(
self
,
form
):
user
=
self
.
request
.
user
is_owner
=
form
.
instance
.
has_level
(
user
,
"owner"
)
if
not
(
is_owner
and
user
.
has_perm
(
"vm.toggle_boot_menu"
)):
raise
PermissionDenied
()
return
super
(
VmToggleBootMenuUpdate
,
self
)
.
form_valid
(
form
)
def
get_success_url
(
self
):
return
self
.
get_object
()
.
get_absolute_url
()
+
"#resources"
class
VmOperationView
(
AjaxOperationMixin
,
OperationView
):
class
VmOperationView
(
AjaxOperationMixin
,
OperationView
):
model
=
Instance
model
=
Instance
...
@@ -612,6 +592,38 @@ class VmResourcesChangeView(VmOperationView):
...
@@ -612,6 +592,38 @@ class VmResourcesChangeView(VmOperationView):
*
args
,
**
kwargs
)
*
args
,
**
kwargs
)
class
VmToggleBootMenuUpdate
(
VmOperationView
):
op
=
'toggle_bootmenu'
icon
=
"save"
show_in_toolbar
=
False
wait_for_result
=
0.5
def
post
(
self
,
request
,
extra
=
None
,
*
args
,
**
kwargs
):
if
extra
is
None
:
extra
=
{}
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
)
class
TokenOperationView
(
OperationView
):
class
TokenOperationView
(
OperationView
):
"""Abstract operation view with token support.
"""Abstract operation view with token support.
...
...
circle/vm/operations.py
View file @
5bf0da3b
...
@@ -1403,6 +1403,27 @@ class ResourcesOperation(InstanceOperation):
...
@@ -1403,6 +1403,27 @@ class ResourcesOperation(InstanceOperation):
@register_operation
@register_operation
class
ToggleBootMenuOperation
(
InstanceOperation
):
id
=
'toggle_bootmenu'
name
=
_
(
"toggle boot menu"
)
description
=
_
(
"Turn on/off boot menu."
)
acl_level
=
"owner"
required_perms
=
(
'vm.change_resources'
,
)
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
def
_operation
(
self
,
user
,
activity
,
boot_menu
):
self
.
instance
.
boot_menu
=
boot_menu
self
.
instance
.
full_clean
()
self
.
instance
.
save
()
return
create_readable
(
ugettext_noop
(
"Boot menu toggled:
%(boot_menu)
s"
),
boot_menu
=
"ON"
if
boot_menu
else
"OFF"
)
@register_operation
class
PasswordResetOperation
(
RemoteAgentOperation
):
class
PasswordResetOperation
(
RemoteAgentOperation
):
id
=
'password_reset'
id
=
'password_reset'
name
=
_
(
"password reset"
)
name
=
_
(
"password reset"
)
...
...
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