This repository has been archived by the owner on Jul 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data-migration] Update resolv-retry value for OpenVPN
- Loading branch information
1 parent
f4d083e
commit f16768d
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
django_netjsonconfig/migrations/0019_cleanup_model_options.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
django_netjsonconfig/migrations/0020_openvpn_resolv_retry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |