Example #1
0
    def test_form_save(self):
        """
        Test form for creation of VirtualMachineTemplate on save

        Verifies:
            * Form has valid data
            * VirtualMachineTemplate is created
        """
        for i, user in enumerate(self.users):
            data = self.template_data.copy()
            template_name = 'template_save_%s' % i
            data['template_name'] = template_name
            self.assertFalse(VirtualMachineTemplate.objects.filter(template_name=template_name).exists())
            form = VirtualMachineTemplateForm(data, user=user)
            self.assertTrue(form.is_bound)
            self.assertTrue(form.is_valid())
            form.save()
            self.assertTrue(VirtualMachineTemplate.objects.filter(template_name=template_name).exists())
Example #2
0
    def test_form_save(self):
        """
        Test form for creation of VirtualMachineTemplate on save

        Verifies:
            * Form has valid data
            * VirtualMachineTemplate is created
        """
        for i, user in enumerate(self.users):
            data = self.template_data.copy()
            template_name = 'template_save_%s' % i
            data['template_name'] = template_name
            self.assertFalse(
                VirtualMachineTemplate.objects.filter(
                    template_name=template_name).exists())
            form = VirtualMachineTemplateForm(data, user=user)
            self.assertTrue(form.is_bound)
            self.assertTrue(form.is_valid())
            form.save()
            self.assertTrue(
                VirtualMachineTemplate.objects.filter(
                    template_name=template_name).exists())
Example #3
0
def create(request):
    """
    View to create a new VirtualMachineTemplate.

    @param template Will populate the form with data from a template.
    """
    user = request.user
    if request.method == "GET":
        form = VirtualMachineTemplateForm(user=user)
    elif request.method == "POST":
        form = VirtualMachineTemplateForm(request.POST, user=user)
        if form.is_valid():
            form_obj = form.save()
            return HttpResponseRedirect(reverse('template-detail',
                args=[form_obj.cluster.slug, form_obj]))

    return render_to_response('ganeti/vm_template/create.html', {
        'form':form,
        'action':reverse('template-create'),
        },
        context_instance = RequestContext(request)
    )
Example #4
0
def create(request):
    """
    View to create a new VirtualMachineTemplate.

    @param template Will populate the form with data from a template.
    """
    user = request.user
    if request.method == "GET":
        form = VirtualMachineTemplateForm(user=user)
    elif request.method == "POST":
        form = VirtualMachineTemplateForm(request.POST, user=user)
        if form.is_valid():
            form_obj = form.save()
            return HttpResponseRedirect(reverse('template-detail',
                args=[form_obj.cluster.slug, form_obj]))

    return render_to_response('ganeti/vm_template/create.html', {
        'form':form,
        'action':reverse('template-create'),
        },
        context_instance = RequestContext(request)
    )
Example #5
0
def edit(request, cluster_slug=None, template=None):
    """
    View to edit a new VirtualMachineTemplate.
    """
    user = request.user
    if cluster_slug:
        cluster = get_object_or_404(Cluster, slug=cluster_slug)
        if not (
            user.is_superuser or
            user.has_perm('admin', cluster) or
            user.has_perm('create_vm', cluster)
            ):
            raise Http403(NO_PRIVS)

    if cluster_slug and template:
        obj = get_object_or_404(VirtualMachineTemplate, template_name=template,
                                cluster__slug=cluster_slug)

    if request.method == "GET":
        initial = vars(obj)
        initial['cluster'] = cluster.id
        form = VirtualMachineTemplateForm(user=user, initial=initial)
    elif request.method == "POST":
        form = VirtualMachineTemplateForm(request.POST, user=user)
        if form.is_valid():
            form.instance.pk = obj.pk
            form_obj = form.save()
            return HttpResponseRedirect(reverse('template-detail',
                args=[form_obj.cluster.slug, form_obj]))

    return render_to_response('ganeti/vm_template/create.html', {
        'form':form,
        'action':reverse('template-edit', args=[cluster_slug, obj]),
        'template':obj,
        },
        context_instance = RequestContext(request)
    )
Example #6
0
def edit(request, cluster_slug=None, template=None):
    """
    View to edit a new VirtualMachineTemplate.
    """
    user = request.user
    if cluster_slug:
        cluster = get_object_or_404(Cluster, slug=cluster_slug)
        if not (
            user.is_superuser or
            user.has_perm('admin', cluster) or
            user.has_perm('create_vm', cluster)
            ):
            raise Http403(NO_PRIVS)

    if cluster_slug and template:
        obj = get_object_or_404(VirtualMachineTemplate, template_name=template,
                                cluster__slug=cluster_slug)

    if request.method == "GET":
        initial = vars(obj)
        initial['cluster'] = cluster.id
        form = VirtualMachineTemplateForm(user=user, initial=initial)
    elif request.method == "POST":
        form = VirtualMachineTemplateForm(request.POST, user=user)
        if form.is_valid():
            form.instance.pk = obj.pk
            form_obj = form.save()
            return HttpResponseRedirect(reverse('template-detail',
                args=[form_obj.cluster.slug, form_obj]))

    return render_to_response('ganeti/vm_template/create.html', {
        'form':form,
        'action':reverse('template-edit', args=[cluster_slug, obj]),
        'template':obj,
        },
        context_instance = RequestContext(request)
    )