Exemplo n.º 1
0
def devview(request, group_id: int, device_id: int):
    ports, manager = None, None
    device = get_object_or_404(Device, id=device_id)

    if not device.group:
        messages.warning(request, _('Please attach group for device'))
        return redirect('devapp:fix_device_group', device.pk)

    template_name = 'generic_switch.html'
    try:
        if device.ip_address and not ping(str(device.ip_address)):
            messages.error(request, _('Dot was not pinged'))
        if device.man_passw:
            manager = device.get_manager_object()
            ports = tuple(manager.get_ports())
            if ports is not None and len(ports) > 0 and isinstance(
                    ports[0], Exception):
                messages.error(request, ports[0])
                ports = ports[1]
            template_name = manager.get_template_name()
        else:
            messages.warning(request, _('Not Set snmp device password'))

        # unregistered units
        unregistered = []
        if hasattr(manager, 'get_fibers'):
            for fiber in manager.get_fibers():
                for onu in manager.get_units_unregistered(
                        int(fiber.get('fb_id'))):
                    if onu:
                        unregistered.append(onu)
        return render(
            request, 'devapp/custom_dev_page/' + template_name, {
                'dev':
                device,
                'ports':
                ports,
                'dev_accs':
                Abon.objects.filter(device=device),
                'dev_manager':
                manager,
                'unregistered':
                unregistered,
                'ports_db':
                Port.objects.filter(device=device).annotate(
                    num_abons=Count('abon')),
            })
    except EasySNMPError as e:
        messages.error(request,
                       "%s: %s" % (gettext('SNMP error on device'), e))
    except (DeviceDBException, DeviceImplementationError) as e:
        messages.error(request, e)
    return render(request, 'devapp/custom_dev_page/' + template_name,
                  {'dev': device})
Exemplo n.º 2
0
def devview(request, group_id: int, device_id: int):
    ports, manager = None, None
    device = get_object_or_404(Device, id=device_id)

    if not device.group:
        messages.warning(request, _('Please attach group for device'))
        return redirect('devapp:fix_device_group', device.pk)

    template_name = 'generic_switch.html'
    try:
        if device.ip_address and not ping(str(device.ip_address)):
            messages.error(request, _('Dot was not pinged'))
        if device.man_passw:
            manager = device.get_manager_object()
            ports = tuple(manager.get_ports())
            if ports is not None and len(ports) > 0 and isinstance(ports[0],
                                                                   Exception):
                messages.error(request, ports[0])
                ports = ports[1]
            template_name = manager.get_template_name()
        else:
            messages.warning(request, _('Not Set snmp device password'))

        return render(request, 'devapp/custom_dev_page/' + template_name, {
            'dev': device,
            'ports': ports,
            'dev_accs': Abon.objects.filter(device=device),
            'dev_manager': manager,
            'ports_db': Port.objects.filter(device=device).annotate(
                num_abons=Count('abon')
            ),
        })
    except EasySNMPError as e:
        messages.error(request,
                       "%s: %s" % (gettext('SNMP error on device'), e))
    except (DeviceDBException, DeviceImplementationError) as e:
        messages.error(request, e)
    return render(request, 'devapp/custom_dev_page/' + template_name, {
        'dev': device
    })
Exemplo n.º 3
0
def toggle_port(request, device_id: str, port_id: str, status=0):
    status = int(status)
    port_id = int(port_id)
    device = get_object_or_404(Device, id=int(device_id))
    try:
        if ping(device.ip_address):
            if device.man_passw:
                manager = device.get_manager_object()
                ports = tuple(manager.get_ports())
                if status:
                    ports[port_id - 1].enable()
                else:
                    ports[port_id - 1].disable()
            else:
                messages.warning(request, _('Not Set snmp device password'))
        else:
            messages.error(request, _('Dot was not pinged'))
    except EasySNMPTimeoutError:
        messages.error(request, _('wait for a reply from the SNMP Timeout'))
    except EasySNMPError as e:
        messages.error(request, 'EasySNMPError: %s' % e)
    return redirect('devapp:view',
                    device.group.pk if device.group is not None else 0,
                    device_id)
Exemplo n.º 4
0
def toggle_port(request, device_id: str, port_id: str, status=0):
    status = int(status)
    port_id = int(port_id)
    device = get_object_or_404(Device, id=int(device_id))
    try:
        if ping(device.ip_address):
            if device.man_passw:
                manager = device.get_manager_object()
                ports = tuple(manager.get_ports())
                if status:
                    ports[port_id - 1].enable()
                else:
                    ports[port_id - 1].disable()
            else:
                messages.warning(request, _('Not Set snmp device password'))
        else:
            messages.error(request, _('Dot was not pinged'))
    except EasySNMPTimeoutError:
        messages.error(request, _('wait for a reply from the SNMP Timeout'))
    except EasySNMPError as e:
        messages.error(request, 'EasySNMPError: %s' % e)
    return redirect('devapp:view',
                    device.group.pk if device.group is not None else 0,
                    device_id)
Exemplo n.º 5
0
 def __init__(self, ip: str, *args, **kwargs):
     if not ping(ip):
         raise NasNetworkError('NAS %(ip_addr)s does not pinged' % {
             'ip_addr': ip
         })