Skip to content

Commit c18226a

Browse files
authored
Merge pull request #82 from TechConsult/ansible-support
Ansible support
2 parents 709e499 + 3330e9b commit c18226a

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

setup.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ packages=['upcloud_api', 'upcloud_api.cloud_manager']
1111
license = MIT
1212

1313
[options]
14-
python_requires = >=3.6
14+
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4
1515
setup_requires =
1616
setuptools
1717
pytest-runner
1818
install_requires =
1919
python-dateutil
2020
requests
2121
six
22+
python-dateutil
2223
tests_require =
2324
pytest==4.0.2
24-
packages =
25+
packages =
2526
upcloud_api
2627
upcloud_api.cloud_manager
2728

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)