Commit a77de49a by Őry Máté

dashboard: add vm ops to vm-detail context

parent deeeddce
...@@ -13,6 +13,7 @@ class Operation(object): ...@@ -13,6 +13,7 @@ class Operation(object):
""" """
async_queue = 'localhost.man' async_queue = 'localhost.man'
required_perms = () required_perms = ()
do_not_call_in_templates = True
def __call__(self, **kwargs): def __call__(self, **kwargs):
return self.call(**kwargs) return self.call(**kwargs)
...@@ -127,6 +128,19 @@ class OperatedMixin(object): ...@@ -127,6 +128,19 @@ class OperatedMixin(object):
raise AttributeError("%r object has no attribute %r" % raise AttributeError("%r object has no attribute %r" %
(self.__class__.__name__, name)) (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): def register_operation(target_cls, op_cls, op_id=None):
"""Register the specified operation with the target class. """Register the specified operation with the target class.
......
...@@ -203,7 +203,8 @@ class VmDetailView(CheckedDetailView): ...@@ -203,7 +203,8 @@ class VmDetailView(CheckedDetailView):
context.update({ context.update({
'graphite_enabled': VmGraphView.get_graphite_url() is not None, 'graphite_enabled': VmGraphView.get_graphite_url() is not None,
'vnc_url': reverse_lazy("dashboard.views.detail-vnc", '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 # activity data
...@@ -1589,23 +1590,28 @@ def vm_activity(request, pk): ...@@ -1589,23 +1590,28 @@ def vm_activity(request, pk):
raise PermissionDenied() raise PermissionDenied()
response = {} 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['human_readable_status'] = instance.get_status_display()
response['status'] = instance.status response['status'] = instance.status
response['icon'] = instance.get_status_icon() response['icon'] = instance.get_status_icon()
if only_status == "false": # instance activity if only_status == "false": # instance activity
context = { context = {
'instance': instance,
'activities': InstanceActivity.objects.filter( 'activities': InstanceActivity.objects.filter(
instance=instance, parent=None 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", "dashboard/vm-detail/_activity-timeline.html",
RequestContext(request, context), RequestContext(request, context),
) )
response['activities'] = activities response['ops'] = render_to_string(
"dashboard/vm-detail/_operations.html",
RequestContext(request, context),
)
return HttpResponse( return HttpResponse(
json.dumps(response), json.dumps(response),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment