Ejemplo n.º 1
0
def host_info(request, host_name):
    """Manipulate or show a host in the database."""
    data = request_data(request)
    try:
        host = interface.get_host(host_name)
    except interface.InexistantObjectError:
        return error_404(request)

    if request.method == "PUT":
        category = data.get("category")
        if category:
            category = [category]
        alias = data.get("alias")
        if not alias:
            alias = ""
        alias = alias.replace(", ", ",")
        if alias:
            alias = alias.split(",")
        mac = data.get("macaddr")
        try:
            if mac:
                mac = mac.lower()
                if not re.match("^[a-f0-9]{2}(:[a-f0-9]{2}){5}$", mac):
                    return error_view(
                        request, 400, _("Invalid MAC"),
                        _("The format of the given MAC address is invalid :"
                          " %(mac)s.") % {"mac": mac})

            interface.modify(host=host_name,
                             mac=data.get("macaddr"),
                             newname=data.get("newname"),
                             category=category,
                             alias=alias,
                             serial=data.get("serial"),
                             inventory=data.get("inventory"),
                             nodns=((data.get("nodns") == "on") != host.nodns),
                             clearalias=data.get("clearalias") == "on")
            if data.get("owner"):
                interface.set_prop("owner", data.get("owner"), host=host)
        except interface.MissingParameterError:
            return error_view(
                request, 400, _("Missing information"),
                _("You must specify the new values to modify an object."))
        #annomalie espace dans le name host
        except interface.PropertyFormatError:
            return error_view(
                request, 400, _("Format invalid"),
                _("You must specify a valid host name or alias without space, special character etc."
                  ))
        #anomalie9
        except interface.DuplicateObjectError, e:
            return error_view(request, 409, _("Host or alias already exists"),
                              e.args[0])
        #fin anomalie9
        except interface.InexistantObjectError:
            return error_404(request)
Ejemplo n.º 2
0
Archivo: views.py Proyecto: aflp91/SLAM
def host_info(request, host_name):
    """Manipulate or show a host in the database."""
    data = request_data(request)
    try:
        host = interface.get_host(host_name)
    except interface.InexistantObjectError:
        return error_404(request)

    if request.method == "PUT":
        category = data.get("category")
        if category:
            category = [category]
        alias = data.get("alias")
        if not alias:
            alias = ""
        alias = alias.replace(", ", ",")
        if alias:
            alias = alias.split(",")
        mac = data.get("macaddr")
        try:
            if mac:
                mac = mac.lower()
                if not re.match("^[a-f0-9]{2}(:[a-f0-9]{2}){5}$", mac):
                    return error_view(request, 400, _("Invalid MAC"),
                        _("The format of the given MAC address is invalid :"
                            " %(mac)s.") % {"mac": mac})

            interface.modify(host=host_name,
                mac=data.get("macaddr"),
                newname=data.get("newname"),
                category=category,
                alias=alias,
                serial=data.get("serial"),
                inventory=data.get("inventory"),
                nodns=((data.get("nodns") == "on") != host.nodns),
                clearalias=data.get("clearalias") == "on")
            if data.get("owner"):
                interface.set_prop("owner", data.get("owner"), host=host)
        except interface.MissingParameterError:
            return error_view(request, 400, _("Missing information"),
                _("You must specify the new values to modify an object."))
        #annomalie espace dans le name host
        except interface.PropertyFormatError:
            return error_view(request, 400, _("Format invalid"),
                _("You must specify a valid host name or alias without space, special character etc."))
        #anomalie9
        except interface.DuplicateObjectError, e:
            return error_view(request, 409, _("Host or alias already exists"), e.args[0])
        #fin anomalie9
        except interface.InexistantObjectError:
            return error_404(request)
Ejemplo n.º 3
0
Archivo: views.py Proyecto: aflp91/SLAM
def property_(request):
    """Create, edit or delete a property."""
    if request.method == "POST" or request.method == "DELETE":
        try:
            interface.set_prop(request.POST.get("name"),
                request.POST.get("value"), request.POST.get("pool"),
                request.POST.get("host"), request.method == "DELETE")
        except interface.MissingParameterError():
            return error_view(request, 400, _("Missing information"),
                _("You must at least specify a pool or a host and the name of"
                    " property to create, edit or delete a property."))
        except interface.InexistantObjectError:
            return error_404(request)
        #except interface.inexistant
        if request.POST.get("host"):
            return redirect("/host/" + request.POST.get("host"))
        elif request.POST.get("pool"):
            return redirect("/host/" + request.POST.get("pool"))

    return redirect("/")
Ejemplo n.º 4
0
def property_(request):
    """Create, edit or delete a property."""
    if request.method == "POST" or request.method == "DELETE":
        try:
            interface.set_prop(request.POST.get("name"),
                               request.POST.get("value"),
                               request.POST.get("pool"),
                               request.POST.get("host"),
                               request.method == "DELETE")
        except interface.MissingParameterError():
            return error_view(
                request, 400, _("Missing information"),
                _("You must at least specify a pool or a host and the name of"
                  " property to create, edit or delete a property."))
        except interface.InexistantObjectError:
            return error_404(request)
        #except interface.inexistant
        if request.POST.get("host"):
            return redirect("/host/" + request.POST.get("host"))
        elif request.POST.get("pool"):
            return redirect("/host/" + request.POST.get("pool"))

    return redirect("/")
Ejemplo n.º 5
0
             request, 412, _("Address not available"),
             _("The address you asked for (%(addr)s) is not available.") %
             {"addr": str(request.POST.get("address"))})
     except models.FullPoolError:
         return error_view(
             request, 412, _("Pool is full"),
             _("The destination address pool (%(pool)s) is full. "
               "Impossible to allocate another IP in this pool.") %
             {"pool": str(pool.name)})
     msg = _("The host \"%(host)s\" have been created") % {"host": hoststr}
     if addrstr:
         msg = msg + _(" and was assigned to address: ") + addrstr
     if request.POST.get("owner"):
         try:
             interface.set_prop("owner",
                                request.POST.get("owner"),
                                host=request.POST.get("name"))
         except interface.InexistantObjectError:
             error_404(request)
         except interface.MissingParameterError:
             return error_view(
                 request, 400, _("Missing information"),
                 _("You must at least specify the name of the new property "
                   "you want to create."))
     return msg_view(request,
                     _("Created host %(host)s") % {"host": hoststr},
                     msg,
                     referer="/host/" + hoststr)
 else:
     categories = []
     for pools in models.Pool.objects.exclude(category=""):
Ejemplo n.º 6
0
Archivo: views.py Proyecto: aflp91/SLAM
                     "pool": str(pool.name)})
     except models.AddressNotAvailableError:
         return error_view(request, 412, _("Address not available"),
             _("The address you asked for (%(addr)s) is not available.")
                 % {"addr": str(request.POST.get("address"))})
     except models.FullPoolError:
         return error_view(request, 412, _("Pool is full"),
             _("The destination address pool (%(pool)s) is full. "
                 "Impossible to allocate another IP in this pool.")
                 % {"pool": str(pool.name)})
     msg = _("The host \"%(host)s\" have been created") % {"host": hoststr}
     if addrstr:
         msg = msg + _(" and was assigned to address: ") + addrstr
     if request.POST.get("owner"):
         try:
             interface.set_prop("owner", request.POST.get("owner"),
                 host=request.POST.get("name"))
         except interface.InexistantObjectError:
             error_404(request)
         except interface.MissingParameterError:
             return error_view(request, 400, _("Missing information"),
                 _("You must at least specify the name of the new property "
                     "you want to create."))
     return msg_view(request,
         _("Created host %(host)s") % {"host": hoststr}, msg,
         referer="/host/" + hoststr)
 else:
     categories = []
     for pools in models.Pool.objects.exclude(category=""):
         for cat in pools.category.split(","):
             if cat not in categories:
                 categories.append(cat)