mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Update reverting kwarg; allow pop() to fail
This commit is contained in:
parent
354c5dc1c5
commit
5a0d33a4a8
@ -52,7 +52,7 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_circuittermination_termination(objectchange, revert):
|
||||
def oc_circuittermination_termination(objectchange, reverting):
|
||||
site_ct = ContentType.objects.get_by_natural_key('dcim', 'site').pk
|
||||
provider_network_ct = ContentType.objects.get_by_natural_key('circuits', 'providernetwork').pk
|
||||
for data in (objectchange.prechange_data, objectchange.postchange_data):
|
||||
@ -68,8 +68,8 @@ def oc_circuittermination_termination(objectchange, revert):
|
||||
'termination_type': provider_network_ct,
|
||||
'termination_id': provider_network_id,
|
||||
})
|
||||
data.pop('site')
|
||||
data.pop('provider_network')
|
||||
data.pop('site', None)
|
||||
data.pop('provider_network', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
@ -85,7 +85,7 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_circuitgroupassignment_member(objectchange, revert):
|
||||
def oc_circuitgroupassignment_member(objectchange, reverting):
|
||||
circuit_ct = ContentType.objects.get_by_natural_key('circuits', 'circuit').pk
|
||||
for data in (objectchange.prechange_data, objectchange.postchange_data):
|
||||
if data is None:
|
||||
@ -95,7 +95,7 @@ def oc_circuitgroupassignment_member(objectchange, revert):
|
||||
'member_type': circuit_ct,
|
||||
'member_id': circuit_id,
|
||||
})
|
||||
data.pop('circuit')
|
||||
data.pop('circuit', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
@ -55,11 +55,12 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_interface_primary_mac_address(objectchange, revert):
|
||||
def oc_interface_primary_mac_address(objectchange, reverting):
|
||||
MACAddress = apps.get_model('dcim', 'MACAddress')
|
||||
interface_ct = ContentType.objects.get_by_natural_key('dcim', 'interface')
|
||||
|
||||
if not revert:
|
||||
# Swap data order if the change is being reverted
|
||||
if not reverting:
|
||||
before, after = objectchange.prechange_data, objectchange.postchange_data
|
||||
else:
|
||||
before, after = objectchange.postchange_data, objectchange.prechange_data
|
||||
@ -84,8 +85,8 @@ def oc_interface_primary_mac_address(objectchange, revert):
|
||||
).delete()
|
||||
before['primary_mac_address'] = None
|
||||
|
||||
before.pop('mac_address')
|
||||
after.pop('mac_address')
|
||||
before.pop('mac_address', None)
|
||||
after.pop('mac_address', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
@ -47,7 +47,7 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_prefix_scope(objectchange, revert):
|
||||
def oc_prefix_scope(objectchange, reverting):
|
||||
site_ct = ContentType.objects.get_by_natural_key('dcim', 'site').pk
|
||||
for data in (objectchange.prechange_data, objectchange.postchange_data):
|
||||
if data is None:
|
||||
@ -57,7 +57,7 @@ def oc_prefix_scope(objectchange, revert):
|
||||
'scope_type': site_ct,
|
||||
'scope_id': site_id,
|
||||
})
|
||||
data.pop('site')
|
||||
data.pop('site', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
@ -57,7 +57,7 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_service_parent(objectchange, revert):
|
||||
def oc_service_parent(objectchange, reverting):
|
||||
device_ct = ContentType.objects.get_by_natural_key('dcim', 'device').pk
|
||||
virtual_machine_ct = ContentType.objects.get_by_natural_key('virtualization', 'virtualmachine').pk
|
||||
for data in (objectchange.prechange_data, objectchange.postchange_data):
|
||||
@ -73,8 +73,8 @@ def oc_service_parent(objectchange, revert):
|
||||
'parent_object_type': virtual_machine_ct,
|
||||
'parent_object_id': virtual_machine_id,
|
||||
})
|
||||
data.pop('device')
|
||||
data.pop('virtual_machine')
|
||||
data.pop('device', None)
|
||||
data.pop('virtual_machine', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
@ -68,13 +68,13 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_contact_groups(objectchange, revert):
|
||||
def oc_contact_groups(objectchange, reverting):
|
||||
for data in (objectchange.prechange_data, objectchange.postchange_data):
|
||||
if data is None:
|
||||
continue
|
||||
if 'group' in data:
|
||||
data['groups'] = [data['group']] if data['group'] else []
|
||||
data.pop('group')
|
||||
# Set the M2M field `groups` to a list containing the group ID
|
||||
data['groups'] = [data['group']] if data.get('group') else []
|
||||
data.pop('group', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
@ -46,7 +46,7 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_cluster_scope(objectchange, revert):
|
||||
def oc_cluster_scope(objectchange, reverting):
|
||||
site_ct = ContentType.objects.get_by_natural_key('dcim', 'site').pk
|
||||
for data in (objectchange.prechange_data, objectchange.postchange_data):
|
||||
if data is None:
|
||||
@ -56,7 +56,7 @@ def oc_cluster_scope(objectchange, revert):
|
||||
'scope_type': site_ct,
|
||||
'scope_id': site_id,
|
||||
})
|
||||
data.pop('site')
|
||||
data.pop('site', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
@ -54,11 +54,12 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
|
||||
def oc_vminterface_primary_mac_address(objectchange, revert):
|
||||
def oc_vminterface_primary_mac_address(objectchange, reverting):
|
||||
MACAddress = apps.get_model('dcim', 'MACAddress')
|
||||
vminterface_ct = ContentType.objects.get_by_natural_key('virtualization', 'vminterface')
|
||||
|
||||
if not revert:
|
||||
# Swap data order if the change is being reverted
|
||||
if not reverting:
|
||||
before, after = objectchange.prechange_data, objectchange.postchange_data
|
||||
else:
|
||||
before, after = objectchange.postchange_data, objectchange.prechange_data
|
||||
@ -83,8 +84,8 @@ def oc_vminterface_primary_mac_address(objectchange, revert):
|
||||
).delete()
|
||||
before['primary_mac_address'] = None
|
||||
|
||||
before.pop('mac_address')
|
||||
after.pop('mac_address')
|
||||
before.pop('mac_address', None)
|
||||
after.pop('mac_address', None)
|
||||
|
||||
|
||||
objectchange_migrators = {
|
||||
|
Loading…
Reference in New Issue
Block a user