def view_target(request):
    return_dict = {}
    try:
        if 'name' not in request.GET:
            raise Exception("Malformed request. Please use the menus.")

        target, err = iscsi_stgt.get_target(request.GET['name'])
        if err:
            raise Exception(err)

        if not target:
            raise Exception(
                "Specified target not found. Please use the menus.")

        if "ack" in request.GET:
            if request.GET["ack"] == "lun_created":
                return_dict['ack_message'] = "ISCSI LUN successfully created"
            elif request.GET["ack"] == "lun_deleted":
                return_dict['ack_message'] = "ISCSI LUN successfully deleted"
            elif request.GET["ack"] == "added_acl":
                return_dict[
                    'ack_message'] = "ISCSI target ACL successfully added"
            elif request.GET["ack"] == "removed_acl":
                return_dict[
                    'ack_message'] = "ISCSI target ACL successfully removed"
            elif request.GET["ack"] == "added_initiator_authentication":
                return_dict[
                    'ack_message'] = "ISCSI initiator authentication successfully added"
            elif request.GET["ack"] == "added_target_authentication":
                return_dict[
                    'ack_message'] = "ISCSI target authentication successfully added"
            elif request.GET["ack"] == "removed_initiator_authentication":
                return_dict[
                    'ack_message'] = "ISCSI initiator authentication successfully removed"
            elif request.GET["ack"] == "removed_target_authentication":
                return_dict[
                    'ack_message'] = "ISCSI target authentication successfully removed"

        return_dict["target"] = target

        return django.shortcuts.render_to_response(
            'view_iscsi_target.html',
            return_dict,
            context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'ISCSI target details'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error loading ISCSI target details'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response(
            "logged_in_error.html",
            return_dict,
            context_instance=django.template.context.RequestContext(request))
Exemplo n.º 2
0
def create_iscsi_acl(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(request, [
                                                                 'target_name'])
        if err:
            raise Exception(err)
        if 'target_name' not in req_ret:
            raise Exception(
                "Invalid request, please use the menus.")

        target_name = req_ret['target_name']

        target, err = iscsi_stgt.get_target(target_name)
        if err:
            raise Exception(err)
        if not target:
            raise Exception('Specified target not found')

        if request.method == "GET":
            # Return the form
            initial = {}
            initial['target_name'] = target_name
            form = iscsi_stgt_forms.IscsiAclForm(initial=initial)
            return_dict["form"] = form
            return django.shortcuts.render_to_response("create_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_stgt_forms.IscsiAclForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi_stgt.add_acl(cd['target_name'], cd['acl'])
                if not ret:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception("Unknown error.")
                audit_str = "Added ISCSI ACL %s for target %s" % (
                    cd["acl"], cd['target_name'])
                url = '/view_iscsi_target?name=%s&ack=added_acl' % target_name
                audit.audit("add_iscsi_acl", audit_str, request)
                return django.http.HttpResponseRedirect(url)
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response("create_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Add ISCSI ACL'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error adding ISCSI ACL'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_iscsi_acl(request):
    return_dict = {}
    try:
        req_ret, err = django_utils.get_request_parameter_values(request, [
                                                                 'target_name'])
        if err:
            raise Exception(err)
        if 'target_name' not in req_ret:
            raise Exception(
                "Invalid request, please use the menus.")

        target_name = req_ret['target_name']

        target, err = iscsi_stgt.get_target(target_name)
        if err:
            raise Exception(err)
        if not target:
            raise Exception('Specified target not found')

        if request.method == "GET":
            # Return the form
            initial = {}
            initial['target_name'] = target_name
            form = iscsi_stgt_forms.IscsiAclForm(initial=initial)
            return_dict["form"] = form
            return django.shortcuts.render_to_response("create_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            # Form submission so create
            return_dict = {}
            form = iscsi_stgt_forms.IscsiAclForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                ret, err = iscsi_stgt.add_acl(cd['target_name'], cd['acl'])
                if not ret:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception("Unknown error.")
                audit_str = "Added ISCSI ACL %s for target %s" % (
                    cd["acl"], cd['target_name'])
                url = '/storage_access/view_iscsi_target?name=%s&ack=added_acl' % target_name
                audit.audit("add_iscsi_acl", audit_str, request)
                return django.http.HttpResponseRedirect(url)
            else:
                return_dict["form"] = form
                return django.shortcuts.render_to_response("create_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'Add ISCSI ACL'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error adding ISCSI ACL'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def view_target(request):
    return_dict = {}
    try:
        if 'name' not in request.GET:
            raise Exception("Malformed request. Please use the menus.")

        target, err = iscsi_stgt.get_target(request.GET['name'])
        if err:
            raise Exception(err)

        if not target:
            raise Exception(
                "Specified target not found. Please use the menus.")

        if "ack" in request.GET:
            if request.GET["ack"] == "lun_created":
                return_dict['ack_message'] = "ISCSI LUN successfully created"
            elif request.GET["ack"] == "lun_deleted":
                return_dict['ack_message'] = "ISCSI LUN successfully deleted"
            elif request.GET["ack"] == "added_acl":
                return_dict['ack_message'] = "ISCSI target ACL successfully added"
            elif request.GET["ack"] == "removed_acl":
                return_dict['ack_message'] = "ISCSI target ACL successfully removed"
            elif request.GET["ack"] == "added_initiator_authentication":
                return_dict['ack_message'] = "ISCSI initiator authentication successfully added"
            elif request.GET["ack"] == "added_target_authentication":
                return_dict['ack_message'] = "ISCSI target authentication successfully added"
            elif request.GET["ack"] == "removed_initiator_authentication":
                return_dict['ack_message'] = "ISCSI initiator authentication successfully removed"
            elif request.GET["ack"] == "removed_target_authentication":
                return_dict['ack_message'] = "ISCSI target authentication successfully removed"

        return_dict["target"] = target

        return django.shortcuts.render_to_response('view_iscsi_target.html', return_dict, context_instance=django.template.context.RequestContext(request))
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'ISCSI target details'
        return_dict['tab'] = 'view_iscsi_targets_tab'
        return_dict["error"] = 'Error loading ISCSI target details'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))