Skip to content

Commit

Permalink
Merge pull request #53 from DarylStark/contacts
Browse files Browse the repository at this point in the history
Created methods to retrieve and create contacts and connect them to …
  • Loading branch information
jagter committed Aug 12, 2022
2 parents 279a2f7 + 856c2ae commit eef3bd2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions netbox/tenancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ def get_choices(self, choice_id=None):
def get_tenants(self, **kwargs):
"""Returns the tenants"""
return self.netbox_con.get('/tenancy/tenants/', **kwargs)

def get_contacts(self, **kwargs):
"""Returns the contacts"""
return self.netbox_con.get('/tenancy/contacts/', **kwargs)

def get_contact_assignments(self, **kwargs):
"""Returns the contacts"""
return self.netbox_con.get('/tenancy/contact-assignments/', **kwargs)

def get_contact_roles(self, **kwargs):
"""Returns the roles for contacts"""
return self.netbox_con.get('/tenancy/contact-roles/', **kwargs)

def create_tenant(self, name, slug, **kwargs):
"""Create a new tenant
Expand All @@ -27,6 +39,32 @@ def create_tenant(self, name, slug, **kwargs):
"""
required_fields = {"name": name, "slug": slug}
return self.netbox_con.post('/tenancy/tenants/', required_fields, **kwargs)

def create_contact(self, name: str, **kwargs):
"""Create a new contact
:param name: Contact name
:param kwargs: optional fields
:return: netbox object if successful otherwise exception raised
"""
required_fields = {"name": name}
return self.netbox_con.post('/tenancy/contacts/', required_fields, **kwargs)

def create_contact_assignment_tenant(self, contact_id: int, tenant_id: int, role_id: int, **kwargs):
"""Connect a contect to a tenant
:param contact_display_name: Contact display name
:param tenant_id: The ID of the tenant
:param kwargs: optional fields
:return: netbox object if successful otherwise exception raised
"""
required_fields = {
"content_type": "tenancy.tenant",
"object_id": tenant_id,
"contact": contact_id,
"role": role_id
}
return self.netbox_con.post('/tenancy/contact-assignments/', required_fields, **kwargs)

def delete_tenant(self, tenant_name):
"""Delete tenant
Expand Down

0 comments on commit eef3bd2

Please sign in to comment.