(mor, infrastructure_data, config, include_only=None)
return filtered_tags
Go up the resources hierarchy from the given mor. Note that a host running a VM is not considered to be a
    parent of that VM.

    rootFolder(vim.Folder):
      - vm(vim.Folder):
          VM1-1
          VM1-2
      - host(vim.Folder):
          HOST1
          HOST2
Go up the resources hierarchy from the given mor. Note that a host running a VM is not considered to be a
    parent of that VM.
Go up the resources hierarchy from the given mor . Note that a host running a VM is not considered to be a parent of that VM .
def get_tags_recursively(mor, infrastructure_data, config, include_only=None):
    # type: (vim.ManagedEntity, InfrastructureData, VSphereConfig, Optional[List[str]]) -> List[str]
    """Go up the resources hierarchy from the given mor. Note that a host running a VM is not considered to be a
    parent of that VM.

    rootFolder(vim.Folder):
      - vm(vim.Folder):
          VM1-1
          VM1-2
      - host(vim.Folder):
          HOST1
          HOST2

    """
    tags = []
    properties = infrastructure_data.get(mor, {})
    entity_name = to_string(properties.get('name', 'unknown'))
    if isinstance(mor, vim.HostSystem):
        tags.append('vsphere_host:{}'.format(entity_name))
    elif isinstance(mor, vim.Folder):
        if isinstance(mor, vim.StoragePod):
            tags.append('vsphere_datastore_cluster:{}'.format(entity_name))
            # Legacy mode: keep it as "folder"
            if config.include_datastore_cluster_folder_tag:
                tags.append('vsphere_folder:{}'.format(entity_name))
        else:
            tags.append('vsphere_folder:{}'.format(entity_name))
    elif isinstance(mor, vim.ComputeResource):
        if isinstance(mor, vim.ClusterComputeResource):
            tags.append('vsphere_cluster:{}'.format(entity_name))
        tags.append('vsphere_compute:{}'.format(entity_name))
    elif isinstance(mor, vim.Datacenter):
        tags.append('vsphere_datacenter:{}'.format(entity_name))
    elif isinstance(mor, vim.Datastore):
        tags.append('vsphere_datastore:{}'.format(entity_name))

    parent = infrastructure_data.get(mor, {}).get('parent')
    if parent is None:
        return tags
    tags.extend(get_tags_recursively(parent, infrastructure_data, config))
    if not include_only:
        return tags
    filtered_tags = []
    for tag in tags:
        for prefix in include_only:
            if not tag.startswith(prefix + ":"):
                continue
            filtered_tags.append(tag)
    return filtered_tags
def get_tags_recursively ( mor , infrastructure_data , config , include_only = None ) : # type: (vim.ManagedEntity, InfrastructureData, VSphereConfig, Optional[List[str]]) -> List[str] tags = [ ] properties = infrastructure_data . get ( mor , { } ) entity_name = to_string ( properties . get ( 'name' , 'unknown' ) ) if isinstance ( mor , vim . HostSystem ) : tags . append ( 'vsphere_host:{}' . format ( entity_name ) ) elif isinstance ( mor , vim . Folder ) : if isinstance ( mor , vim . StoragePod ) : tags . append ( 'vsphere_datastore_cluster:{}' . format ( entity_name ) ) # Legacy mode: keep it as "folder" if config . include_datastore_cluster_folder_tag : tags . append ( 'vsphere_folder:{}' . format ( entity_name ) ) else : tags . append ( 'vsphere_folder:{}' . format ( entity_name ) ) elif isinstance ( mor , vim . ComputeResource ) : if isinstance ( mor , vim . ClusterComputeResource ) : tags . append ( 'vsphere_cluster:{}' . format ( entity_name ) ) tags . append ( 'vsphere_compute:{}' . format ( entity_name ) ) elif isinstance ( mor , vim . Datacenter ) : tags . append ( 'vsphere_datacenter:{}' . format ( entity_name ) ) elif isinstance ( mor , vim . Datastore ) : tags . append ( 'vsphere_datastore:{}' . format ( entity_name ) ) parent = infrastructure_data . get ( mor , { } ) . get ( 'parent' ) if parent is None : return tags tags . extend ( get_tags_recursively ( parent , infrastructure_data , config ) ) if not include_only : return tags filtered_tags = [ ] for tag in tags : for prefix in include_only : if not tag . startswith ( prefix + ":" ) : continue filtered_tags . append ( tag ) return filtered_tags