File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ # - name: cage 101
2
+ # slug: cage-101
3
+ # site: SING 1
Original file line number Diff line number Diff line change 16
16
# text_field: Description
17
17
# - site: SING 1
18
18
# name: rack-03
19
+ # group: cage 101
19
20
# role: Role 3
20
21
# type: 4-post cabinet
21
22
# width: 19 inches
Original file line number Diff line number Diff line change
1
+ from dcim .models import Site ,RackGroup
2
+ from ruamel .yaml import YAML
3
+
4
+ from pathlib import Path
5
+ import sys
6
+
7
+ file = Path ('/opt/netbox/initializers/rack_groups.yml' )
8
+ if not file .is_file ():
9
+ sys .exit ()
10
+
11
+ with file .open ('r' ) as stream :
12
+ yaml = YAML (typ = 'safe' )
13
+ rack_groups = yaml .load (stream )
14
+
15
+ required_assocs = {
16
+ 'site' : (Site , 'name' )
17
+ }
18
+
19
+ if rack_groups is not None :
20
+ for params in rack_groups :
21
+
22
+ for assoc , details in required_assocs .items ():
23
+ model , field = details
24
+ query = { field : params .pop (assoc ) }
25
+ params [assoc ] = model .objects .get (** query )
26
+
27
+ rack_group , created = RackGroup .objects .get_or_create (** params )
28
+
29
+ if created :
30
+ print ("🎨 Created rack group" , rack_group .name )
31
+
You can’t perform that action at this time.
0 commit comments