Skip to content

Commit

Permalink
Revert "DeviceGroups: Add new API-Calls from lnms 24.2.0"
Browse files Browse the repository at this point in the history
  • Loading branch information
WhaleJ84 authored Jun 30, 2024
1 parent dc59de5 commit 4109b7f
Showing 1 changed file with 2 additions and 96 deletions.
98 changes: 2 additions & 96 deletions src/librenms_handler/device_groups/device_groups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Includes all the methods available to the DeviceGroups endpoint."""
from requests import delete, get, patch, post
from requests import get, post

from librenms_handler import LibreNMS

Expand Down Expand Up @@ -60,109 +60,15 @@ def add_devicegroups( # pylint: disable=R0913
verify=self.verify,
)

def delete_devicegroup(self, name: str):
"""
Deletes a device group.
:param name: name of the device group which can be obtained using get_devicegroups.
Please ensure that the name is urlencoded if it needs to be (i.e. Linux Servers would need to be urlencoded.)
"""
return delete(
f"{self.url}/{name}",
headers=self.headers,
verify=self.verify,
)

def update_devicegroups( # pylint: disable=R0913
self,
name: str,
new_name: str = None,
group_type: str = None,
desc: str = None,
rules: str = None,
devices: list = None,
):
"""
Updates a device group.
:param name: Name of the group
:param new_name: optional - New name for this group
:param group_type: optional - Should be `static` or `dynamic`.
Setting this to static requires that the devices input be provided.
:param desc: optional - Description of the device group
:param rules: required if type == dynamic.
A set of rules to determine which devices should be included in this device group
:param devices: required if type == static.
A list of devices that should be included in this group. This is a static list of devices
"""
data = {}
if new_name:
data.update({"name": new_name})
if group_type:
data.update({"type": group_type})
if desc:
data.update({"desc": desc})
if devices:
data.update({"devices": devices})
if rules:
data.update({"rules": rules})

return patch(
f"{self.url}/{name}",
json=data,
headers=self.headers,
verify=self.verify,
)

def get_devices_by_group(self, name: str):
"""
List all devices matching the group provided.
:param name: name of the device group which can be obtained using get_devicegroups.
Please ensure that the name is urlencoded if it needs to be (i.e. Linux Servers would need to be urlencoded.)
Please ensure that the name is urlencoded if it needs to be (i.e Linux Servers would need to be urlencoded.
"""
return get(
f"{self.url}/{name}",
headers=self.headers,
verify=self.verify,
)

def add_devices_to_group(
self,
name: str,
devices: list[str]
):
"""
Add devices to a device group.
:param name: name of the device group which can be obtained using get_devicegroups.
Please ensure that the name is urlencoded if it needs to be (i.e. Linux Servers would need to be urlencoded.)
:param devices: A list of devices to be added to the group.
"""
parameters = {"devices": devices}
return post(
f"{self.url}/{name}/devices",
json=parameters,
headers=self.headers,
verify=self.verify
)

def del_devices_from_group(
self,
name: str,
devices: list[str]
):
"""
Removes devices from a device group.
:param name: name of the device group which can be obtained using get_devicegroups.
Please ensure that the name is urlencoded if it needs to be (i.e. Linux Servers would need to be urlencoded.)
:param devices: A list of devices to be removed from the group.
"""
parameters = {"devices": devices}
return delete(
f"{self.url}/{name}/devices",
json=parameters,
headers=self.headers,
verify=self.verify
)

0 comments on commit 4109b7f

Please sign in to comment.