iamkubi / pydactyl

Python wrapper for the Pterodactyl Panel API
MIT License
69 stars 21 forks source link

Allocations endpoint #3

Closed yamikaitou closed 4 years ago

yamikaitou commented 4 years ago

Requesting implementation of the Allocations endpoint (at least the fetching of the existing allocations)

iamkubi commented 4 years ago

Didn't realize this was missing, thanks for pointing it out. Should have it done today.

iamkubi commented 4 years ago

Implemented the allocation API in https://github.com/iamkubi/pydactyl/commit/ecab9b423901f3592067389512cedf27aa11eaa8 and pushed a 0.1.5 release.

I didn't test this, so let me know if you run into issues. Specifically I don't know if the range parsing works in the API or if I need to implement that myself, but I'll verify it later today.

yamikaitou commented 4 years ago

Thanks, tested the list_node_allocations function and it works, so my use-case is good.

Tested the create_allocations and delete_allocation functions as well and it seems to error when returning the result as the panel reflects the changes.

I tried it with dino.nodes.create_allocations(3, 'actual ip', ['27016','27017','27018']) and dino.nodes.create_allocations(3, 'actual ip', ['27019']) (API wanted an array of strings). Here is the traceback >>> dino.nodes.create_allocations(3, 'actual ip', ['27019']) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/user/.pyenv/versions/scgc/lib/python3.8/site-packages/pydactyl/api/nodes.py", line 114, in create_allocations response = self._api_request( File "/home/user/.pyenv/versions/scgc/lib/python3.8/site-packages/pydactyl/api/base.py", line 103, in _api_request return response.json() File "/home/user/.pyenv/versions/scgc/lib/python3.8/site-packages/requests/models.py", line 898, in json return complexjson.loads(self.text, **kwargs) File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/json/__init__.py", line 357, in loads return _default_decoder.decode(s) File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Using delete_allocations >>> dino.nodes.delete_allocation(3,25) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/user/.pyenv/versions/scgc/lib/python3.8/site-packages/pydactyl/api/nodes.py", line 127, in delete_allocation response = self._api_request( File "/home/user/.pyenv/versions/scgc/lib/python3.8/site-packages/pydactyl/api/base.py", line 103, in _api_request return response.json() File "/home/user/.pyenv/versions/scgc/lib/python3.8/site-packages/requests/models.py", line 898, in json return complexjson.loads(self.text, **kwargs) File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/json/__init__.py", line 357, in loads return _default_decoder.decode(s) File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/home/user/.pyenv/versions/3.8.2/lib/python3.8/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

iamkubi commented 4 years ago

Thanks for that. Should be an easy fix, will get another build within a few hours once I have a chance to validate it myself.