Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
[data-migration] Update resolv-retry value for OpenVPN
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Feb 8, 2017
1 parent f4d083e commit f16768d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
32 changes: 32 additions & 0 deletions django_netjsonconfig/migrations/0019_cleanup_model_options.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
37 changes: 37 additions & 0 deletions django_netjsonconfig/migrations/0020_openvpn_resolv_retry.py
Original file line number Diff line number Diff line change
@@ -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.