-
-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from Lon1/contact-startups
Contact startups
- Loading branch information
Showing
6 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# - name: Network-Team | ||
# slug: network-team | ||
# description: This is a new contact group for the Network-Team | ||
# - name: New Contact Group | ||
# slug: new-contact-group | ||
# description: This is a new contact group sub under of Network-Team | ||
# parent: Network-Team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# - name: New Contact Role | ||
# slug: new-contact-role | ||
# description: This is a new contact role description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# - name: Lee Widget | ||
# title: CEO of Widget Corp | ||
# phone: 221-555-1212 | ||
# email: [email protected] | ||
# address: 1200 Nowhere Blvd, Scranton NJ, 555111 | ||
# comments: This is a very important contact | ||
# - name: Ali Gator | ||
# group: Network-Team | ||
# title: Consultant for Widget Corp | ||
# phone: 221-555-1213 | ||
# email: [email protected] | ||
# address: 1200 Nowhere Blvd, Scranton NJ, 555111 | ||
# comments: This is a very important contact | ||
# - name: Karlchen Maier | ||
# group: New Contact Group | ||
# title: COO of Widget Corp | ||
# phone: 221-555-1214 | ||
# email: [email protected] | ||
# address: 1200 Nowhere Blvd, Scranton NJ, 555111 | ||
# comments: This is a very important contact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
|
||
from startup_script_utils import ( | ||
load_yaml, | ||
pop_custom_fields, | ||
set_custom_fields_values, | ||
split_params, | ||
) | ||
from tenancy.models import ContactGroup | ||
|
||
contact_groups = load_yaml("/opt/netbox/initializers/contact_groups.yml") | ||
|
||
if contact_groups is None: | ||
sys.exit() | ||
|
||
optional_assocs = {"parent": (ContactGroup, "name")} | ||
|
||
for params in contact_groups: | ||
custom_field_data = pop_custom_fields(params) | ||
|
||
for assoc, details in optional_assocs.items(): | ||
if assoc in params: | ||
model, field = details | ||
query = {field: params.pop(assoc)} | ||
|
||
params[assoc] = model.objects.get(**query) | ||
|
||
matching_params, defaults = split_params(params) | ||
contact_group, created = ContactGroup.objects.get_or_create( | ||
**matching_params, defaults=defaults | ||
) | ||
|
||
if created: | ||
print("🔳 Created Contact Group", contact_group.name) | ||
|
||
set_custom_fields_values(contact_group, custom_field_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
|
||
from startup_script_utils import ( | ||
load_yaml, | ||
pop_custom_fields, | ||
set_custom_fields_values, | ||
split_params, | ||
) | ||
from tenancy.models import ContactRole | ||
|
||
contact_roles = load_yaml("/opt/netbox/initializers/contact_roles.yml") | ||
|
||
if contact_roles is None: | ||
sys.exit() | ||
|
||
|
||
for params in contact_roles: | ||
custom_field_data = pop_custom_fields(params) | ||
|
||
matching_params, defaults = split_params(params) | ||
contact_role, created = ContactRole.objects.get_or_create(**matching_params, defaults=defaults) | ||
|
||
if created: | ||
print("🔳 Created Contact Role", contact_role.name) | ||
|
||
set_custom_fields_values(contact_role, custom_field_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
|
||
from startup_script_utils import ( | ||
load_yaml, | ||
pop_custom_fields, | ||
set_custom_fields_values, | ||
split_params, | ||
) | ||
from tenancy.models import Contact, ContactGroup | ||
|
||
contacts = load_yaml("/opt/netbox/initializers/contacts.yml") | ||
|
||
if contacts is None: | ||
sys.exit() | ||
|
||
optional_assocs = {"group": (ContactGroup, "name")} | ||
|
||
for params in contacts: | ||
custom_field_data = pop_custom_fields(params) | ||
|
||
for assoc, details in optional_assocs.items(): | ||
if assoc in params: | ||
model, field = details | ||
query = {field: params.pop(assoc)} | ||
|
||
params[assoc] = model.objects.get(**query) | ||
|
||
matching_params, defaults = split_params(params) | ||
contact, created = Contact.objects.get_or_create(**matching_params, defaults=defaults) | ||
|
||
if created: | ||
print("👩💻 Created Contact", contact.name) | ||
|
||
set_custom_fields_values(contact, custom_field_data) |