Browse Source

continue second operation even if raised en exception in first

devel
www-data 8 years ago
parent
commit
d67e8be613
  1. 17
      agent/mod_mikrotik.py

17
agent/mod_mikrotik.py

@ -11,11 +11,12 @@ from .structs import TariffStruct, AbonStruct, IpStruct, VectorAbon, VectorTarif
from . import settings as local_settings from . import settings as local_settings
from django.conf import settings from django.conf import settings
from djing import ping from djing import ping
from agent.core import NasNetworkError, NasFailedResult
DEBUG = getattr(settings, 'DEBUG', False) DEBUG = getattr(settings, 'DEBUG', False)
LIST_USERS_ALLOWED = 'DjingUsersAllowed' LIST_USERS_ALLOWED = 'DjingUsersAllowed'
LIST_USERS_BLOCKED = 'DjingUsersBlocked'
#LIST_USERS_BLOCKED = 'DjingUsersBlocked'
@singleton @singleton
@ -421,12 +422,14 @@ class MikrotikTransmitter(QueueManager, IpAddressListManager):
return return
if not isinstance(user.tariff, TariffStruct): if not isinstance(user.tariff, TariffStruct):
raise TypeError raise TypeError
QueueManager.add(self, user)
IpAddressListManager.add(self, LIST_USERS_ALLOWED, user.ip)
# remove user from denied user list
firewall_ip_list_obj = IpAddressListManager.find(self, user.ip, LIST_USERS_BLOCKED)
if len(firewall_ip_list_obj) > 1:
IpAddressListManager.remove(self, firewall_ip_list_obj[0]['=.id'])
try:
QueueManager.add(self, user)
except (NasNetworkError, NasFailedResult) as e:
print('Error:', e)
try:
IpAddressListManager.add(self, LIST_USERS_ALLOWED, user.ip)
except (NasNetworkError, NasFailedResult) as e:
print('Error:', e)
def remove_user(self, user: AbonStruct): def remove_user(self, user: AbonStruct):
QueueManager.remove(self, user) QueueManager.remove(self, user)

Loading…
Cancel
Save