You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.2 KiB
60 lines
2.2 KiB
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.11 on 2018-05-29 13:11
|
|
from __future__ import unicode_literals
|
|
import os
|
|
from json import load
|
|
|
|
from django.db import migrations, models
|
|
from django.core import serializers
|
|
|
|
TMP_FILE = '/tmp/djing_snmp_info_backup.json'
|
|
|
|
|
|
def snmp_backup_info(apps, _):
|
|
Device = apps.get_model('devapp', 'Device')
|
|
obs = Device.objects.only('snmp_item_num')
|
|
with open(TMP_FILE, 'w') as f:
|
|
serializers.serialize('json', obs, stream=f, fields=('snmp_item_num',))
|
|
|
|
|
|
def snmp_restore_info_to_new_scheme(apps, _):
|
|
Device = apps.get_model('devapp', 'Device')
|
|
with open(TMP_FILE, 'r') as f:
|
|
for device in load(f):
|
|
Device.objects.filter(pk=device['pk']).update(snmp_extra=device['fields']['snmp_item_num'])
|
|
if os.path.isfile(TMP_FILE):
|
|
os.remove(TMP_FILE)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('devapp', '0002_auto_20180409_1318'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(snmp_backup_info),
|
|
migrations.AlterModelOptions(
|
|
name='device',
|
|
options={'ordering': ('id',), 'permissions': (('can_view_device', 'Can view device'),), 'verbose_name': 'Device', 'verbose_name_plural': 'Devices'},
|
|
),
|
|
migrations.AlterModelOptions(
|
|
name='port',
|
|
options={'ordering': ('num',), 'permissions': (('can_toggle_ports', 'Can toggle ports'),), 'verbose_name': 'Port', 'verbose_name_plural': 'Ports'},
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='device',
|
|
name='snmp_item_num',
|
|
),
|
|
migrations.AddField(
|
|
model_name='device',
|
|
name='snmp_extra',
|
|
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='SNMP extra info'),
|
|
),
|
|
migrations.AlterField(
|
|
model_name='device',
|
|
name='devtype',
|
|
field=models.CharField(choices=[('Dl', 'DLink switch'), ('Pn', 'PON OLT'), ('On', 'PON ONU'), ('Ex', 'Eltex switch'), ('Zt', 'OLT ZTE C320'), ('Zo', 'ZTE PON ONU')], default='Dl', max_length=2, verbose_name='Device type'),
|
|
),
|
|
migrations.RunPython(snmp_restore_info_to_new_scheme)
|
|
]
|