Exemplo n.º 1
0
def storages(request, host_id):
    """
    Storage pool block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/login")

    errors = []
    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmStorages(compute.hostname, compute.login, compute.password, compute.type)
        storages = conn.get_storages_info()

        if request.method == "POST":
            if "create" in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data["name"] in storages:
                        msg = _("Pool name already use")
                        errors.append(msg)
                    if not errors:
                        conn.create_storage(data["stg_type"], data["name"], data["source"], data["target"])
                        return HttpResponseRedirect("/storage/%s/%s/" % (host_id, data["name"]))
        conn.close()
    except libvirtError as err:
        errors.append(err.message)

    return render_to_response("storages.html", locals(), context_instance=RequestContext(request))
Exemplo n.º 2
0
def storages(request, host_id):
    """
    Storage pool block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')

    errors = []
    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmStorages(compute.hostname, compute.login, compute.password,
                           compute.type)
        storages = conn.get_storages_info()

        if request.method == 'POST':
            if 'create' in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data['name'] in storages:
                        msg = _("Pool name already use")
                        errors.append(msg)
                    if not errors:
                        conn.create_storage(data['stg_type'], data['name'],
                                            data['source'], data['target'])
                        return HttpResponseRedirect('/storage/%s/%s/' %
                                                    (host_id, data['name']))
        conn.close()
    except libvirtError as err:
        errors.append(err.message)

    return render_to_response('storages.html',
                              locals(),
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def storages(request, host_id):
    """
    Storage pool block
    """
    errors = []
    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmStorages(compute.hostname, compute.login, compute.password,
                           compute.type)
        storages = conn.get_storages_info()
        secrets = conn.get_secrets()

        if request.method == 'POST':
            if 'create' in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data['name'] in storages:
                        msg = _("Pool name already use")
                        errors.append(msg)
                    if data['stg_type'] == 'rbd':
                        if not data['secret']:
                            msg = _("You need create secret for pool")
                            errors.append(msg)
                        if not data['ceph_pool'] and not data[
                                'ceph_host'] and not data['ceph_user']:
                            msg = _(
                                "You need input all fields for creating ceph pool"
                            )
                            errors.append(msg)
                    if not errors:
                        if data['stg_type'] == 'rbd':
                            conn.create_storage_ceph(data['stg_type'],
                                                     data['name'],
                                                     data['ceph_pool'],
                                                     data['ceph_host'],
                                                     data['ceph_user'],
                                                     data['secret'])
                        else:
                            conn.create_storage(data['stg_type'], data['name'],
                                                data['source'], data['target'])
                        url = '/%s/storage/%s/' % (host_id, data['name'])
                        object = {'response': {}}
                        return redirect_or_json(object, url, request)
                else:
                    errors = [error for error in form.errors]

        conn.close()
    except libvirtError as err:
        errors.append(err)

    object = {
        'response': {
            'storages': storages,
            'secrets': secrets,
        },
        'errors': [str(error) for error in errors]
    }
    return render(object, 'storages.html', locals(), request)
Exemplo n.º 4
0
def storages(request, host_id):
    """
    Storage pool block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    errors = []
    compute = Compute.objects.get(id=host_id)

    try:
        conn = WvmStorages(compute.hostname, compute.login, compute.password,
                           compute.type)
        storages = conn.get_storages_info()
        secrets = conn.get_secrets()

        if request.method == 'POST':
            if 'create' in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data['name'] in storages:
                        msg = _("Pool name already use")
                        errors.append(msg)
                    if data['stg_type'] == 'rbd':
                        if not data['secret']:
                            msg = _("You need create secret for pool")
                            errors.append(msg)
                        if not data['ceph_pool'] and not data[
                                'ceph_host'] and not data['ceph_user']:
                            msg = _(
                                "You need input all fields for creating ceph pool"
                            )
                            errors.append(msg)
                    if not errors:
                        if data['stg_type'] == 'rbd':
                            conn.create_storage_ceph(data['stg_type'],
                                                     data['name'],
                                                     data['ceph_pool'],
                                                     data['ceph_host'],
                                                     data['ceph_user'],
                                                     data['secret'])
                        elif data['stg_type'] == 'netfs':
                            conn.create_storage_netfs(data['stg_type'],
                                                      data['name'],
                                                      data['netfs_host'],
                                                      data['source'],
                                                      data['source_format'],
                                                      data['target'])
                        else:
                            conn.create_storage(data['stg_type'], data['name'],
                                                data['source'], data['target'])
                        return HttpResponseRedirect(
                            reverse('storage', args=[host_id, data['name']]))
        conn.close()
    except libvirtError as err:
        errors.append(err)

    return render(request, 'storages.html', locals())
Exemplo n.º 5
0
def storages(request, compute_id):
    """
    :param request:
    :return:
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index'))

    if not request.user.is_superuser:
        return HttpResponseRedirect(reverse('index'))

    error_messages = []
    compute = get_object_or_404(Compute, pk=compute_id)

    try:
        conn = wvmStorages(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type)
        storages = conn.get_storages_info()
        secrets = conn.get_secrets()

        if request.method == 'POST':
            if 'create' in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data['name'] in storages:
                        msg = _("Pool name already use")
                        error_messages.append(msg)
                    if data['stg_type'] == 'rbd':
                        if not data['secret']:
                            msg = _("You need create secret for pool")
                            error_messages.append(msg)
                        if not data['ceph_pool'] and not data['ceph_host'] and not data['ceph_user']:
                            msg = _("You need input all fields for creating ceph pool")
                            error_messages.append(msg)
                    if not error_messages:
                        if data['stg_type'] == 'rbd':
                            conn.create_storage_ceph(data['stg_type'], data['name'],
                                                     data['ceph_pool'], data['ceph_host'],
                                                     data['ceph_user'], data['secret'])
                        elif data['stg_type'] == 'netfs':
                            conn.create_storage_netfs(data['stg_type'], data['name'],
                                                      data['netfs_host'], data['source'],
                                                      data['source_format'], data['target'])
                        else:
                            conn.create_storage(data['stg_type'], data['name'], data['source'], data['target'])
                        return HttpResponseRedirect(reverse('storage', args=[compute_id, data['name']]))
                else:
                    for msg_err in form.errors.values():
                        error_messages.append(msg_err.as_text())
        conn.close()
    except libvirtError as lib_err:
        error_messages.append(lib_err)

    return render(request, 'storages.html', locals())
Exemplo n.º 6
0
def storages(request, compute_id):
    """
    :param request:
    :return:
    """

    if not request.user.is_superuser:
        return HttpResponseRedirect(reverse('index'))

    error_messages = []
    compute = get_object_or_404(Compute, pk=compute_id)

    try:
        conn = wvmStorages(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type)
        storages = conn.get_storages_info()
        secrets = conn.get_secrets()

        if request.method == 'POST':
            if 'create' in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data['name'] in storages:
                        msg = _("Pool name already use")
                        error_messages.append(msg)
                    if data['stg_type'] == 'rbd':
                        if not data['secret']:
                            msg = _("You need create secret for pool")
                            error_messages.append(msg)
                        if not data['ceph_pool'] and not data['ceph_host'] and not data['ceph_user']:
                            msg = _("You need input all fields for creating ceph pool")
                            error_messages.append(msg)
                    if not error_messages:
                        if data['stg_type'] == 'rbd':
                            conn.create_storage_ceph(data['stg_type'], data['name'],
                                                     data['ceph_pool'], data['ceph_host'],
                                                     data['ceph_user'], data['secret'])
                        elif data['stg_type'] == 'netfs':
                            conn.create_storage_netfs(data['stg_type'], data['name'],
                                                      data['netfs_host'], data['source'],
                                                      data['source_format'], data['target'])
                        else:
                            conn.create_storage(data['stg_type'], data['name'], data['source'], data['target'])
                        return HttpResponseRedirect(reverse('storage', args=[compute_id, data['name']]))
                else:
                    for msg_err in form.errors.values():
                        error_messages.append(msg_err.as_text())
        conn.close()
    except libvirtError as lib_err:
        error_messages.append(lib_err)

    return render(request, 'storages.html', locals())
Exemplo n.º 7
0
def storages(request, host_id):
    """
    Storage pool block
    """
    errors = []
    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmStorages(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type)
        storages = conn.get_storages_info()
        secrets = conn.get_secrets()

        if request.method == 'POST':
            if 'create' in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data['name'] in storages:
                        msg = _("Pool name already use")
                        errors.append(msg)
                    if data['stg_type'] == 'rbd':
                        if not data['secret']:
                            msg = _("You need create secret for pool")
                            errors.append(msg)
                        if not data['ceph_pool'] and not data['ceph_host'] and not data['ceph_user']:
                            msg = _("You need input all fields for creating ceph pool")
                            errors.append(msg)
                    if not errors:
                        if data['stg_type'] == 'rbd':
                            conn.create_storage_ceph(data['stg_type'], data['name'],
                                                     data['ceph_pool'], data['ceph_host'],
                                                     data['ceph_user'], data['secret'])
                        else:
                            conn.create_storage(data['stg_type'], data['name'], data['source'], data['target'])
                        url = '/%s/storage/%s/' % (host_id, data['name'])
                        object = {'response': {}}
                        return redirect_or_json(object, url, request)
                else:
                    errors = [error for error in form.errors]

        conn.close()
    except libvirtError as err:
        errors.append(err)

    object = {
        'response': {
            'storages': storages,
            'secrets': secrets,
        },
        'errors': [str(error) for error in errors]
    }
    return render(object, 'storages.html', locals(), request)
Exemplo n.º 8
0
def storages(request, host_id):
    """
    Storage pool block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    if not request.user.is_staff:
        raise PermissionDenied

    errors = []
    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmStorages(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type,
                           compute.hypervisor)
        storages = conn.get_storages_info()
        secrets = conn.get_secrets()

        if request.method == 'POST':
            if 'create' in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data['name'] in storages:
                        msg = _("Pool name already use")
                        errors.append(msg)
                    if data['stg_type'] == 'rbd':
                        if not data['secret']:
                            msg = _("You need create secret for pool")
                            errors.append(msg)
                        if not data['ceph_pool'] and not data['ceph_host'] and not data['ceph_user']:
                            msg = _("You need input all fields for creating ceph pool")
                            errors.append(msg)
                    if not errors:
                        if data['stg_type'] == 'rbd':
                            conn.create_storage_ceph(data['stg_type'], data['name'],
                                                     data['ceph_pool'], data['ceph_host'],
                                                     data['ceph_user'], data['secret'])
                        elif data['stg_type'] == 'netfs':
                            conn.create_storage_netfs(data['stg_type'], data['name'],
                                                      data['netfs_host'], data['source'],
                                                      data['source_format'], data['target'])
                        else:
                            conn.create_storage(data['stg_type'], data['name'], data['source'], data['target'])
                        return HttpResponseRedirect(reverse('storage', args=[host_id, data['name']]))
        conn.close()
    except libvirtError as err:
        errors.append(err)

    return render_to_response('storages.html', locals(), context_instance=RequestContext(request))
Exemplo n.º 9
0
def storages(request, compute_id):
    """
    :param request:
    :param compute_id:
    :return:
    """

    compute = get_object_or_404(Compute, pk=compute_id)
    errors = False

    try:
        conn = wvmStorages(compute.hostname, compute.login, compute.password,
                           compute.type)
        storages = conn.get_storages_info()
        secrets = conn.get_secrets()

        if request.method == "POST":
            if "create" in request.POST:
                form = AddStgPool(request.POST)
                if form.is_valid():
                    data = form.cleaned_data
                    if data["name"] in storages:
                        msg = _("Pool name already use")
                        messages.error(request, msg)
                        errors = True
                    if data["stg_type"] == "rbd":
                        if not data["secret"]:
                            msg = _("You need create secret for pool")
                            messages.error(request, msg)
                            errors = True
                        if not data["ceph_pool"] and not data[
                                "ceph_host"] and not data["ceph_user"]:
                            msg = _(
                                "You need input all fields for creating ceph pool"
                            )
                            messages.error(request, msg)
                            errors = True
                    if not errors:
                        if data["stg_type"] == "rbd":
                            conn.create_storage_ceph(
                                data["stg_type"],
                                data["name"],
                                data["ceph_pool"],
                                data["ceph_host"],
                                data["ceph_user"],
                                data["secret"],
                            )
                        elif data["stg_type"] == "netfs":
                            conn.create_storage_netfs(
                                data["stg_type"],
                                data["name"],
                                data["netfs_host"],
                                data["source"],
                                data["source_format"],
                                data["target"],
                            )
                        else:
                            conn.create_storage(data["stg_type"], data["name"],
                                                data["source"], data["target"])
                        return HttpResponseRedirect(
                            reverse("storage", args=[compute_id,
                                                     data["name"]]))
                else:
                    for msg_err in form.errors.values():
                        messages.error(request, msg_err.as_text())
        conn.close()
    except libvirtError as lib_err:
        messages.error(request, lib_err)

    return render(request, "storages.html", locals())