Browse Source

Теперь онушки регистрируются при сохранении онушки

devel
bashmak 9 years ago
parent
commit
9f5817b492
  1. 35
      devapp/models.py
  2. 32
      devapp/onu_register.sh
  3. 32
      djing/__init__.py

35
devapp/models.py

@ -6,6 +6,8 @@ from .base_intr import DevBase
from mydefs import MyGenericIPAddressField, MyChoicesAdapter
from .dev_types import DLinkDevice, OLTDevice, OnuDevice
from mapapp.models import Dot
from subprocess import call
from django.conf import settings
DEVICE_TYPES = (
@ -66,3 +68,36 @@ class Port(models.Model):
class Meta:
db_table = 'dev_port'
unique_together = (('device', 'num'))
def dev_post_save_signal(sender, instance, **kwargs):
if instance.devtype != 'On':
return
grp = instance.user_group.pk
if grp == 87:
code = 'chk'
elif grp == 85:
code = 'drf'
elif grp == 86:
code = 'eme'
elif grp == 84:
code = 'kunc'
elif grp == 47:
code = 'mtr'
elif grp == 60:
code = 'nvg'
elif grp == 65:
code = 'ohot'
elif grp == 89:
code = 'psh'
elif grp == 92:
code = 'str'
elif grp == 80:
code = 'uy'
elif grp == 79 or grp == 91:
code = 'zrk'
newmac = str(instance.mac_addr)
call(["%s/devapp/onu_register.sh" % settings.BASE_DIR, newmac, code])
models.signals.post_save.connect(dev_post_save_signal, sender=Device)

32
devapp/onu_register.sh

@ -0,0 +1,32 @@
#!/bin/bash
# old mac address
if [[ $1 =~ ^([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]{1,2})$ ]]; then
MAC=$1
else
echo "Bad mac $MAC addr"
exit
fi
# part code
if [[ $2 =~ ^[a-zA-Z]+$ ]]; then
PART_CODE=$2
else
echo 'code must contains only letters'
exit
fi
DHCP_PATH='/home/bashmak/Projects/djing/macs'
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin
if grep "${MAC}" "${DHCP_PATH}/${PART_CODE}.conf" > /dev/null; then
# mac is already exists
exit
else
# add new mac
echo "subclass \"${PART_CODE}\" \"${MAC}\";" >> "${DHCP_PATH}/${PART_CODE}.conf"
fi

32
djing/__init__.py

@ -1,39 +1,17 @@
import importlib
import warnings
from django.conf import settings
from netaddr import mac_unix, mac_eui48
MAC_ADDR_REGEX = r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
MAC_ADDR_REGEX = r'^([0-9A-Fa-f]{1,2}[:-]){5}([0-9A-Fa-f]{1,2})$'
class mac_linux(mac_unix):
"""MAC format with zero-padded all upper-case hex and colon separated"""
word_fmt = '%.2X'
word_fmt = '%x'
def default_dialect(eui_obj=None):
# Check to see if a default dialect class has been specified in settings,
# using 'module.dialect_cls' string and use importlib and getattr to retrieve dialect class. 'module' is the module and
# 'dialect_cls' is the class name of the custom dialect. The dialect must either be defined or imported by the module's
# __init__.py if the module is a package.
from .fields import MACAddressField # Remove import at v1.4
if hasattr(settings, 'MACADDRESS_DEFAULT_DIALECT') and not MACAddressField.dialect:
module, dialect_cls = settings.MACADDRESS_DEFAULT_DIALECT.split('.')
dialect = getattr(importlib.import_module(module), dialect_cls, mac_linux)
return dialect
else:
if MACAddressField.dialect: # Remove this "if" statement at v1.4
warnings.warn(
"The set_dialect class method on MACAddressField has been deprecated, in favor of the default_dialect "
"utility function and settings.MACADDRESS_DEFAULT_DIALECT. See macaddress.__init__.py source or the "
"project README for more information.",
DeprecationWarning,
)
return MACAddressField.dialect
if eui_obj:
return eui_obj.dialect
else:
return mac_linux
return mac_linux
def format_mac(eui_obj, dialect):
# Format a EUI instance as a string using the supplied dialect class, allowing custom string classes by

Loading…
Cancel
Save