File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
src/netbox_initializers/initializers Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,20 @@ def load_data(self):
2626
2727 matching_params , defaults = self .split_params (params )
2828
29+ asnFounds = []
2930 if defaults .get ("asns" , 0 ):
31+ for asn in defaults ["asns" ]:
32+ found = ASN .objects .filter (asn = asn ).first ()
33+ if found :
34+ asnFounds += [found ]
35+
36+ if len (defaults ["asns" ]) != len (asnFounds ):
37+ print (
38+ "⚠️ Unable to create Site '{0}': all ASNs could not be found" .format (
39+ params .get ("name" )
40+ )
41+ )
42+
3043 # asns will be assosciated below
3144 del defaults ["asns" ]
3245
@@ -35,15 +48,13 @@ def load_data(self):
3548 if created :
3649 print ("📍 Created site" , site .name )
3750
38- if params .get ("asns" , 0 ):
39- for asn in params ["asns" ]:
40- found = ASN .objects .filter (asn = asn ).first ()
51+ self .set_custom_fields_values (site , custom_field_data )
4152
42- if found :
43- site .asns .add (found )
44- print (" 👤 Assigned site %s asn %s" % (site .name , asn ))
53+ for asn in asnFounds :
54+ site .asns .add (asn )
55+ print (" 👤 Assigned asn %s to site %s" % (asn , site .name ))
4556
46- self . set_custom_fields_values ( site , custom_field_data )
57+ site . save ( )
4758
4859
4960register_initializer ("sites" , SiteInitializer )
You can’t perform that action at this time.
0 commit comments