Browse Source

Fix dlink view error

devel
bashmak 8 years ago
parent
commit
fb5ae9af6a
  1. 19
      devapp/base_intr.py
  2. 12
      devapp/dev_types.py
  3. 8
      devapp/templates/devapp/custom_dev_page/ports.html
  4. 3
      devapp/views.py

19
devapp/base_intr.py

@ -1,8 +1,11 @@
# -*- coding: utf-8 -*-
from abc import ABCMeta, abstractmethod
from easysnmp import Session
class DeviceImplementationError(Exception):
pass
class DevBase(object, metaclass=ABCMeta):
def __init__(self, dev_instance=None):
@ -10,19 +13,19 @@ class DevBase(object, metaclass=ABCMeta):
@staticmethod
def description():
"""Возвращает текстовое описание"""
pass
@abstractmethod
def reboot(self):
"""Перезагружает устройство"""
pass
@abstractmethod
def get_ports(self):
"""Получаем инфу о портах"""
pass
@abstractmethod
def get_device_name(self):
"""Получаем имя устройства по snmp"""
"""Return device name by snmp"""
@abstractmethod
def uptime(self):
@ -30,17 +33,17 @@ class DevBase(object, metaclass=ABCMeta):
@abstractmethod
def get_template_name(self):
"""Получаем путь к html шаблону отображения устройства"""
"""Return path to html template for device"""
@staticmethod
@abstractmethod
def has_attachable_to_subscriber():
"""Можно-ли подключать устройство к абоненту"""
"""Can connect device to subscriber"""
@staticmethod
@abstractmethod
def is_use_device_port():
"""True если при авторизации по opt82 используется порт"""
"""True if used device port while opt82 authorization"""
class BasePort(object, metaclass=ABCMeta):

12
devapp/dev_types.py

@ -3,7 +3,7 @@ from django.utils.translation import gettext_lazy as _
from mydefs import RuTimedelta, safe_int
from datetime import timedelta
from easysnmp import EasySNMPTimeoutError
from .base_intr import DevBase, SNMPBaseWorker, BasePort
from .base_intr import DevBase, SNMPBaseWorker, BasePort, DeviceImplementationError
class DLinkPort(BasePort):
@ -41,21 +41,25 @@ class DLinkDevice(DevBase, SNMPBaseWorker):
return self.get_item('.1.3.6.1.4.1.2021.8.1.101.1')
def get_ports(self):
interfaces_count = safe_int(self.get_item('.1.3.6.1.2.1.2.1.0'))
nams = list(self.get_list('.1.3.6.1.4.1.171.10.134.2.1.1.100.2.1.3'))
stats = list(self.get_list('.1.3.6.1.2.1.2.2.1.7'))
macs = list(self.get_list('.1.3.6.1.2.1.2.2.1.6'))
speeds = self.get_list('.1.3.6.1.2.1.31.1.1.1.15')
speeds = list(self.get_list('.1.3.6.1.2.1.2.2.1.5'))
res = []
for n, speed in enumerate(speeds):
try:
for n in range(interfaces_count):
status = True if int(stats[n]) == 1 else False
res.append(DLinkPort(
n+1,
nams[n] if len(nams) > 0 else _('does not fetch the name'),
status,
macs[n] if len(macs) > 0 else _('does not fetch the mac'),
int(speed or 0),
int(speeds[n]) if len(speeds) > 0 else 0,
self))
return res
except IndexError:
raise DeviceImplementationError('Dlink port index error')
def get_device_name(self):
return self.get_item('.1.3.6.1.2.1.1.1.0')

8
devapp/templates/devapp/custom_dev_page/ports.html

@ -18,16 +18,16 @@
{% for port in ports %}
{% if port.st %}
{% if port.sp == 10 %}
{% if port.sp == 10000000 %}
<div class="port kilo text-center">
<b>10 mbps</b>
{% elif port.sp == 100 %}
{% elif port.sp == 100000000 %}
<div class="port mega text-center">
<b>100 mbps</b>
{% elif port.sp == 1000 %}
{% elif port.sp == 1000000000 %}
<div class="port giga text-center">
<b>1 gbps</b>
{% elif port.sp == 10000 %}
{% elif port.sp == 10000000000 %}
<div class="port ten text-center">
<b>10 gbps</b>
{% else %}

3
devapp/views.py

@ -13,6 +13,7 @@ from django.utils.translation import gettext_lazy as _, gettext
from easysnmp import EasySNMPTimeoutError, EasySNMPError
from django.views.generic import ListView, DetailView
from devapp.base_intr import DeviceImplementationError
from mydefs import res_success, res_error, only_admins, ping, ip_addr_regex
from abonapp.models import AbonGroup, Abon
from django.conf import settings
@ -371,7 +372,7 @@ def devview(request, device_id):
})
except EasySNMPError:
messages.error(request, _('SNMP error on device'))
except DeviceDBException as e:
except (DeviceDBException, DeviceImplementationError) as e:
messages.error(request, e)
return render(request, 'devapp/custom_dev_page/' + template_name, {
'dev': dev

Loading…
Cancel
Save