Skip to content

Commit 0f0697c

Browse files
committed
Resolve "Implement client for ISO endpoint"
1 parent 130af48 commit 0f0697c

13 files changed

Lines changed: 151 additions & 15 deletions

File tree

hcloud/hcloud.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import requests
55

66
from hcloud.actions.client import ActionsClient
7+
from hcloud.isos.client import IsosClient
78
from hcloud.servers.client import ServersClient
89
from hcloud.server_types.client import ServerTypesClient
910
from hcloud.volumes.client import VolumesClient
@@ -35,6 +36,7 @@ def __init__(self, token):
3536
self.volumes = VolumesClient(self)
3637
self.actions = ActionsClient(self)
3738
self.images = ImagesClient(self)
39+
self.isos = IsosClient(self)
3840

3941
def _get_user_agent(self):
4042
return "hcloud-python/" + self.version

hcloud/iso/client.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

hcloud/isos/client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
from hcloud.core.client import BoundModelBase, ClientEntityBase
3+
4+
from hcloud.isos.domain import Iso
5+
6+
7+
class BoundIso(BoundModelBase):
8+
model = Iso
9+
10+
11+
class IsosClient(ClientEntityBase):
12+
13+
def get_by_id(self, id):
14+
# type: (int) -> BoundIso
15+
response = self._client.request(url="/isos/{iso_id}".format(iso_id=id), method="GET")
16+
return BoundIso(self, response['iso'])
17+
18+
def get_all(self, name=None):
19+
# type: (Optional[str]) -> List[BoundIso]
20+
params = {}
21+
if name:
22+
params['name'] = name
23+
24+
response = self._client.request(url="/isos", method="GET", params=params)
25+
return [BoundIso(self, iso_data) for iso_data in response['isos']]

hcloud/servers/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from hcloud.core.client import ClientEntityBase, BoundModelBase
33

44
from hcloud.actions.client import BoundAction
5+
from hcloud.isos.client import BoundIso
56
from hcloud.servers.domain import Server, CreateServerResponse, ResetPasswordResponse, EnableRescueResponse, RequestConsoleResponse
67
from hcloud.volumes.client import BoundVolume
78
from hcloud.images.domain import CreateImageResponse
89
from hcloud.images.client import BoundImage
9-
from hcloud.iso.domain import Iso
1010
from hcloud.server_types.client import BoundServerType
1111
from hcloud.datacenters.client import BoundDatacenter
1212

@@ -31,8 +31,7 @@ def __init__(self, client, data, complete=False):
3131

3232
iso = data.get("iso", None)
3333
if iso is not None:
34-
# data['iso'] = BoundIso(client._client.iso, iso, complete=True) # When ISO Client is implemented
35-
data['iso'] = Iso(**iso)
34+
data['iso'] = BoundIso(client._client.isos, iso)
3635

3736
server_type = data.get("server_type")
3837
if server_type is not None:

tests/integration/isos/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class TestIsosClient(object):
2+
def test_get_by_id(self, hetzner_client):
3+
iso = hetzner_client.isos.get_by_id(1)
4+
assert iso.id == 4711
5+
assert iso.name == "FreeBSD-11.0-RELEASE-amd64-dvd1"
6+
assert iso.description == "FreeBSD 11.0 x64"
7+
assert iso.type == "public"
8+
9+
def test_get_all(self, hetzner_client):
10+
isos = hetzner_client.isos.get_all()
11+
assert isos[0].id == 4711
12+
assert isos[0].name == "FreeBSD-11.0-RELEASE-amd64-dvd1"
13+
assert isos[0].description == "FreeBSD 11.0 x64"
14+
assert isos[0].type == "public"

tests/integration/servers/test_servers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from hcloud.servers.domain import Server
66
from hcloud.volumes.domain import Volume
77
from hcloud.images.domain import Image
8-
from hcloud.iso.domain import Iso
8+
from hcloud.isos.domain import Iso
99
from hcloud.server_types.domain import ServerType
1010
from hcloud.locations.domain import Location
1111

tests/unit/iso/conftest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
3+
4+
@pytest.fixture()
5+
def iso_response():
6+
return {
7+
"iso": {
8+
"id": 4711,
9+
"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
10+
"description": "FreeBSD 11.0 x64",
11+
"type": "public",
12+
"deprecated": "2018-02-28T00:00:00+00:00"
13+
}
14+
}
15+
16+
17+
@pytest.fixture()
18+
def two_isos_response():
19+
return {
20+
"isos": [
21+
{
22+
"id": 4711,
23+
"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
24+
"description": "FreeBSD 11.0 x64",
25+
"type": "public",
26+
"deprecated": "2018-02-28T00:00:00+00:00"
27+
},
28+
{
29+
"id": 4712,
30+
"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
31+
"description": "FreeBSD 11.0 x64",
32+
"type": "public",
33+
"deprecated": "2018-02-28T00:00:00+00:00"
34+
}
35+
]
36+
}

0 commit comments

Comments
 (0)