def detail(request, cluster_slug, instance, rest=False): """ Display details of virtual machine. """ vm, cluster = get_vm_and_cluster_or_404(cluster_slug, instance) user = request.user cluster_admin = (user.is_superuser or user.has_any_perms(cluster, perms=['admin', 'create_vm'])) if not cluster_admin: perms = user.get_perms(vm) if cluster_admin or 'admin' in perms: admin = True remove = True power = True modify = True migrate = True tags = True else: admin = False remove = 'remove' in perms power = 'power' in perms modify = 'modify' in perms tags = 'tags' in perms migrate = 'migrate' in perms if not (admin or power or remove or modify or tags): # TODO REST raise Http403(_('You do not have permission to view ' 'this virtual machines\'s details')) context = { 'cluster': cluster, 'instance': vm, 'admin': admin, 'cluster_admin': cluster_admin, 'remove': remove, 'power': power, 'modify': modify, 'migrate': migrate, "has_immediate_shutdown": has_shutdown_timeout(cluster), } # check job for pending jobs that should be rendered with a different # detail template. This allows us to reduce the chance that users will do # something strange like rebooting a VM that is being deleted or is not # fully created yet. if vm.pending_delete: template = 'ganeti/virtual_machine/delete_status.html' elif vm.template: template = 'ganeti/virtual_machine/create_status.html' if vm.last_job: context['job'] = vm.last_job else: ct = ContentType.objects.get_for_model(vm) jobs_loc = Job.objects.order_by('-finished') \ .filter(content_type=ct, object_id=vm.pk) if jobs_loc.count() > 0: context['job'] = jobs_loc[0] else: context['job'] = None else: template = 'ganeti/virtual_machine/detail.html' if rest: return context else: return render_to_response(template, context, context_instance=RequestContext(request), )
def test_has_shutdown_timeout(self): cluster = make_mock_cluster("2.5.0") self.assertTrue(has_shutdown_timeout(cluster))
def test_lacks_shutdown_timeout(self): cluster = make_mock_cluster("2.4.0") self.assertFalse(has_shutdown_timeout(cluster))
def detail(request, cluster_slug, instance, rest=False): """ Display details of virtual machine. """ vm, cluster = get_vm_and_cluster_or_404(cluster_slug, instance) user = request.user cluster_admin = user.is_superuser or user.has_perm('admin', cluster) if not cluster_admin: perms = user.get_perms(vm) if cluster_admin or 'admin' in perms: admin = True remove = True power = True modify = True migrate = True tags = True else: admin = False remove = 'remove' in perms power = 'power' in perms modify = 'modify' in perms tags = 'tags' in perms migrate = 'migrate' in perms if not (admin or power or remove or modify or tags): #TODO REST raise Http403(_('You do not have permission to view this virtual machines\'s details')) context = { 'cluster': cluster, 'instance': vm, 'admin':admin, 'cluster_admin':cluster_admin, 'remove':remove, 'power':power, 'modify':modify, 'migrate':migrate, "has_immediate_shutdown": has_shutdown_timeout(cluster), } # check job for pending jobs that should be rendered with a different # detail template. This allows us to reduce the chance that users will do # something strange like rebooting a VM that is being deleted or is not # fully created yet. if vm.pending_delete: template = 'ganeti/virtual_machine/delete_status.html' elif vm.template: template = 'ganeti/virtual_machine/create_status.html' if vm.last_job: context['job'] = vm.last_job else: ct = ContentType.objects.get_for_model(vm) jobs_loc = Job.objects.order_by('-finished') \ .filter(content_type=ct, object_id=vm.pk) if jobs_loc.count() > 0: context['job'] = jobs_loc[0] else: context['job'] = None else: template = 'ganeti/virtual_machine/detail.html' if rest: return context else: return render_to_response(template, context, context_instance=RequestContext(request), )