Permalink
Browse files

[data-migration] Update resolv-retry value for OpenVPN

  • Loading branch information...
nemesisdesign committed Feb 8, 2017
1 parent f4d083e commit f16768d3e9031197a71cd988c0643f88a4badbd7
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2017-02-08 13:15
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('django_netjsonconfig', '0018_openvpn_disabled_attr'),
]
operations = [
migrations.AlterModelOptions(
name='template',
options={'verbose_name': 'template', 'verbose_name_plural': 'templates'},
),
migrations.AlterModelOptions(
name='vpn',
options={'verbose_name': 'VPN server', 'verbose_name_plural': 'VPN servers'},
),
migrations.AlterModelOptions(
name='vpnclient',
options={'verbose_name': 'VPN client', 'verbose_name_plural': 'VPN clients'},
),
migrations.AlterField(
model_name='config',
name='vpn',
field=models.ManyToManyField(blank=True, related_name='vpn_relations', through='django_netjsonconfig.VpnClient', to='django_netjsonconfig.Vpn'),
),
]
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
def forward(apps, schema_editor):
"""
converts "resolv_retry" attribute to string format in OpenVPN configurations,
according to the change introduced in netjsonconfig 0.5.4
(see https://github.com/openwisp/netjsonconfig/commit/904659962832b1cf097e34c4251a56e158a247ae)
TODO: delete this migration in future releases
"""
if not schema_editor.connection.alias == 'default':
return
Config = apps.get_model('django_netjsonconfig', 'Config')
Template = apps.get_model('django_netjsonconfig', 'Template')
Vpn = apps.get_model('django_netjsonconfig', 'Vpn')
for model in [Config, Template, Vpn]:
# find objects which have OpenVPN configurations containing the "resolv_retry" attribute
queryset = model.objects.filter(config__contains='"openvpn"')\
.filter(config__contains='"resolv_retry"')
for obj in queryset:
for vpn in obj.config['openvpn']:
if 'resolv_retry' in vpn:
vpn['resolv_retry'] = 'infinite' if vpn['resolv_retry'] else '0'
obj.save()
class Migration(migrations.Migration):
dependencies = [
('django_netjsonconfig', '0019_cleanup_model_options'),
]
operations = [
migrations.RunPython(forward, reverse_code=migrations.RunPython.noop),
]

0 comments on commit f16768d

Please sign in to comment.