@@ -7,7 +7,7 @@ def __init__(self, netbox_con):
77 self .netbox_con = netbox_con
88
99 def get_sites (self , ** kwargs ):
10- """Returns the available sites"""
10+ """Returns all available sites"""
1111 return self .netbox_con .get ('/dcim/sites/' , ** kwargs )
1212
1313 def create_site (self , name , slug , ** kwargs ):
@@ -47,7 +47,7 @@ def update_site(self, site_name, **kwargs):
4747 return self .netbox_con .patch ('/dcim/sites/' , site_id , ** kwargs )
4848
4949 def get_racks (self , ** kwargs ):
50- """Returns the available racks"""
50+ """Returns all available racks"""
5151 return self .netbox_con .get ('/dcim/racks/' , ** kwargs )
5252
5353 def create_rack (self , name , site_name , ** kwargs ):
@@ -90,6 +90,51 @@ def update_rack(self, rack_name, **kwargs):
9090 raise exceptions .NotFoundException ('rack: {}' .format (rack_name )) from None
9191 return self .netbox_con .patch ('/dcim/racks/' , rack_id , ** kwargs )
9292
93+ def get_rack_groups (self , ** kwargs ):
94+ """Returns all available rack groups"""
95+ return self .netbox_con .get ('/dcim/rack-groups/' , ** kwargs )
96+
97+ def create_rack_group (self , name , slug , site_name , ** kwargs ):
98+ """Create new rack group
99+
100+ :param name: Rack group name
101+ :param slug: slug name
102+ :param site_name: The site at which the rack exists
103+ :param kwargs: Optional arguments
104+ :return: netbox object if successful otherwise create exception
105+ """
106+ try :
107+ site_id = self .get_sites (name = site_name )[0 ]['id' ]
108+ except IndexError :
109+ raise exceptions .NotFoundException ('site: {}' .format (site_name )) from None
110+ required_fields = {"name" : name , "slug" : slug , "site" : site_id }
111+ return self .netbox_con .post ('/dcim/rack-groups/' , required_fields , ** kwargs )
112+
113+ def delete_rack_group (self , name ):
114+ """Delete rack group
115+
116+ :param name: Name of the rack group to delete
117+ :return: bool True if successful otherwise raise DeleteException
118+ """
119+ try :
120+ rack_group_id = self .get_rack_groups (name = name )[0 ]['id' ]
121+ except IndexError :
122+ raise exceptions .NotFoundException ('rack-group: {}' .format (name )) from None
123+ return self .netbox_con .delete ('/dcim/rack-groups/' , rack_group_id )
124+
125+ def update_rack_group (self , name , ** kwargs ):
126+ """
127+
128+ :param name: Rack group name to update
129+ :param kwargs: requests body dict
130+ :return: bool True if successful otherwise raise UpdateException
131+ """
132+ try :
133+ rack_group_id = self .get_rack_groups (name = name )[0 ]['id' ]
134+ except IndexError :
135+ raise exceptions .NotFoundException ('rack group: {}' .format (name )) from None
136+ return self .netbox_con .patch ('/dcim/rack-groups/' , rack_group_id , ** kwargs )
137+
93138 def get_devices (self , ** kwargs ):
94139 """Get all devices"""
95140 return self .netbox_con .get ('/dcim/devices/' , ** kwargs )
0 commit comments