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
a77de49a
authored
Apr 16, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add vm ops to vm-detail context
parent
deeeddce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
circle/common/operations.py
+14
-0
circle/dashboard/views.py
+11
-5
No files found.
circle/common/operations.py
View file @
a77de49a
...
...
@@ -13,6 +13,7 @@ class Operation(object):
"""
async_queue
=
'localhost.man'
required_perms
=
()
do_not_call_in_templates
=
True
def
__call__
(
self
,
**
kwargs
):
return
self
.
call
(
**
kwargs
)
...
...
@@ -127,6 +128,19 @@ class OperatedMixin(object):
raise
AttributeError
(
"
%
r object has no attribute
%
r"
%
(
self
.
__class__
.
__name__
,
name
))
def
get_available_operations
(
self
,
user
):
"""Yield Operations that match permissions of user and preconditions.
"""
for
name
in
getattr
(
self
,
operation_registry_name
,
{}):
try
:
op
=
getattr
(
self
,
name
)
op
.
check_auth
(
user
)
op
.
check_precond
()
except
:
pass
# unavailable
else
:
yield
op
def
register_operation
(
target_cls
,
op_cls
,
op_id
=
None
):
"""Register the specified operation with the target class.
...
...
circle/dashboard/views.py
View file @
a77de49a
...
...
@@ -203,7 +203,8 @@ class VmDetailView(CheckedDetailView):
context
.
update
({
'graphite_enabled'
:
VmGraphView
.
get_graphite_url
()
is
not
None
,
'vnc_url'
:
reverse_lazy
(
"dashboard.views.detail-vnc"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
'ops'
:
list
(
instance
.
get_available_operations
(
self
.
request
.
user
)),
})
# activity data
...
...
@@ -1589,23 +1590,28 @@ def vm_activity(request, pk):
raise
PermissionDenied
()
response
=
{}
only_status
=
request
.
GET
.
get
(
"only_status"
)
only_status
=
request
.
GET
.
get
(
"only_status"
,
"false"
)
response
[
'human_readable_status'
]
=
instance
.
get_status_display
()
response
[
'status'
]
=
instance
.
status
response
[
'icon'
]
=
instance
.
get_status_icon
()
if
only_status
==
"false"
:
# instance activity
context
=
{
'instance'
:
instance
,
'activities'
:
InstanceActivity
.
objects
.
filter
(
instance
=
instance
,
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
()
)
.
order_by
(
'-started'
)
.
select_related
(),
'ops'
:
instance
.
get_available_operations
(
request
.
user
),
}
activities
=
render_to_string
(
response
[
'activities'
]
=
render_to_string
(
"dashboard/vm-detail/_activity-timeline.html"
,
RequestContext
(
request
,
context
),
)
response
[
'activities'
]
=
activities
response
[
'ops'
]
=
render_to_string
(
"dashboard/vm-detail/_operations.html"
,
RequestContext
(
request
,
context
),
)
return
HttpResponse
(
json
.
dumps
(
response
),
...
...
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