diff --git a/abonapp/views.py b/abonapp/views.py index ed1a717..afd4b72 100644 --- a/abonapp/views.py +++ b/abonapp/views.py @@ -602,7 +602,8 @@ def clear_dev(request, gid, uname): abon = models.Abon.objects.get(username=uname) abon.device = None abon.dev_port = None - abon.save(update_fields=('device', 'dev_port')) + abon.is_dynamic_ip = False + abon.save(update_fields=('device', 'dev_port', 'is_dynamic_ip')) messages.success(request, _('Device has successfully unattached')) except models.Abon.DoesNotExist: messages.error(request, _('Abon does not exist')) diff --git a/agent/commands/dhcp.py b/agent/commands/dhcp.py index 92051a8..f73db47 100644 --- a/agent/commands/dhcp.py +++ b/agent/commands/dhcp.py @@ -9,7 +9,7 @@ def dhcp_commit(client_ip: str, client_mac: str, switch_mac: str, switch_port: i dev = Device.objects.get(mac_addr=switch_mac) mngr_class = dev.get_manager_klass() - if mngr_class.is_use_device_port(): + if mngr_class.is_use_device_port: abon = Abon.objects.get(dev_port__device=dev, dev_port__num=switch_port, device=dev) diff --git a/devapp/base_intr.py b/devapp/base_intr.py index 3b63998..0d35450 100644 --- a/devapp/base_intr.py +++ b/devapp/base_intr.py @@ -49,12 +49,14 @@ class DevBase(object, metaclass=ABCMeta): def get_template_name(self) -> AnyStr: """Return path to html template for device""" + @property @abstractmethod def has_attachable_to_subscriber(self) -> bool: """Can connect device to subscriber""" - @abstract_static_method - def is_use_device_port() -> bool: + @property + @abstractmethod + def is_use_device_port(self) -> bool: """True if used device port while opt82 authorization""" # fixme: only that is abstract static diff --git a/devapp/dev_types.py b/devapp/dev_types.py index 7baf5e0..31aeb0b 100644 --- a/devapp/dev_types.py +++ b/devapp/dev_types.py @@ -60,6 +60,9 @@ class DLinkPort(BasePort): class DLinkDevice(DevBase, SNMPBaseWorker): + has_attachable_to_subscriber = True + is_use_device_port = True + def __init__(self, dev_instance): DevBase.__init__(self, dev_instance) SNMPBaseWorker.__init__(self, dev_instance.ip_address, dev_instance.man_passw, 2) @@ -103,13 +106,6 @@ class DLinkDevice(DevBase, SNMPBaseWorker): def get_template_name(self): return 'ports.html' - def has_attachable_to_subscriber(self) -> bool: - return True - - @staticmethod - def is_use_device_port(): - return True - @staticmethod def validate_extra_snmp_info(v: str) -> None: # Dlink has no require snmp info @@ -142,6 +138,9 @@ class ONUdev(BasePort): class OLTDevice(DevBase, SNMPBaseWorker): + has_attachable_to_subscriber = False + is_use_device_port = False + def __init__(self, dev_instance): DevBase.__init__(self, dev_instance) SNMPBaseWorker.__init__(self, dev_instance.ip_address, dev_instance.man_passw, 2) @@ -187,13 +186,6 @@ class OLTDevice(DevBase, SNMPBaseWorker): def get_template_name(self): return 'olt.html' - def has_attachable_to_subscriber(self) -> bool: - return False - - @staticmethod - def is_use_device_port(): - return False - @staticmethod def validate_extra_snmp_info(v: str) -> None: # Olt has no require snmp info @@ -208,6 +200,9 @@ class OLTDevice(DevBase, SNMPBaseWorker): class OnuDevice(DevBase, SNMPBaseWorker): + has_attachable_to_subscriber = True + is_use_device_port = False + def __init__(self, dev_instance): DevBase.__init__(self, dev_instance) dev_ip_addr = None @@ -242,13 +237,6 @@ class OnuDevice(DevBase, SNMPBaseWorker): def get_template_name(self): return "onu.html" - def has_attachable_to_subscriber(self) -> bool: - return True - - @staticmethod - def is_use_device_port(): - return False - def get_details(self): if self.db_instance is None: return @@ -330,6 +318,9 @@ class EltexPort(BasePort): class EltexSwitch(DLinkDevice): + has_attachable_to_subscriber = True + is_use_device_port = False + @staticmethod def description(): return _('Eltex switch') @@ -355,13 +346,6 @@ class EltexSwitch(DLinkDevice): tm = RuTimedelta(timedelta(seconds=uptimestamp / 100)) or RuTimedelta(timedelta()) return tm - def has_attachable_to_subscriber(self) -> bool: - return True - - @staticmethod - def is_use_device_port(): - return False - def monitoring_template(self, *args, **kwargs) -> Optional[str]: device = self.db_instance return plain_ip_device_mon_template(device) diff --git a/devapp/models.py b/devapp/models.py index b0a94ee..5f2dedd 100644 --- a/devapp/models.py +++ b/devapp/models.py @@ -73,11 +73,11 @@ class Device(models.Model): return self.status def get_manager_klass(self): - klasses = tuple(kl for kl in self.DEVICE_TYPES if kl[0] == self.devtype) - if len(klasses) > 0: - res = klasses[0][1] - if issubclass(res, DevBase): - return res + klasses = next(kl for kl in self.DEVICE_TYPES if kl[0] == self.devtype) + if klasses: + code, dev_class = klasses + if issubclass(dev_class, DevBase): + return dev_class raise TypeError('one of types is not subclass of DevBase. ' 'Or implementation of that device type is not found') @@ -89,8 +89,8 @@ class Device(models.Model): # Can attach device to subscriber in subscriber page def has_attachable_to_subscriber(self) -> bool: - mngr = self.get_manager_object() - return mngr.has_attachable_to_subscriber() + mngr = self.get_manager_klass() + return mngr.has_attachable_to_subscriber def __str__(self): return "%s: (%s) %s %s" % (self.comment, self.get_devtype_display(), self.ip_address or '', self.mac_addr or '') diff --git a/devapp/templates/devapp/manage_ports/list.html b/devapp/templates/devapp/manage_ports/list.html index e578479..a8bebe6 100644 --- a/devapp/templates/devapp/manage_ports/list.html +++ b/devapp/templates/devapp/manage_ports/list.html @@ -27,7 +27,7 @@ {% else %}