Improved error logging

This commit is contained in:
Tobias Genannt 2021-04-13 14:31:05 +02:00
parent 3673196c16
commit f637de88f0
2 changed files with 12 additions and 9 deletions

View File

@ -1,24 +1,24 @@
# - name: VLAN group 1 # - name: VLAN group 1
# scope_type: "dcim.region" # scope_type: dcim.region
# scope: Amsterdam # scope: Amsterdam
# slug: vlan-group-1 # slug: vlan-group-1
# - name: VLAN group 2 # - name: VLAN group 2
# scope_type: "dcim.site" # scope_type: dcim.site
# scope: AMS 1 # scope: AMS 1
# slug: vlan-group-2 # slug: vlan-group-2
# - name: VLAN group 3 # - name: VLAN group 3
# scope_type: "dcim.location" # scope_type: dcim.location
# scope: cage 101 # scope: cage 101
# slug: vlan-group-3 # slug: vlan-group-3
# - name: VLAN group 4 # - name: VLAN group 4
# scope_type: "dcim.rack" # scope_type: dcim.rack
# scope: rack-01 # scope: rack-01
# slug: vlan-group-4 # slug: vlan-group-4
# - name: VLAN group 5 # - name: VLAN group 5
# scope_type: "virtualization.cluster" # scope_type: virtualization.cluster
# scope: cluster1 # scope: cluster1
# slug: vlan-group-5 # slug: vlan-group-5
# - name: VLAN group 6 # - name: VLAN group 6
# scope_type: "virtualization.clustergroup" # scope_type: virtualization.clustergroup
# scope: Group 1 # scope: Group 1
# slug: vlan-group-6 # slug: vlan-group-6

View File

@ -21,12 +21,15 @@ for params in vlan_groups:
# Get model from Contenttype # Get model from Contenttype
scope_type = params.pop("scope_type", None) scope_type = params.pop("scope_type", None)
if not scope_type: if not scope_type:
print("scope_type is missing from VLAN Group") print(f"VLAN Group '{params['name']}': scope_type is missing from VLAN Group")
continue continue
app_label, model = str(scope_type).split(".") app_label, model = str(scope_type).split(".")
ct = ContentType.objects.get(app_label=app_label, model=model) ct = ContentType.objects.filter(app_label=app_label, model=model).first()
if not ct: if not ct:
print(f"ContentType for app_label = '{app_label}' and model = '{model}' not found") print(
f"VLAN Group '{params['name']}': ContentType for "
+ "app_label = '{app_label}' and model = '{model}' not found"
)
continue continue
params["scope_id"] = ct.model_class().objects.get(**query).id params["scope_id"] = ct.model_class().objects.get(**query).id
vlan_group, created = VLANGroup.objects.get_or_create(**params) vlan_group, created = VLANGroup.objects.get_or_create(**params)