Skip to content

Commit f61653c

Browse files
committed
changes needed for newest version to work with ansible
1 parent 10017ca commit f61653c

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ setup_requires =
1818
install_requires =
1919
requests
2020
six
21+
python-dateutil
2122
tests_require =
2223
pytest==4.0.2
23-
packages =
24+
packages =
2425
upcloud_api
2526
upcloud_api.cloud_manager
2627

upcloud_api/cloud_manager/ip_address_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def get_ip(self, address):
2222
res = self.get_request('/ip_address/' + address)
2323
return IPAddress(cloud_manager=self, **res['ip_address'])
2424

25-
def get_ips(self):
25+
def get_ips(self, ignore_ips_without_server=False):
2626
"""
2727
Get all IPAddress objects from the API.
2828
"""
2929
res = self.get_request('/ip_address')
30-
IPs = IPAddress._create_ip_address_objs(res['ip_addresses'], cloud_manager=self)
30+
IPs = IPAddress._create_ip_address_objs(res['ip_addresses'], self, ignore_ips_without_server)
3131
return IPs
3232

3333
def attach_ip(self, server, family='IPv4'):

upcloud_api/ip_address.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class IPAddress(UpCloudResource):
1616
1717
The only updateable field is the ptr_record.
1818
19-
Note that all of the fields are not always available depending on the API call,
19+
Note that all of the fields are not always available depending on the API call,
2020
consult the official API docs for details.
2121
"""
2222

@@ -26,7 +26,7 @@ class IPAddress(UpCloudResource):
2626
'family': 'IPv4',
2727
'part_of_plan': None,
2828
'ptr_record': None,
29-
'server': None,
29+
'server': None
3030
}
3131

3232
def save(self):
@@ -51,7 +51,7 @@ def __str__(self):
5151
return self.address
5252

5353
@staticmethod
54-
def _create_ip_address_objs(ip_addresses, cloud_manager):
54+
def _create_ip_address_objs(ip_addresses, cloud_manager, ignore_ips_without_server=False):
5555
"""
5656
Create IPAddress objects from API response data.
5757
Also associates CloudManager with the objects.
@@ -65,7 +65,14 @@ def _create_ip_address_objs(ip_addresses, cloud_manager):
6565
if 'ip_address' in ip_addresses:
6666
ip_addresses = ip_addresses['ip_address']
6767

68+
filtered_ip_addresses = [] if ignore_ips_without_server else ip_addresses
69+
70+
if ignore_ips_without_server:
71+
for ip_addr in ip_addresses:
72+
if ip_addr.get('server'):
73+
filtered_ip_addresses.append(ip_addr)
74+
6875
return [
6976
IPAddress(cloud_manager=cloud_manager, **ip_addr)
70-
for ip_addr in ip_addresses
77+
for ip_addr in filtered_ip_addresses
7178
]

0 commit comments

Comments
 (0)