File tree Expand file tree Collapse file tree 6 files changed +126
-0
lines changed Expand file tree Collapse file tree 6 files changed +126
-0
lines changed Original file line number Diff line number Diff line change
1
+ # - name: Network-Team
2
+ # slug: network-team
3
+ # description: This is a new contact group for the Network-Team
4
+ # - name: New Contact Group
5
+ # slug: new-contact-group
6
+ # description: This is a new contact group sub under of Network-Team
7
+ # parent: Network-Team
Original file line number Diff line number Diff line change
1
+ # - name: New Contact Role
2
+ # slug: new-contact-role
3
+ # description: This is a new contact role description
Original file line number Diff line number Diff line change
1
+ # - name: Lee Widget
2
+ # title: CEO of Widget Corp
3
+ # phone: 221-555-1212
4
+ # email: widgetCEO@widgetcorp.com
5
+ # address: 1200 Nowhere Blvd, Scranton NJ, 555111
6
+ # comments: This is a very important contact
7
+ # - name: Ali Gator
8
+ # group: Network-Team
9
+ # title: Consultant for Widget Corp
10
+ # phone: 221-555-1213
11
+ # email: Consultant@widgetcorp.com
12
+ # address: 1200 Nowhere Blvd, Scranton NJ, 555111
13
+ # comments: This is a very important contact
14
+ # - name: Karlchen Maier
15
+ # group: New Contact Group
16
+ # title: COO of Widget Corp
17
+ # phone: 221-555-1214
18
+ # email: Karlchen@widgetcorp.com
19
+ # address: 1200 Nowhere Blvd, Scranton NJ, 555111
20
+ # comments: This is a very important contact
Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+ from startup_script_utils import (
4
+ load_yaml ,
5
+ pop_custom_fields ,
6
+ set_custom_fields_values ,
7
+ split_params ,
8
+ )
9
+ from tenancy .models import ContactGroup
10
+
11
+ contact_groups = load_yaml ("/opt/netbox/initializers/contact_groups.yml" )
12
+
13
+ if contact_groups is None :
14
+ sys .exit ()
15
+
16
+ optional_assocs = {"parent" : (ContactGroup , "name" )}
17
+
18
+ for params in contact_groups :
19
+ custom_field_data = pop_custom_fields (params )
20
+
21
+ for assoc , details in optional_assocs .items ():
22
+ if assoc in params :
23
+ model , field = details
24
+ query = {field : params .pop (assoc )}
25
+
26
+ params [assoc ] = model .objects .get (** query )
27
+
28
+ matching_params , defaults = split_params (params )
29
+ contact_group , created = ContactGroup .objects .get_or_create (
30
+ ** matching_params , defaults = defaults
31
+ )
32
+
33
+ if created :
34
+ print ("🔳 Created Contact Group" , contact_group .name )
35
+
36
+ set_custom_fields_values (contact_group , custom_field_data )
Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+ from startup_script_utils import (
4
+ load_yaml ,
5
+ pop_custom_fields ,
6
+ set_custom_fields_values ,
7
+ split_params ,
8
+ )
9
+ from tenancy .models import ContactRole
10
+
11
+ contact_roles = load_yaml ("/opt/netbox/initializers/contact_roles.yml" )
12
+
13
+ if contact_roles is None :
14
+ sys .exit ()
15
+
16
+
17
+ for params in contact_roles :
18
+ custom_field_data = pop_custom_fields (params )
19
+
20
+ matching_params , defaults = split_params (params )
21
+ contact_role , created = ContactRole .objects .get_or_create (** matching_params , defaults = defaults )
22
+
23
+ if created :
24
+ print ("🔳 Created Contact Role" , contact_role .name )
25
+
26
+ set_custom_fields_values (contact_role , custom_field_data )
Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+ from startup_script_utils import (
4
+ load_yaml ,
5
+ pop_custom_fields ,
6
+ set_custom_fields_values ,
7
+ split_params ,
8
+ )
9
+ from tenancy .models import Contact , ContactGroup
10
+
11
+ contacts = load_yaml ("/opt/netbox/initializers/contacts.yml" )
12
+
13
+ if contacts is None :
14
+ sys .exit ()
15
+
16
+ optional_assocs = {"group" : (ContactGroup , "name" )}
17
+
18
+ for params in contacts :
19
+ custom_field_data = pop_custom_fields (params )
20
+
21
+ for assoc , details in optional_assocs .items ():
22
+ if assoc in params :
23
+ model , field = details
24
+ query = {field : params .pop (assoc )}
25
+
26
+ params [assoc ] = model .objects .get (** query )
27
+
28
+ matching_params , defaults = split_params (params )
29
+ contact , created = Contact .objects .get_or_create (** matching_params , defaults = defaults )
30
+
31
+ if created :
32
+ print ("👩💻 Created Contact" , contact .name )
33
+
34
+ set_custom_fields_values (contact , custom_field_data )
You can’t perform that action at this time.
0 commit comments