(self)
return cast(InfrastructureData, infrastructure_data)
Traverse the whole vSphere infrastructure and outputs a dict mapping the mors to their properties.

        :return: {
            'vim.VirtualMachine-VM0': {
              'name': 'VM-0',
              ...
            }
            ...
        }
Traverse the whole vSphere infrastructure and outputs a dict mapping the mors to their properties.
Traverse the whole vSphere infrastructure and outputs a dict mapping the mors to their properties .
def get_infrastructure(self):
        # type: () -> InfrastructureData
        """Traverse the whole vSphere infrastructure and outputs a dict mapping the mors to their properties.

        :return: {
            'vim.VirtualMachine-VM0': {
              'name': 'VM-0',
              ...
            }
            ...
        }
        """

        obj_content_list = self._get_raw_infrastructure()
        # Build infrastructure data
        # Each `obj_content` contains the fields:
        #   - `obj`: `ManagedEntity` aka `mor`
        #   - `propSet`: properties related to the `mor`
        infrastructure_data = {
            obj_content.obj: {prop.name: prop.val for prop in obj_content.propSet}
            for obj_content in obj_content_list
            if obj_content.propSet
        }

        # Add the root folder entity as it can't be fetched from the previous api calls.
        root_folder = self._conn.content.rootFolder
        infrastructure_data[root_folder] = {"name": root_folder.name, "parent": None}

        if self.config.should_collect_attributes:
            # Clean up attributes in infrastructure_data,
            # at this point they are custom pyvmomi objects and the attribute keys are not resolved.

            attribute_keys = {x.key: x.name for x in self._fetch_all_attributes()}
            for props in itervalues(infrastructure_data):
                mor_attributes = []
                if 'customValue' not in props:
                    continue
                for attribute in props.pop('customValue'):
                    # The attribute key is always unique
                    attr_key_name = attribute_keys.get(attribute.key)
                    if attr_key_name is None:
                        self.log.debug("Unable to resolve attribute key with ID: %s", attribute.key)
                        continue
                    attr_value = attribute.value
                    mor_attributes.append("{}{}:{}".format(self.config.attr_prefix, attr_key_name, attr_value))

                props['attributes'] = mor_attributes
        return cast(InfrastructureData, infrastructure_data)
def get_infrastructure ( self ) : # type: () -> InfrastructureData obj_content_list = self . _get_raw_infrastructure ( ) # Build infrastructure data # Each `obj_content` contains the fields: #   - `obj`: `ManagedEntity` aka `mor` #   - `propSet`: properties related to the `mor` infrastructure_data = { obj_content . obj : { prop . name : prop . val for prop in obj_content . propSet } for obj_content in obj_content_list if obj_content . propSet } # Add the root folder entity as it can't be fetched from the previous api calls. root_folder = self . _conn . content . rootFolder infrastructure_data [ root_folder ] = { "name" : root_folder . name , "parent" : None } if self . config . should_collect_attributes : # Clean up attributes in infrastructure_data, # at this point they are custom pyvmomi objects and the attribute keys are not resolved. attribute_keys = { x . key : x . name for x in self . _fetch_all_attributes ( ) } for props in itervalues ( infrastructure_data ) : mor_attributes = [ ] if 'customValue' not in props : continue for attribute in props . pop ( 'customValue' ) : # The attribute key is always unique attr_key_name = attribute_keys . get ( attribute . key ) if attr_key_name is None : self . log . debug ( "Unable to resolve attribute key with ID: %s" , attribute . key ) continue attr_value = attribute . value mor_attributes . append ( "{}{}:{}" . format ( self . config . attr_prefix , attr_key_name , attr_value ) ) props [ 'attributes' ] = mor_attributes return cast ( InfrastructureData , infrastructure_data )