mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-08-19 21:53:41 +00:00
Add logger message and rename var
This commit is contained in:
parent
ee9262bb2c
commit
b5c2b4208b
1 changed files with 14 additions and 9 deletions
|
@ -3,20 +3,25 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
import logging
|
||||||
|
|
||||||
def fix_duplicate(apps, schema_editor):
|
def fix_duplicate(apps, schema_editor):
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
domain = apps.get_model("machines", "Domain")
|
Domain = apps.get_model("machines", "Domain")
|
||||||
machines_to_fix = list(filter(lambda m : not m.name.islower(), domain.objects.using(db_alias).all()))
|
domains_to_fix = filter(lambda m : not m.name.islower(), Domain.objects.using(db_alias).all())
|
||||||
for machine in machines_to_fix:
|
for domain in domains_to_fix:
|
||||||
try:
|
try:
|
||||||
machine.name = machine.name.lower()
|
domain.name = domain.name.lower()
|
||||||
machine.validate_unique()
|
domain.validate_unique()
|
||||||
machine.clean()
|
domain.clean()
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
machine.name = machine.name.lower() + str(machine.interface_parent.id)
|
old_name = domain.name
|
||||||
machine.clean()
|
domain.name = domain.name.lower() + str(domain.interface_parent.id)
|
||||||
machine.save()
|
domain.clean()
|
||||||
|
warning_message = "Warning : Domain %s has been renamed %s due to dns uniqueness" % (old_name, domain.name)
|
||||||
|
logger.warning(warning_message)
|
||||||
|
domain.save()
|
||||||
|
|
||||||
def unfix_duplicate(apps, schema_editor):
|
def unfix_duplicate(apps, schema_editor):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue