Commit 8a7bc268 authored by Alberts S's avatar Alberts S
Browse files

Add ability to Inventory to filter hosts

parent 5e082627
......@@ -11,8 +11,18 @@ class Inventory(CapybaraNetty):
self.chef_api = chef.autoconfigure()
self.chef_api.ssl_verify = False
self.inventory_match_hosts = self.config.get("inventory_match_hosts", None)
def is_matched_host(self, hostname: str):
if not self.inventory_match_hosts:
return False
for node_filter in self.inventory_match_hosts:
if hostname.startswith(node_filter):
return True
return False
async def get_hosts(self):
hosts = []
for node_name in self.chef_api["/nodes"]:
......@@ -21,6 +31,11 @@ class Inventory(CapybaraNetty):
nodeTime = datetime.utcfromtimestamp(chefNode.attributes["ohai_time"])
ipv4 = chefNode.attributes["base"]["public_ipv4"].strip()
hostname = chefNode.attributes["base"]["hostname"]
if not self.is_matched_host(hostname):
self.__logger.warning(f"host {hostname} is FILTERED out")
# If Node time is less than 1 hour old - its active
if (nodeTime + timedelta(hours=1)) > datetime.utcnow():
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment