forked from ceph/ceph-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ipaddr() with ips_in_ranges()
This change implements a filter_plugin that is used in the ceph-facts, ceph-validate roles and infrastucture-playbooks. The new filter plugin will return a list of all IP address that reside in any one of the given IP ranges. The new filter replaces the use of the ipaddr filter. ceph.conf already support a comma separated list of CIDRs for the public_network and cluster_network options. Changes: [1] and [2] introduced a regression in ceph-ansible where public_network can no longer be a comma separated list of cidrs. With this change a comma separated list of subnet CIDRs can also be used for monitor_address_block and radosgw_address_block. [1] commit: d67230b [2] commit: 20e4852 Related-To: https://bugs.launchpad.net/tripleo/+bug/1840030 Related-To: https://bugzilla.redhat.com/show_bug.cgi?id=1740283 Closes: ceph#4333 Please backport to stable-4.0 Signed-off-by: Harald Jensås <hjensas@redhat.com>
- Loading branch information
Showing
14 changed files
with
85 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from ansible import errors | ||
|
||
try: | ||
import netaddr | ||
except ImportError: | ||
# in this case, we'll make the filter return an error message (see bottom) | ||
netaddr = None | ||
|
||
|
||
class FilterModule(object): | ||
''' IP addresses within IP ranges ''' | ||
|
||
def ips_in_ranges(self, ip_addresses, ip_ranges): | ||
ips_in_ranges = list() | ||
for ip_addr in ip_addresses: | ||
for ip_range in ip_ranges: | ||
if netaddr.IPAddress(ip_addr) in netaddr.IPNetwork(ip_range): | ||
ips_in_ranges.append(ip_addr) | ||
return ips_in_ranges | ||
|
||
def filters(self): | ||
if netaddr: | ||
return { | ||
'ips_in_ranges': self.ips_in_ranges | ||
} | ||
else: | ||
# Need to install python's netaddr for these filters to work | ||
raise errors.AnsibleFilterError( | ||
"The ips_in_ranges filter requires python's netaddr be " | ||
"installed on the ansible controller.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from . import ipaddrs_in_ranges | ||
|
||
filter_plugin = ipaddrs_in_ranges.FilterModule() | ||
|
||
class TestIpaddrsInRanges(object): | ||
|
||
def test_one_ip_one_range(self): | ||
ips = ['10.10.10.1'] | ||
ranges = ['10.10.10.1/24'] | ||
result = filter_plugin.ips_in_ranges(ips, ranges) | ||
assert ips[0] in result | ||
assert len(result) == 1 | ||
|
||
def test_two_ip_one_range(self): | ||
ips = ['192.168.1.1', '10.10.10.1'] | ||
ranges = ['10.10.10.1/24'] | ||
result = filter_plugin.ips_in_ranges(ips, ranges) | ||
assert ips[0] not in result | ||
assert ips[1] in result | ||
assert len(result) == 1 | ||
|
||
def test_one_ip_two_ranges(self): | ||
ips = ['10.10.10.1'] | ||
ranges = ['192.168.1.0/24', '10.10.10.1/24'] | ||
result = filter_plugin.ips_in_ranges(ips, ranges) | ||
assert ips[0] in result | ||
assert len(result) == 1 | ||
|
||
def test_multiple_ips_multiple_ranges(self): | ||
ips = ['10.10.10.1', '192.168.1.1', '172.16.10.1'] | ||
ranges = ['192.168.1.0/24', '10.10.10.1/24', '172.16.17.0/24'] | ||
result = filter_plugin.ips_in_ranges(ips, ranges) | ||
assert ips[0] in result | ||
assert ips[1] in result | ||
assert ips[2] not in result | ||
assert len(result) == 2 | ||
|
||
def test_no_ips_in_ranges(self): | ||
ips = ['10.10.20.1', '192.168.2.1', '172.16.10.1'] | ||
ranges = ['192.168.1.0/24', '10.10.10.1/24', '172.16.17.0/24'] | ||
result = filter_plugin.ips_in_ranges(ips, ranges) | ||
assert result == [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters