Browse Source

fix dhcp commit command, and little bit refactoring

devel
nerosketch 8 years ago
parent
commit
c008c9d9f8
  1. 2
      abonapp/views.py
  2. 9
      agent/commands/dhcp.py
  3. 2
      agent/mod_mikrotik.py
  4. 2
      devapp/dev_types.py
  5. 3
      devapp/locale/ru/LC_MESSAGES/django.po

2
abonapp/views.py

@ -71,7 +71,7 @@ class PeoplesListView(BaseAbonListView):
def get_context_data(self, **kwargs):
gid = mydefs.safe_int(self.kwargs.get('gid'))
if gid == 0:
if gid < 1:
return HttpResponseBadRequest('group id is broken')
group = get_object_or_404(Group, pk=gid)
if not self.request.user.has_perm('group_app.can_view_group', group):

9
agent/commands/dhcp.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from typing import Optional
from django.core.exceptions import MultipleObjectsReturned
from abonapp.models import Abon
@ -19,13 +18,13 @@ def dhcp_commit(client_ip: str, client_mac: str, switch_mac: str, switch_port: i
if not abon.is_dynamic_ip:
print('D:', 'User settings is not dynamic')
return
if not abon.is_access():
print('D:', 'User %s is not access to service' % abon.username)
return
if abon.ip_address != client_ip:
abon.ip_address = client_ip
abon.save(update_fields=('ip_address',))
if abon.is_access():
abon.sync_with_nas(created=False)
else:
print('D:', 'User %s is not access to service' % abon.username)
except Abon.DoesNotExist:
return "User with device with mac '%s' does not exist" % switch_mac
except Device.DoesNotExist:
@ -36,7 +35,7 @@ def dhcp_commit(client_ip: str, client_mac: str, switch_mac: str, switch_port: i
'switch_mac': switch_mac
}
except MultipleObjectsReturned as e:
return 'MultipleObjectsReturned:' + ' '.join(type(e), e, str(switch_port))
return 'MultipleObjectsReturned:' + ' '.join((type(e), e, str(switch_port)))
def dhcp_expiry(client_ip) -> Optional[str]:

2
agent/mod_mikrotik.py

@ -405,7 +405,7 @@ class MikrotikTransmitter(QueueManager, IpAddressListManager):
self.add_user(usr)
def remove_user_range(self, users: VectorAbon):
if not isinstance(users, (tuple, list)):
if not isinstance(users, (tuple, list, set)):
raise ValueError('*users* is used twice, generator does not fit')
queue_ids = (usr.queue_id for usr in users if usr is not None)
QueueManager.remove_range(self, queue_ids)

2
devapp/dev_types.py

@ -163,7 +163,7 @@ class OnuDevice(DevBase, SNMPBaseWorker):
if parent_device is not None and parent_device.ip_address:
dev_ip_addr = parent_device.ip_address
if dev_ip_addr is None:
raise DeviceImplementationError('Ip address or parent device with ip address required for ONU device')
raise DeviceImplementationError(gettext('Ip address or parent device with ip address required for ONU device'))
SNMPBaseWorker.__init__(self, dev_ip_addr, dev_instance.man_passw, 2)
@staticmethod

3
devapp/locale/ru/LC_MESSAGES/django.po

@ -532,3 +532,6 @@ msgstr "%(device_name)s недостижим"
msgid "Device %(device_name)s getting undefined status code"
msgstr "Устройство %(device_name)s получило не определённый код состояния"
msgid "Ip address or parent device with ip address required for ONU device"
msgstr "Необходим ip адрес. Или родительское устройство с назначенным ip адресом необходимо."
Loading…
Cancel
Save