Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created methods to create, retrieve, update and delete virtual chassi… #56

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
36 changes: 36 additions & 0 deletions netbox/dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,42 @@ def update_rack_group_by_id(self, rack_group_id, **kwargs):
"""
return self.netbox_con.patch('/dcim/rack-groups/', rack_group_id, **kwargs)

def create_virtual_chassis(self, name, **kwargs):
"""Create a new virtual chassis

:param name: Name of the virtual chassis
:param kwargs: Optional arguments
:return: netbox object if successful otherwise raise CreateException
"""
required_fields = {"name": name}
return self.netbox_con.post('/dcim/virtual-chassis/', required_fields, **kwargs)

def get_virtual_chassis(self, **kwargs):
"""Get all virtual chassis"""
return self.netbox_con.get('/dcim/virtual-chassis/', **kwargs)

def update_virtual_chassis(self, virtual_chassis_name, **kwargs):
"""Update virtual chassis by virtual chassis name

:param virtual_chassis_name: virtual chassis name to update
:param kwargs: requests body dict
:return: bool True if successful otherwise raise UpdateException
"""
device_id = self.get_virtual_chassis(name=virtual_chassis_name)[0]['id']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name is device_id. Now I assume you would do a self.get_devices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're right; I fixed it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

return self.netbox_con.patch('/dcim/virtual-chassis/', device_id, **kwargs)

def delete_virtual_chassis(self, virtual_chassis_name):
"""Delete virtual chassis by virtual chassis name name

:param virtual_chassis_name: Virtual chassis to delete
:return: bool True if successful otherwise raise DeleteException
"""
try:
device_id = self.get_virtual_chassis(name=virtual_chassis_name)[0]['id']
except IndexError:
raise exceptions.NotFoundException({"detail": "device: {}".format(virtual_chassis_name)}) from None
return self.netbox_con.delete('/dcim/virtual-chassis/', device_id)

def get_devices(self, **kwargs):
"""Get all devices"""
return self.netbox_con.get('/dcim/devices/', **kwargs)
Expand Down