mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Use pools or ranges depending on the package version.
This commit is contained in:
parent
7fd37ea247
commit
58aa521f68
2 changed files with 12 additions and 1 deletions
4
changelogs/fragments/8248-linode-rename.yml
Normal file
4
changelogs/fragments/8248-linode-rename.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
bugfixes:
|
||||||
|
- "linode inventory plugin - linode_api4 renamed the IPv6 ``pools`` to ``ranges`` in version 5.4.1. The plugin now checks the package
|
||||||
|
version to use the appropriate name (https://github.com/ansible-collections/community.general/issues/8213,
|
||||||
|
https://github.com/ansible-collections/community.general/pull/8248)."
|
|
@ -124,10 +124,12 @@ from ansible.errors import AnsibleError
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||||
|
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from linode_api4 import LinodeClient
|
from linode_api4 import LinodeClient
|
||||||
|
from linode_api4.linode_client import package_version
|
||||||
from linode_api4.objects.linode import Instance
|
from linode_api4.objects.linode import Instance
|
||||||
from linode_api4.errors import ApiError as LinodeApiError
|
from linode_api4.errors import ApiError as LinodeApiError
|
||||||
HAS_LINODE = True
|
HAS_LINODE = True
|
||||||
|
@ -219,7 +221,12 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
if ip_style == 'api':
|
if ip_style == 'api':
|
||||||
ips = instance.ips.ipv4.public + instance.ips.ipv4.private
|
ips = instance.ips.ipv4.public + instance.ips.ipv4.private
|
||||||
ips += [instance.ips.ipv6.slaac, instance.ips.ipv6.link_local]
|
ips += [instance.ips.ipv6.slaac, instance.ips.ipv6.link_local]
|
||||||
ips += instance.ips.ipv6.pools
|
# linode_api4 renamed pools to ranges in 5.4.1 (https://github.com/linode/linode_api4-python/releases/tag/v5.4.1,
|
||||||
|
# https://github.com/linode/linode_api4-python/commit/dc592c706518abc1c6d4b4c88b074970e5375d5f)
|
||||||
|
if LooseVersion(package_version) < LooseVersion("5.4.1"):
|
||||||
|
ips += instance.ips.ipv6.pools
|
||||||
|
else:
|
||||||
|
ips += instance.ips.ipv6.ranges
|
||||||
|
|
||||||
for ip_type in set(ip.type for ip in ips):
|
for ip_type in set(ip.type for ip in ips):
|
||||||
self.inventory.set_variable(
|
self.inventory.set_variable(
|
||||||
|
|
Loading…
Reference in a new issue