Skip to content

Commit 6819ffe

Browse files
authored
Remove ISODateTimeDescriptor and supported_fields in favor of direct domain fields. (#75)
1 parent a987275 commit 6819ffe

14 files changed

Lines changed: 54 additions & 150 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ master (XXXX-XX-XX)
66
--------------------
77

88
* Feature: Add 'created' property to SSH Key domain
9+
* Fix: Remove ISODatetime Descriptor because it leads to wrong dates
910

1011
1.6.2 (2019-10-15)
1112
-------------------

hcloud/actions/domain.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
from hcloud.core.domain import BaseDomain
2+
from dateutil.parser import isoparse
33

4-
from hcloud.helpers.descriptors import ISODateTime
4+
from hcloud.core.domain import BaseDomain
55

66

77
class Action(BaseDomain):
@@ -23,20 +23,17 @@ class Action(BaseDomain):
2323
STATUS_ERROR = "error"
2424
"""Action Status error"""
2525

26-
started = ISODateTime()
27-
finished = ISODateTime()
28-
2926
__slots__ = (
3027
"id",
3128
"command",
3229
"status",
3330
"progress",
3431
"resources",
3532
"error",
33+
"started",
34+
"finished"
3635
)
3736

38-
supported_fields = ("started", "finished")
39-
4037
def __init__(
4138
self,
4239
id,
@@ -53,8 +50,8 @@ def __init__(
5350

5451
self.status = status
5552
self.progress = progress
56-
self.started = started
57-
self.finished = finished
53+
self.started = isoparse(started) if started else None
54+
self.finished = isoparse(finished) if finished else None
5855
self.resources = resources
5956
self.error = error
6057

hcloud/core/domain.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,9 @@
55
class BaseDomain(object):
66
__slots__ = ()
77

8-
supported_fields = ()
9-
10-
@classmethod
11-
def get_supported_fields(cls):
12-
return set(cls.__slots__ + cls.supported_fields)
13-
148
@classmethod
159
def from_dict(cls, data):
16-
supported_fields = cls.get_supported_fields()
17-
supported_data = {k: v for k, v in data.items() if k in supported_fields}
10+
supported_data = {k: v for k, v in data.items() if k in cls.__slots__}
1811
return cls(**supported_data)
1912

2013

hcloud/floating_ips/domain.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
from hcloud.core.domain import BaseDomain
2+
from dateutil.parser import isoparse
33

4-
from hcloud.helpers.descriptors import ISODateTime
4+
from hcloud.core.domain import BaseDomain
55

66

77
class FloatingIP(BaseDomain):
@@ -43,10 +43,9 @@ class FloatingIP(BaseDomain):
4343
"blocked",
4444
"protection",
4545
"labels",
46-
"name"
46+
"name",
47+
"created"
4748
)
48-
created = ISODateTime()
49-
supported_fields = ("created",)
5049

5150
def __init__(
5251
self,
@@ -73,7 +72,7 @@ def __init__(
7372
self.blocked = blocked
7473
self.protection = protection
7574
self.labels = labels
76-
self.created = created
75+
self.created = isoparse(created) if created else None
7776
self.name = name
7877

7978

hcloud/helpers/descriptors.py

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

hcloud/images/domain.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
2+
from dateutil.parser import isoparse
3+
24
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
3-
from hcloud.helpers.descriptors import ISODateTime
45

56

67
class Image(BaseDomain, DomainIdentityMixin):
@@ -39,8 +40,6 @@ class Image(BaseDomain, DomainIdentityMixin):
3940
:param labels: Dict
4041
User-defined labels (key-value pairs)
4142
"""
42-
created = ISODateTime()
43-
deprecated = ISODateTime()
4443

4544
__slots__ = (
4645
"id",
@@ -56,11 +55,11 @@ class Image(BaseDomain, DomainIdentityMixin):
5655
"created_from",
5756
"status",
5857
"protection",
59-
"labels"
58+
"labels",
59+
"created",
60+
"deprecated"
6061
)
6162

62-
supported_fields = ("created", "deprecated")
63-
6463
def __init__(
6564
self,
6665
id=None,
@@ -84,11 +83,11 @@ def __init__(
8483
self.id = id
8584
self.name = name
8685
self.type = type
87-
self.created = created
86+
self.created = isoparse(created) if created else None
8887
self.description = description
8988
self.image_size = image_size
9089
self.disk_size = disk_size
91-
self.deprecated = deprecated
90+
self.deprecated = isoparse(deprecated) if deprecated else None
9291
self.bound_to = bound_to
9392
self.os_flavor = os_flavor
9493
self.os_version = os_version

hcloud/isos/domain.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
2+
from dateutil.parser import isoparse
3+
24
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
3-
from hcloud.helpers.descriptors import ISODateTime
45

56

67
class Iso(BaseDomain, DomainIdentityMixin):
@@ -17,17 +18,15 @@ class Iso(BaseDomain, DomainIdentityMixin):
1718
:param deprecated: datetime, None
1819
ISO 8601 timestamp of deprecation, None if ISO is still available. After the deprecation time it will no longer be possible to attach the ISO to servers.
1920
"""
20-
deprecated = ISODateTime()
2121

2222
__slots__ = (
2323
"id",
2424
"name",
2525
"type",
26-
"description"
26+
"description",
27+
"deprecated"
2728
)
2829

29-
supported_fields = ("deprecated", )
30-
3130
def __init__(
3231
self,
3332
id=None,
@@ -40,4 +39,4 @@ def __init__(
4039
self.name = name
4140
self.type = type
4241
self.description = description
43-
self.deprecated = deprecated
42+
self.deprecated = isoparse(deprecated) if deprecated else None

hcloud/networks/domain.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
2+
from dateutil.parser import isoparse
3+
24
from hcloud.core.domain import BaseDomain
3-
from hcloud.helpers.descriptors import ISODateTime
45

56

67
class Network(BaseDomain):
@@ -32,12 +33,10 @@ class Network(BaseDomain):
3233
"routes",
3334
"servers",
3435
"protection",
35-
"labels"
36+
"labels",
37+
"created"
3638
)
3739

38-
created = ISODateTime()
39-
supported_fields = ("created",)
40-
4140
def __init__(
4241
self,
4342
id,
@@ -52,7 +51,7 @@ def __init__(
5251
):
5352
self.id = id
5453
self.name = name
55-
self.created = created
54+
self.created = isoparse(created) if created else None
5655
self.ip_range = ip_range
5756
self.subnets = subnets
5857
self.routes = routes

hcloud/server_types/domain.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class ServerType(BaseDomain, DomainIdentityMixin):
2323
Type of server boot drive. Local has higher speed. Network has better availability. Choices: `local`, `network`
2424
:param cpu_type: string
2525
Type of cpu. Choices: `shared`, `dedicated`
26+
:param deprecated: bool
27+
True if server type is deprecated
2628
"""
2729
__slots__ = (
2830
"id",
@@ -33,7 +35,8 @@ class ServerType(BaseDomain, DomainIdentityMixin):
3335
"disk",
3436
"prices",
3537
"storage_type",
36-
"cpu_type"
38+
"cpu_type",
39+
"deprecated"
3740
)
3841

3942
def __init__(
@@ -46,8 +49,8 @@ def __init__(
4649
disk=None,
4750
prices=None,
4851
storage_type=None,
49-
cpu_type=None
50-
52+
cpu_type=None,
53+
deprecated=None
5154
):
5255
self.id = id
5356
self.name = name
@@ -58,3 +61,4 @@ def __init__(
5861
self.prices = prices
5962
self.storage_type = storage_type
6063
self.cpu_type = cpu_type
64+
self.deprecated = deprecated

hcloud/servers/domain.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2-
from hcloud.core.domain import BaseDomain
2+
from dateutil.parser import isoparse
33

4-
from hcloud.helpers.descriptors import ISODateTime
4+
from hcloud.core.domain import BaseDomain
55

66

77
class Server(BaseDomain):
@@ -78,13 +78,10 @@ class Server(BaseDomain):
7878
"protection",
7979
"labels",
8080
"volumes",
81-
"private_net"
81+
"private_net",
82+
"created"
8283
)
8384

84-
created = ISODateTime()
85-
86-
supported_fields = ("created",)
87-
8885
def __init__(
8986
self,
9087
id,
@@ -110,7 +107,7 @@ def __init__(
110107
self.id = id
111108
self.name = name
112109
self.status = status
113-
self.created = created
110+
self.created = isoparse(created) if created else None
114111
self.public_net = public_net
115112
self.server_type = server_type
116113
self.datacenter = datacenter

0 commit comments

Comments
 (0)