Skip to content

Commit

Permalink
Remove ISODateTimeDescriptor and supported_fields in favor of direct …
Browse files Browse the repository at this point in the history
…domain fields. (#75)
  • Loading branch information
LKaemmerling authored Jan 9, 2020
1 parent a987275 commit 6819ffe
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 150 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ master (XXXX-XX-XX)
--------------------

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

1.6.2 (2019-10-15)
-------------------
Expand Down
15 changes: 6 additions & 9 deletions hcloud/actions/domain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from hcloud.core.domain import BaseDomain
from dateutil.parser import isoparse

from hcloud.helpers.descriptors import ISODateTime
from hcloud.core.domain import BaseDomain


class Action(BaseDomain):
Expand All @@ -23,20 +23,17 @@ class Action(BaseDomain):
STATUS_ERROR = "error"
"""Action Status error"""

started = ISODateTime()
finished = ISODateTime()

__slots__ = (
"id",
"command",
"status",
"progress",
"resources",
"error",
"started",
"finished"
)

supported_fields = ("started", "finished")

def __init__(
self,
id,
Expand All @@ -53,8 +50,8 @@ def __init__(

self.status = status
self.progress = progress
self.started = started
self.finished = finished
self.started = isoparse(started) if started else None
self.finished = isoparse(finished) if finished else None
self.resources = resources
self.error = error

Expand Down
9 changes: 1 addition & 8 deletions hcloud/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@
class BaseDomain(object):
__slots__ = ()

supported_fields = ()

@classmethod
def get_supported_fields(cls):
return set(cls.__slots__ + cls.supported_fields)

@classmethod
def from_dict(cls, data):
supported_fields = cls.get_supported_fields()
supported_data = {k: v for k, v in data.items() if k in supported_fields}
supported_data = {k: v for k, v in data.items() if k in cls.__slots__}
return cls(**supported_data)


Expand Down
11 changes: 5 additions & 6 deletions hcloud/floating_ips/domain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from hcloud.core.domain import BaseDomain
from dateutil.parser import isoparse

from hcloud.helpers.descriptors import ISODateTime
from hcloud.core.domain import BaseDomain


class FloatingIP(BaseDomain):
Expand Down Expand Up @@ -43,10 +43,9 @@ class FloatingIP(BaseDomain):
"blocked",
"protection",
"labels",
"name"
"name",
"created"
)
created = ISODateTime()
supported_fields = ("created",)

def __init__(
self,
Expand All @@ -73,7 +72,7 @@ def __init__(
self.blocked = blocked
self.protection = protection
self.labels = labels
self.created = created
self.created = isoparse(created) if created else None
self.name = name


Expand Down
17 changes: 0 additions & 17 deletions hcloud/helpers/descriptors.py

This file was deleted.

15 changes: 7 additions & 8 deletions hcloud/images/domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse

from hcloud.core.domain import BaseDomain, DomainIdentityMixin
from hcloud.helpers.descriptors import ISODateTime


class Image(BaseDomain, DomainIdentityMixin):
Expand Down Expand Up @@ -39,8 +40,6 @@ class Image(BaseDomain, DomainIdentityMixin):
:param labels: Dict
User-defined labels (key-value pairs)
"""
created = ISODateTime()
deprecated = ISODateTime()

__slots__ = (
"id",
Expand All @@ -56,11 +55,11 @@ class Image(BaseDomain, DomainIdentityMixin):
"created_from",
"status",
"protection",
"labels"
"labels",
"created",
"deprecated"
)

supported_fields = ("created", "deprecated")

def __init__(
self,
id=None,
Expand All @@ -84,11 +83,11 @@ def __init__(
self.id = id
self.name = name
self.type = type
self.created = created
self.created = isoparse(created) if created else None
self.description = description
self.image_size = image_size
self.disk_size = disk_size
self.deprecated = deprecated
self.deprecated = isoparse(deprecated) if deprecated else None
self.bound_to = bound_to
self.os_flavor = os_flavor
self.os_version = os_version
Expand Down
11 changes: 5 additions & 6 deletions hcloud/isos/domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse

from hcloud.core.domain import BaseDomain, DomainIdentityMixin
from hcloud.helpers.descriptors import ISODateTime


class Iso(BaseDomain, DomainIdentityMixin):
Expand All @@ -17,17 +18,15 @@ class Iso(BaseDomain, DomainIdentityMixin):
:param deprecated: datetime, None
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.
"""
deprecated = ISODateTime()

__slots__ = (
"id",
"name",
"type",
"description"
"description",
"deprecated"
)

supported_fields = ("deprecated", )

def __init__(
self,
id=None,
Expand All @@ -40,4 +39,4 @@ def __init__(
self.name = name
self.type = type
self.description = description
self.deprecated = deprecated
self.deprecated = isoparse(deprecated) if deprecated else None
11 changes: 5 additions & 6 deletions hcloud/networks/domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse

from hcloud.core.domain import BaseDomain
from hcloud.helpers.descriptors import ISODateTime


class Network(BaseDomain):
Expand Down Expand Up @@ -32,12 +33,10 @@ class Network(BaseDomain):
"routes",
"servers",
"protection",
"labels"
"labels",
"created"
)

created = ISODateTime()
supported_fields = ("created",)

def __init__(
self,
id,
Expand All @@ -52,7 +51,7 @@ def __init__(
):
self.id = id
self.name = name
self.created = created
self.created = isoparse(created) if created else None
self.ip_range = ip_range
self.subnets = subnets
self.routes = routes
Expand Down
10 changes: 7 additions & 3 deletions hcloud/server_types/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ServerType(BaseDomain, DomainIdentityMixin):
Type of server boot drive. Local has higher speed. Network has better availability. Choices: `local`, `network`
:param cpu_type: string
Type of cpu. Choices: `shared`, `dedicated`
:param deprecated: bool
True if server type is deprecated
"""
__slots__ = (
"id",
Expand All @@ -33,7 +35,8 @@ class ServerType(BaseDomain, DomainIdentityMixin):
"disk",
"prices",
"storage_type",
"cpu_type"
"cpu_type",
"deprecated"
)

def __init__(
Expand All @@ -46,8 +49,8 @@ def __init__(
disk=None,
prices=None,
storage_type=None,
cpu_type=None

cpu_type=None,
deprecated=None
):
self.id = id
self.name = name
Expand All @@ -58,3 +61,4 @@ def __init__(
self.prices = prices
self.storage_type = storage_type
self.cpu_type = cpu_type
self.deprecated = deprecated
13 changes: 5 additions & 8 deletions hcloud/servers/domain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from hcloud.core.domain import BaseDomain
from dateutil.parser import isoparse

from hcloud.helpers.descriptors import ISODateTime
from hcloud.core.domain import BaseDomain


class Server(BaseDomain):
Expand Down Expand Up @@ -78,13 +78,10 @@ class Server(BaseDomain):
"protection",
"labels",
"volumes",
"private_net"
"private_net",
"created"
)

created = ISODateTime()

supported_fields = ("created",)

def __init__(
self,
id,
Expand All @@ -110,7 +107,7 @@ def __init__(
self.id = id
self.name = name
self.status = status
self.created = created
self.created = isoparse(created) if created else None
self.public_net = public_net
self.server_type = server_type
self.datacenter = datacenter
Expand Down
12 changes: 5 additions & 7 deletions hcloud/ssh_keys/domain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
from dateutil.parser import isoparse

from hcloud.helpers.descriptors import ISODateTime
from hcloud.core.domain import BaseDomain, DomainIdentityMixin


class SSHKey(BaseDomain, DomainIdentityMixin):
Expand All @@ -25,12 +25,10 @@ class SSHKey(BaseDomain, DomainIdentityMixin):
"name",
"fingerprint",
"public_key",
"labels"
"labels",
"created"
)

created = ISODateTime()
supported_fields = ("created",)

def __init__(
self,
id=None,
Expand All @@ -45,4 +43,4 @@ def __init__(
self.fingerprint = fingerprint
self.public_key = public_key
self.labels = labels
self.created = created
self.created = isoparse(created) if created else None
12 changes: 5 additions & 7 deletions hcloud/volumes/domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from dateutil.parser import isoparse

from hcloud.core.domain import BaseDomain, DomainIdentityMixin
from hcloud.helpers.descriptors import ISODateTime


class Volume(BaseDomain, DomainIdentityMixin):
Expand Down Expand Up @@ -34,8 +35,6 @@ class Volume(BaseDomain, DomainIdentityMixin):
STATUS_AVAILABLE = "available"
"""Volume Status available"""

created = ISODateTime()

__slots__ = (
"id",
"name",
Expand All @@ -46,11 +45,10 @@ class Volume(BaseDomain, DomainIdentityMixin):
"format",
"protection",
"labels",
"status"
"status",
"created"
)

supported_fields = ("created",)

def __init__(
self,
id,
Expand All @@ -69,7 +67,7 @@ def __init__(
self.id = id
self.name = name
self.server = server
self.created = created
self.created = isoparse(created) if created else None
self.location = location
self.size = size
self.linux_device = linux_device
Expand Down
Loading

0 comments on commit 6819ffe

Please sign in to comment.