File tree Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 1
1
# - name: VLAN group 1
2
- # site: AMS 1
2
+ # scope_type: "dcim.region"
3
+ # scope: Amsterdam
3
4
# slug: vlan-group-1
4
5
# - name: VLAN group 2
5
- # site: AMS 1
6
+ # scope_type: "dcim.site"
7
+ # scope: AMS 1
6
8
# slug: vlan-group-2
9
+ # - name: VLAN group 3
10
+ # scope_type: "dcim.location"
11
+ # scope: cage 101
12
+ # slug: vlan-group-3
13
+ # - name: VLAN group 4
14
+ # scope_type: "dcim.rack"
15
+ # scope: rack-01
16
+ # slug: vlan-group-4
17
+ # - name: VLAN group 5
18
+ # scope_type: "virtualization.cluster"
19
+ # scope: cluster1
20
+ # slug: vlan-group-5
21
+ # - name: VLAN group 6
22
+ # scope_type: "virtualization.clustergroup"
23
+ # scope: Group 1
24
+ # slug: vlan-group-6
Original file line number Diff line number Diff line change 1
1
import sys
2
2
3
- from dcim . models import Site
3
+ from django . contrib . contenttypes . models import ContentType
4
4
from ipam .models import VLANGroup
5
5
from startup_script_utils import load_yaml , pop_custom_fields , set_custom_fields_values
6
6
9
9
if vlan_groups is None :
10
10
sys .exit ()
11
11
12
- optional_assocs = {"site " : (Site , "name" )}
12
+ optional_assocs = {"scope " : (None , "name" )}
13
13
14
14
for params in vlan_groups :
15
15
custom_field_data = pop_custom_fields (params )
18
18
if assoc in params :
19
19
model , field = details
20
20
query = {field : params .pop (assoc )}
21
-
22
- params [assoc ] = model .objects .get (** query )
23
-
21
+ # Get model from Contenttype
22
+ scope_type = params .pop ("scope_type" , None )
23
+ if not scope_type :
24
+ print ("scope_type is missing from VLAN Group" )
25
+ continue
26
+ app_label , model = str (scope_type ).split ("." )
27
+ ct = ContentType .objects .get (app_label = app_label , model = model )
28
+ if not ct :
29
+ print (f"ContentType for app_label = '{ app_label } ' and model = '{ model } ' not found" )
30
+ continue
31
+ params ["scope_id" ] = ct .model_class ().objects .get (** query ).id
24
32
vlan_group , created = VLANGroup .objects .get_or_create (** params )
25
33
26
34
if created :
You can’t perform that action at this time.
0 commit comments