Skip to content

Commit 95340db

Browse files
authored
Add created property to Floating IP Domain (#42)
1 parent 131361e commit 95340db

4 files changed

Lines changed: 26 additions & 2 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 status filter for servers, images and volumes
9+
* Feature: Add 'created' property to Floating IP domain
910

1011
1.2.1 (2019-03-13)
1112
------------------

hcloud/floating_ips/domain.py

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

4+
from hcloud.helpers.descriptors import ISODateTime
5+
46

57
class FloatingIP(BaseDomain):
68
"""Floating IP Domain
@@ -25,6 +27,8 @@ class FloatingIP(BaseDomain):
2527
Protection configuration for the Floating IP
2628
:param labels: dict
2729
User-defined labels (key-value pairs)
30+
:param created: datetime
31+
Point in time when the Floating IP was created
2832
"""
2933
__slots__ = (
3034
"id",
@@ -38,6 +42,8 @@ class FloatingIP(BaseDomain):
3842
"protection",
3943
"labels"
4044
)
45+
created = ISODateTime()
46+
supported_fields = ("created",)
4147

4248
def __init__(
4349
self,
@@ -50,8 +56,8 @@ def __init__(
5056
home_location=None,
5157
blocked=None,
5258
protection=None,
53-
labels=None
54-
59+
labels=None,
60+
created=None
5561
):
5662
self.id = id
5763
self.type = type
@@ -63,6 +69,7 @@ def __init__(
6369
self.blocked = blocked
6470
self.protection = protection
6571
self.labels = labels
72+
self.created = created
6673

6774

6875
class CreateFloatingIPResponse(BaseDomain):

tests/unit/floating_ips/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def floating_ip_response():
77
"floating_ip": {
88
"id": 4711,
99
"description": "Web Frontend",
10+
"created": "2016-01-30T23:50+00:00",
1011
"ip": "131.232.99.1",
1112
"type": "ipv4",
1213
"server": 42,
@@ -41,6 +42,7 @@ def two_floating_ips_response():
4142
{
4243
"id": 4711,
4344
"description": "Web Frontend",
45+
"created": "2016-01-30T23:50+00:00",
4446
"ip": "131.232.99.1",
4547
"type": "ipv4",
4648
"server": 42,
@@ -68,6 +70,7 @@ def two_floating_ips_response():
6870
{
6971
"id": 4712,
7072
"description": "Web Backend",
73+
"created": "2016-01-30T23:50+00:00",
7174
"ip": "131.232.99.2",
7275
"type": "ipv4",
7376
"server": 42,
@@ -102,6 +105,7 @@ def floating_ip_create_response():
102105
"floating_ip": {
103106
"id": 4711,
104107
"description": "Web Frontend",
108+
"created": "2016-01-30T23:50+00:00",
105109
"ip": "131.232.99.1",
106110
"type": "ipv4",
107111
"server": 42,
@@ -154,6 +158,7 @@ def response_update_floating_ip():
154158

155159
"id": 4711,
156160
"description": "New description",
161+
"created": "2016-01-30T23:50+00:00",
157162
"ip": "131.232.99.1",
158163
"type": "ipv4",
159164
"server": 42,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import datetime
2+
from dateutil.tz import tzoffset
3+
4+
from hcloud.floating_ips.domain import FloatingIP
5+
6+
7+
class TestFloatingIP(object):
8+
9+
def test_created_is_datetime(self):
10+
floatingIP = FloatingIP(id=1, created="2016-01-30T23:50+00:00")
11+
assert floatingIP.created == datetime.datetime(2016, 1, 30, 23, 50, tzinfo=tzoffset(None, 0))

0 commit comments

Comments
 (0)