Skip to content

Commit

Permalink
Update servers.py for includes and params
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkubi committed Oct 13, 2022
1 parent 539e2e8 commit 0aab24a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
26 changes: 17 additions & 9 deletions pydactyl/api/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@
class Servers(base.PterodactylAPI):
"""Class for interacting with the Pterdactyl Servers API."""

def list_servers(self, includes=None):
def list_servers(self, includes=None, params=None):
"""List all servers.
Args:
includes(iter): List of includes, e.g. ('servers', 'allocations')
includes(iter): List of includes, e.g. ('allocations', 'node')
params(dict): Extra parameters to pass, e.g. {'per_page': 300}
"""
endpoint = 'application/servers'
response = base.parse_response(
self._api_request(endpoint=endpoint, includes=includes),
self._api_request(endpoint=endpoint, includes=includes,
params=params),
detail=True)
return PaginatedResponse(self, endpoint, response)

def get_server_info(self, server_id=None, external_id=None, detail=False,
includes=None):
includes=None, params=None):
"""Get detailed info for the specified server.
Args:
server_id(int): Pterodactyl Server ID.
external_id(int): Server ID from an external system like WHMCS
detail(bool): If True includes created and updated timestamps.
includes(iter): List of includes, e.g. ('egg', 'allocations')
params(dict): Extra parameters to pass, e.g. {'per_page': 300}
"""
if not server_id and not external_id:
raise BadRequestError('Must specify either server_id or '
Expand All @@ -40,7 +43,8 @@ def get_server_info(self, server_id=None, external_id=None, detail=False,
else:
endpoint = 'application/servers/external/{}'.format(external_id)

response = self._api_request(endpoint=endpoint, includes=includes)
response = self._api_request(endpoint=endpoint, includes=includes,
params=params)
return base.parse_response(response, detail)

def suspend_server(self, server_id):
Expand Down Expand Up @@ -105,19 +109,21 @@ def delete_server(self, server_id, force=False):
response = self._api_request(endpoint=endpoint, mode='DELETE')
return response

def list_server_databases(self, server_id, includes=None):
def list_server_databases(self, server_id, includes=None, params=None):
"""List the database servers assigned to the specified server ID.
Args:
server_id(int): Pterodactyl Server ID.
includes(iter): List of includes, e.g. ('password', 'host')
params(dict): Extra parameters to pass, e.g. {'per_page': 300}
"""
endpoint = 'application/servers/{}/databases'.format(server_id)
response = self._api_request(endpoint=endpoint, includes=includes)
response = self._api_request(endpoint=endpoint, includes=includes,
params=params)
return PaginatedResponse(self, endpoint, response)

def get_server_database_info(self, server_id, database_id, detail=False,
includes=None):
includes=None, params=None):
"""Get information about the specified database on the specified server.
Args:
Expand All @@ -126,10 +132,12 @@ def get_server_database_info(self, server_id, database_id, detail=False,
detail(bool): If True includes the object type and a nested data
structure.
includes(iter): List of includes, e.g. ('password', 'host')
params(dict): Extra parameters to pass, e.g. {'per_page': 300}
"""
endpoint = 'application/servers/{}/databases/{}'.format(server_id,
database_id)
response = self._api_request(endpoint=endpoint, includes=includes)
response = self._api_request(endpoint=endpoint, includes=includes,
params=params)
return base.parse_response(response, detail)

def create_server_database(self, server_id):
Expand Down
5 changes: 5 additions & 0 deletions tests/application/servers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_list_servers(self, mock_api):
expected = {
'endpoint': 'application/servers',
'includes': None,
'params': None,
}
self.client.servers.list_servers()
mock_api.assert_called_with(**expected)
Expand All @@ -23,6 +24,7 @@ def test_get_server_info_by_external_id(self, mock_api):
expected = {
'endpoint': 'application/servers/external/11',
'includes': None,
'params': None,
}
self.client.servers.get_server_info(external_id=11)
mock_api.assert_called_with(**expected)
Expand All @@ -32,6 +34,7 @@ def test_get_server_info_by_server_id(self, mock_api):
expected = {
'endpoint': 'application/servers/22',
'includes': None,
'params': None,
}
self.client.servers.get_server_info(server_id=22)
mock_api.assert_called_with(**expected)
Expand Down Expand Up @@ -103,6 +106,7 @@ def test_list_server_databases(self, mock_api):
expected = {
'endpoint': 'application/servers/99/databases',
'includes': None,
'params': None,
}
self.client.servers.list_server_databases(server_id=99)
mock_api.assert_called_with(**expected)
Expand All @@ -112,6 +116,7 @@ def test_get_server_database_info(self, mock_api):
expected = {
'endpoint': 'application/servers/111/databases/5',
'includes': None,
'params': None,
}
self.client.servers.get_server_database_info(server_id=111,
database_id=5)
Expand Down

0 comments on commit 0aab24a

Please sign in to comment.