Skip to content

Commit 856c2ae

Browse files
author
Daryl Stark
committed
Created methods to retrieve and create contacts and connect them to tenants
1 parent 279a2f7 commit 856c2ae

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

netbox/tenancy.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ def get_choices(self, choice_id=None):
1616
def get_tenants(self, **kwargs):
1717
"""Returns the tenants"""
1818
return self.netbox_con.get('/tenancy/tenants/', **kwargs)
19+
20+
def get_contacts(self, **kwargs):
21+
"""Returns the contacts"""
22+
return self.netbox_con.get('/tenancy/contacts/', **kwargs)
23+
24+
def get_contact_assignments(self, **kwargs):
25+
"""Returns the contacts"""
26+
return self.netbox_con.get('/tenancy/contact-assignments/', **kwargs)
27+
28+
def get_contact_roles(self, **kwargs):
29+
"""Returns the roles for contacts"""
30+
return self.netbox_con.get('/tenancy/contact-roles/', **kwargs)
1931

2032
def create_tenant(self, name, slug, **kwargs):
2133
"""Create a new tenant
@@ -27,6 +39,32 @@ def create_tenant(self, name, slug, **kwargs):
2739
"""
2840
required_fields = {"name": name, "slug": slug}
2941
return self.netbox_con.post('/tenancy/tenants/', required_fields, **kwargs)
42+
43+
def create_contact(self, name: str, **kwargs):
44+
"""Create a new contact
45+
46+
:param name: Contact name
47+
:param kwargs: optional fields
48+
:return: netbox object if successful otherwise exception raised
49+
"""
50+
required_fields = {"name": name}
51+
return self.netbox_con.post('/tenancy/contacts/', required_fields, **kwargs)
52+
53+
def create_contact_assignment_tenant(self, contact_id: int, tenant_id: int, role_id: int, **kwargs):
54+
"""Connect a contect to a tenant
55+
56+
:param contact_display_name: Contact display name
57+
:param tenant_id: The ID of the tenant
58+
:param kwargs: optional fields
59+
:return: netbox object if successful otherwise exception raised
60+
"""
61+
required_fields = {
62+
"content_type": "tenancy.tenant",
63+
"object_id": tenant_id,
64+
"contact": contact_id,
65+
"role": role_id
66+
}
67+
return self.netbox_con.post('/tenancy/contact-assignments/', required_fields, **kwargs)
3068

3169
def delete_tenant(self, tenant_name):
3270
"""Delete tenant

0 commit comments

Comments
 (0)