(self, groups=None, hosts=None)
return Inventory(hosts=new_hosts, groups=new_groups, loaded=True)
Given a list of fnmatch-style group patterns and fnmatch-style host patterns,
        return a subset of the inventory where all groups match the patterns in each.
        If either pattern is omitted, return everything.  Demo, see 'push_to'
        in the opsmop-demo repo: content/push_demo.py
Given a list of fnmatch-style group patterns and fnmatch-style host patterns,
        return a subset of the inventory where all groups match the patterns in each.
        If either pattern is omitted, return everything.  Demo, see 'push_to'
        in the opsmop-demo repo: content/push_demo.py
Given a list of fnmatch - style group patterns and fnmatch - style host patterns return a subset of the inventory where all groups match the patterns in each . If either pattern is omitted return everything . Demo see push_to in the opsmop - demo repo : content / push_demo . py
def filter(self, groups=None, hosts=None):
        """
        Given a list of fnmatch-style group patterns and fnmatch-style host patterns,
        return a subset of the inventory where all groups match the patterns in each.
        If either pattern is omitted, return everything.  Demo, see 'push_to'
        in the opsmop-demo repo: content/push_demo.py
        """

        if not self._loaded:
            self.load()
            self.loaded = True
 
        new_groups = dict()
        new_hosts = dict()

        group_names = self._groups.keys()
        host_names  = self._hosts.keys()

        matched_groups = set()
        matched_host = set()

        if groups is not None and type(groups) != list:
            groups = [ groups ]
        if hosts is not None and type(hosts) != list:
            hosts = [ hosts ]

        if groups:
            for group_filter in groups:
                results = fnmatch.filter(group_names, group_filter)
                for r in results:
                    new_groups[r] = self._groups[r]
        else:
            new_groups = self._groups

        grouped_hosts = []
        for g in new_groups:
            grouped_hosts.extend(self._groups[g].hosts())
        grouped_hosts = list(set(grouped_hosts))
        grouped_hostnames = [ h.name for h in grouped_hosts ]

        if hosts:
            for host_filter in hosts:
                results = fnmatch.filter(grouped_hostnames, host_filter)
                for r in results:
                    new_hosts[r] = self._hosts[r]
        else:
            new_hosts = grouped_hosts


        return Inventory(hosts=new_hosts, groups=new_groups, loaded=True)
def filter ( self , groups = None , hosts = None ) : if not self . _loaded : self . load ( ) self . loaded = True new_groups = dict ( ) new_hosts = dict ( ) group_names = self . _groups . keys ( ) host_names = self . _hosts . keys ( ) matched_groups = set ( ) matched_host = set ( ) if groups is not None and type ( groups ) != list : groups = [ groups ] if hosts is not None and type ( hosts ) != list : hosts = [ hosts ] if groups : for group_filter in groups : results = fnmatch . filter ( group_names , group_filter ) for r in results : new_groups [ r ] = self . _groups [ r ] else : new_groups = self . _groups grouped_hosts = [ ] for g in new_groups : grouped_hosts . extend ( self . _groups [ g ] . hosts ( ) ) grouped_hosts = list ( set ( grouped_hosts ) ) grouped_hostnames = [ h . name for h in grouped_hosts ] if hosts : for host_filter in hosts : results = fnmatch . filter ( grouped_hostnames , host_filter ) for r in results : new_hosts [ r ] = self . _hosts [ r ] else : new_hosts = grouped_hosts return Inventory ( hosts = new_hosts , groups = new_groups , loaded = True )