def find_entity_view(self, view_type, begin_entity=None, filter={},
                         properties=None):
        """Find a ManagedEntity of the requested type.

        Traverses the MOB looking for an entity matching the filter.

        :param view_type: The type of ManagedEntity to find.
        :type view_type: str
        :param begin_entity: The MOR to start searching for the entity. \
        The default is to start the search at the root folder.
        :type begin_entity: ManagedObjectReference or None
        :param filter: Key/value pairs to filter the results. The key is \
        a valid parameter of the ManagedEntity type. The value is what \
        that parameter should match.
        :type filter: dict
        :returns: If an entity is found, a ManagedEntity matching the search.
        :rtype: ManagedEntity

        """
        if properties is None:
            properties = []

        kls = classmapper(view_type)
        # Start the search at the root folder if no begin_entity was given
        if not begin_entity:
            begin_entity = self.sc.rootFolder._mo_ref
            logger.debug("Using %s", self.sc.rootFolder._mo_ref)

        property_spec = self.create('PropertySpec')
        property_spec.type = view_type
        property_spec.all = False
        property_spec.pathSet = list(filter.keys())

        pfs = self.get_search_filter_spec(begin_entity, property_spec)

        # Retrieve properties from server and update entity
        #obj_contents = self.propertyCollector.RetrieveProperties(specSet=pfs)
        obj_contents = self.sc.propertyCollector.RetrieveProperties(specSet=pfs)

        # TODO: Implement filtering
        if not filter:
            logger.warning('No filter specified, returning first match.')
            # If no filter is specified we just return the first item
            # in the list of returned objects
            logger.debug("Creating class in find_entity_view (filter)")
            view = kls(obj_contents[0].obj._mo_ref, self)
            logger.debug("Completed creating class in find_entity_view (filter)")
            #view.update_view_data(properties)
            return view

        matched = False
        # Iterate through obj_contents retrieved
        for obj_content in obj_contents:
            # If there are is no propSet, skip this one
            if not obj_content.propSet:
                continue

            matches = 0
            # Iterate through each property in the set
            for prop in obj_content.propSet:
                for key in filter.keys():
                    # If the property name is in the defined filter
                    if prop.name == key:
                        # ...and it matches the value specified
                        # TODO: Regex this?
                        if prop.val == filter[prop.name]:
                            # We've found a match
                            matches += 1
                        else:
                            break
                    else:
                        continue
            if matches == len(filter):
                filtered_obj_content = obj_content
                matched = True
                break
            else:
                continue

        if matched is not True:
            # There were no matches
            raise ObjectNotFoundError("No matching objects for filter")

        logger.debug("Creating class in find_entity_view")
        view = kls(filtered_obj_content.obj._mo_ref, self)
        logger.debug("Completed creating class in find_entity_view")
        #view.update_view_data(properties=properties)
        return view
def find_entity_view ( self , view_type , begin_entity = None , filter = { } , properties = None ) : if properties is None : properties = [ ] kls = classmapper ( view_type ) if not begin_entity : begin_entity = self . sc . rootFolder . _mo_ref logger . debug ( "Using %s" , self . sc . rootFolder . _mo_ref ) property_spec = self . create ( 'PropertySpec' ) property_spec . type = view_type property_spec . all = False property_spec . pathSet = list ( filter . keys ( ) ) pfs = self . get_search_filter_spec ( begin_entity , property_spec ) obj_contents = self . sc . propertyCollector . RetrieveProperties ( specSet = pfs ) if not filter : logger . warning ( 'No filter specified, returning first match.' ) logger . debug ( "Creating class in find_entity_view (filter)" ) view = kls ( obj_contents [ 0 ] . obj . _mo_ref , self ) logger . debug ( "Completed creating class in find_entity_view (filter)" ) return view matched = False for obj_content in obj_contents : if not obj_content . propSet : continue matches = 0 for prop in obj_content . propSet : for key in filter . keys ( ) : if prop . name == key : if prop . val == filter [ prop . name ] : matches += 1 else : break else : continue if matches == len ( filter ) : filtered_obj_content = obj_content matched = True break else : continue if matched is not True : raise ObjectNotFoundError ( "No matching objects for filter" ) logger . debug ( "Creating class in find_entity_view" ) view = kls ( filtered_obj_content . obj . _mo_ref , self ) logger . debug ( "Completed creating class in find_entity_view" ) return view
Find a ManagedEntity of the requested type.

        Traverses the MOB looking for an entity matching the filter.

        :param view_type: The type of ManagedEntity to find.
        :type view_type: str
        :param begin_entity: The MOR to start searching for the entity. \
        The default is to start the search at the root folder.
        :type begin_entity: ManagedObjectReference or None
        :param filter: Key/value pairs to filter the results. The key is \
        a valid parameter of the ManagedEntity type. The value is what \
        that parameter should match.
        :type filter: dict
        :returns: If an entity is found, a ManagedEntity matching the search.
        :rtype: ManagedEntity