Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 23ee023

Browse files
committed
Add support empty Facility for IPAddress
In case fetch ips for a project with `state=all` a server returns objects with null facility. It happens when IP in Pending status. Signed-off-by: Dmitry Tyzhnenko <t.dmitry@gmail.com>
1 parent 84dab69 commit 23ee023

4 files changed

Lines changed: 190 additions & 1 deletion

File tree

packet/IPAddress.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def __init__(self, data, manager):
2222
self.customdata = data.get("customdata")
2323
self.project = data.get("project")
2424
self.project_lite = data.get("project_lite")
25-
self.facility = Facility(data.get("facility"))
25+
self.facility = \
26+
Facility(data.get("facility")) if data.get("facility") else None
2627
self.details = data.get("details")
2728
self.assigned_to = data.get("assigned_to")
2829
self.interface = data.get("interface")
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{"ip_addresses": [{
2+
"id": "99d5d741-3756-4ebe-a014-34ea7a2e2be1",
3+
"address_family": 4,
4+
"netmask": "255.255.255.254",
5+
"created_at": "2019-07-18T08:46:38Z",
6+
"details": null,
7+
"tags": [],
8+
"public": true,
9+
"cidr": 31,
10+
"management": true,
11+
"manageable": true,
12+
"enabled": true,
13+
"global_ip": null,
14+
"customdata": {},
15+
"project": {},
16+
"project_lite": {},
17+
"facility": {
18+
"id": "8e6470b3-b75e-47d1-bb93-45b225750975",
19+
"name": "Amsterdam, NL",
20+
"code": "ams1",
21+
"features": [
22+
"baremetal",
23+
"storage",
24+
"global_ipv4",
25+
"backend_transfer",
26+
"layer_2"
27+
],
28+
"address": {
29+
"href": "#0688e909-647e-4b21-bdf2-fc056d993fc5"
30+
},
31+
"ip_ranges": [
32+
"2604:1380:2000::/36",
33+
"147.75.204.0/23",
34+
"147.75.100.0/22",
35+
"147.75.80.0/22",
36+
"147.75.32.0/23"
37+
]
38+
},
39+
"assigned_to": {
40+
"href": "/devices/54ffd20d-d972-4c8d-8628-9da18e67ae17"
41+
},
42+
"interface": {
43+
"href": "/ports/02ea0556-df04-4554-b339-760a0d227b44"
44+
},
45+
"network": "147.75.84.94",
46+
"address": "147.75.84.95",
47+
"gateway": "147.75.84.94",
48+
"href": "/ips/99d5d741-3756-4ebe-a014-34ea7a2e2be1"
49+
},
50+
{
51+
"id": "99d5d741-3756-4ebe-a014-34ea7a2e2be2",
52+
"address_family": 4,
53+
"netmask": "255.255.255.254",
54+
"created_at": "2019-07-18T08:46:38Z",
55+
"details": null,
56+
"tags": [],
57+
"public": true,
58+
"cidr": 31,
59+
"management": true,
60+
"manageable": true,
61+
"enabled": true,
62+
"global_ip": null,
63+
"customdata": {},
64+
"project": {},
65+
"project_lite": {},
66+
"facility": {
67+
"id": "8e6470b3-b75e-47d1-bb93-45b225750975",
68+
"name": "Amsterdam, NL",
69+
"code": "ams1",
70+
"features": [
71+
"baremetal",
72+
"storage",
73+
"global_ipv4",
74+
"backend_transfer",
75+
"layer_2"
76+
],
77+
"address": {
78+
"href": "#0688e909-647e-4b21-bdf2-fc056d993fc5"
79+
},
80+
"ip_ranges": [
81+
"2604:1380:2000::/36",
82+
"147.75.204.0/23",
83+
"147.75.100.0/22",
84+
"147.75.80.0/22",
85+
"147.75.32.0/23"
86+
]
87+
},
88+
"assigned_to": {
89+
"href": "/devices/54ffd20d-d972-4c8d-8628-9da18e67ae17"
90+
},
91+
"interface": {
92+
"href": "/ports/02ea0556-df04-4554-b339-760a0d227b44"
93+
},
94+
"network": "147.75.84.94",
95+
"address": "147.75.84.95",
96+
"gateway": "147.75.84.94",
97+
"href": "/ips/99d5d741-3756-4ebe-a014-34ea7a2e2be1"
98+
}]}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{"ip_addresses": [{
2+
"id": "99d5d741-3756-4ebe-a014-34ea7a2e2be1",
3+
"address_family": 4,
4+
"netmask": "255.255.255.254",
5+
"created_at": "2019-07-18T08:46:38Z",
6+
"details": null,
7+
"tags": [],
8+
"public": true,
9+
"cidr": 31,
10+
"management": true,
11+
"manageable": true,
12+
"enabled": true,
13+
"global_ip": null,
14+
"customdata": {},
15+
"project": {},
16+
"project_lite": {},
17+
"facility": null,
18+
"assigned_to": {
19+
"href": "/devices/54ffd20d-d972-4c8d-8628-9da18e67ae17"
20+
},
21+
"interface": {
22+
"href": "/ports/02ea0556-df04-4554-b339-760a0d227b44"
23+
},
24+
"network": "147.75.84.94",
25+
"address": "147.75.84.95",
26+
"gateway": "147.75.84.94",
27+
"href": "/ips/99d5d741-3756-4ebe-a014-34ea7a2e2be1"
28+
},
29+
{
30+
"id": "99d5d741-3756-4ebe-a014-34ea7a2e2be2",
31+
"address_family": 4,
32+
"netmask": "255.255.255.254",
33+
"created_at": "2019-07-18T08:46:38Z",
34+
"details": null,
35+
"tags": [],
36+
"public": true,
37+
"cidr": 31,
38+
"management": true,
39+
"manageable": true,
40+
"enabled": true,
41+
"global_ip": null,
42+
"customdata": {},
43+
"project": {},
44+
"project_lite": {},
45+
"facility": {
46+
"id": "8e6470b3-b75e-47d1-bb93-45b225750975",
47+
"name": "Amsterdam, NL",
48+
"code": "ams1",
49+
"features": [
50+
"baremetal",
51+
"storage",
52+
"global_ipv4",
53+
"backend_transfer",
54+
"layer_2"
55+
],
56+
"address": {
57+
"href": "#0688e909-647e-4b21-bdf2-fc056d993fc5"
58+
},
59+
"ip_ranges": [
60+
"2604:1380:2000::/36",
61+
"147.75.204.0/23",
62+
"147.75.100.0/22",
63+
"147.75.80.0/22",
64+
"147.75.32.0/23"
65+
]
66+
},
67+
"assigned_to": {
68+
"href": "/devices/54ffd20d-d972-4c8d-8628-9da18e67ae17"
69+
},
70+
"interface": {
71+
"href": "/ports/02ea0556-df04-4554-b339-760a0d227b44"
72+
},
73+
"network": "147.75.84.94",
74+
"address": "147.75.84.95",
75+
"gateway": "147.75.84.94",
76+
"href": "/ips/99d5d741-3756-4ebe-a014-34ea7a2e2be1"
77+
}]}

test/test_packet.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ def test_list_device_ips(self):
222222
ips = self.manager.list_device_ips("e123s")
223223
self.assertIsNotNone(ips)
224224

225+
def test_list_projects_ips(self):
226+
ips = self.manager.list_project_ips("438659f0")
227+
self.assertIsNotNone(ips)
228+
for ip in ips:
229+
self.assertIsInstance(ip.facility, packet.Facility)
230+
231+
def test_list_projects_ips_state_all(self):
232+
ips = self.manager.list_project_ips(
233+
"438659f1", params={"state": "all"})
234+
self.assertIsNotNone(ips)
235+
self.assertIsNone(ips[0].facility)
236+
self.assertIsInstance(ips[1].facility, packet.Facility)
237+
225238

226239
class PacketMockManager(packet.Manager):
227240
def call_api(self, method, type="GET", params=None):

0 commit comments

Comments
 (0)