def list_locations()

in libcloud/compute/drivers/vsphere.py [0:0]


    def list_locations(self, ex_show_hosts_in_drs=True):
        """
        Lists locations
        """
        content = self.connection.RetrieveContent()

        potential_locations = [
            dc
            for dc in content.viewManager.CreateContainerView(
                content.rootFolder,
                [vim.ClusterComputeResource, vim.HostSystem],
                recursive=True,
            ).view
        ]

        # Add hosts and clusters with DRS enabled
        locations = []
        hosts_all = []
        clusters = []

        for location in potential_locations:
            if isinstance(location, vim.HostSystem):
                hosts_all.append(location)
            elif isinstance(location, vim.ClusterComputeResource):
                if location.configuration.drsConfig.enabled:
                    clusters.append(location)

        if ex_show_hosts_in_drs:
            hosts = hosts_all
        else:
            hosts_filter = [host for cluster in clusters for host in cluster.host]
            hosts = [host for host in hosts_all if host not in hosts_filter]

        for cluster in clusters:
            locations.append(self._to_location(cluster))

        for host in hosts:
            locations.append(self._to_location(host))

        return locations