Skip to content

Commit

Permalink
bump to 0.16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulyalin committed Oct 20, 2022
1 parent 02dee4b commit 25dde04
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 165 deletions.
19 changes: 19 additions & 0 deletions nornir_salt/plugins/functions/InventoryFun.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
.. autofunction:: nornir_salt.plugins.functions.InventoryFun._delete_host
.. autofunction:: nornir_salt.plugins.functions.InventoryFun._load
.. autofunction:: nornir_salt.plugins.functions.InventoryFun._list_hosts
.. autofunction:: nornir_salt.plugins.functions.InventoryFun._list_hosts_platforms
"""
import logging

Expand Down Expand Up @@ -321,6 +322,22 @@ def _list_hosts(nr, **kwargs):
return list(hosts.inventory.hosts.keys())


def _list_hosts_platforms(nr, **kwargs):
"""
Function to return a dictionary keyed by host names containing platforms details.
Supports filtering using FFun function.
:param nr: (obj) Nornir object
:param kwargs: (dict) FFun function arguments to filter hosts
:return: (list) list of host names
"""
hosts = FFun(nr, kwargs=kwargs)
return {
host_name: host.platform for host_name, host in hosts.inventory.hosts.items()
}


fun_dispatcher = {
"create_host": _create_host,
"update_host": _update_host,
Expand All @@ -333,6 +350,7 @@ def _list_hosts(nr, **kwargs):
"read_inventory": _read_inventory,
"load": _load,
"list_hosts": _list_hosts,
"list_hosts_platforms": _list_hosts_platforms,
}


Expand All @@ -354,5 +372,6 @@ def InventoryFun(nr, call, **kwargs):
- ``load`` - calls ``_load``, to simplify calling multiple functions
- ``read_inventory`` - calls ``_read_inventory``, read inventory content for groups, default and hosts
- ``list_hosts`` - calls ``_list_hosts``, return a list of inventory's host names
- ``list_hosts_platforms`` - calls ``_list_hosts_platforms``, return a dictionary of hosts' platforms
"""
return fun_dispatcher[call](nr, **kwargs)

0 comments on commit 25dde04

Please sign in to comment.