(self, server_instance, regexes, include_only_marked, tags, use_guest_hostname=False)
return obj_list
Explore vCenter infrastructure to discover hosts, virtual machines, etc.
        and compute their associated tags.
        Start at the vCenter `rootFolder`, so as to collect every object.

        Example topology:
            ```
            rootFolder
                - datacenter1
                    - compute_resource1 == cluster
                        - host1
                        - host2
                        - host3
                    - compute_resource2
                        - host5
                            - vm1
                            - vm2
            ```

        If it's a node we want to query metric for, it will be enqueued at the
        instance level and will be processed by a subsequent job.
Explore vCenter infrastructure to discover hosts, virtual machines, etc.
        and compute their associated tags.
        Start at the vCenter `rootFolder`, so as to collect every object.
Explore vCenter infrastructure to discover hosts virtual machines etc . and compute their associated tags . Start at the vCenter rootFolder so as to collect every object .
def _get_all_objs(self, server_instance, regexes, include_only_marked, tags, use_guest_hostname=False):
        """
        Explore vCenter infrastructure to discover hosts, virtual machines, etc.
        and compute their associated tags.
        Start at the vCenter `rootFolder`, so as to collect every object.

        Example topology:
            ```
            rootFolder
                - datacenter1
                    - compute_resource1 == cluster
                        - host1
                        - host2
                        - host3
                    - compute_resource2
                        - host5
                            - vm1
                            - vm2
            ```

        If it's a node we want to query metric for, it will be enqueued at the
        instance level and will be processed by a subsequent job.
        """
        start = time.time()
        obj_list = defaultdict(list)

        # Collect objects and their attributes
        all_objects = self._collect_mors_and_attributes(server_instance)

        # Add rootFolder since it is not explored by the propertyCollector
        rootFolder = server_instance.content.rootFolder
        all_objects[rootFolder] = {"name": rootFolder.name, "parent": None}

        for obj, properties in all_objects.items():
            instance_tags = []
            if not self._is_excluded(obj, properties, regexes, include_only_marked) and isinstance(
                obj, RESOURCE_TYPE_METRICS
            ):
                if use_guest_hostname:
                    hostname = properties.get("guest.hostName", properties.get("name", "unknown"))
                else:
                    hostname = properties.get("name", "unknown")
                if properties.get("parent"):
                    instance_tags.extend(self._get_parent_tags(obj, all_objects))

                if isinstance(obj, vim.VirtualMachine):
                    vsphere_type = 'vsphere_type:vm'
                    vimtype = vim.VirtualMachine
                    mor_type = "vm"
                    power_state = properties.get("runtime.powerState")
                    if power_state != vim.VirtualMachinePowerState.poweredOn:
                        self.log.debug("Skipping VM in state %s", ensure_unicode(power_state))
                        continue
                    host_mor = properties.get("runtime.host")
                    host_props = all_objects.get(host_mor, {})
                    host = "unknown"
                    if host_mor and host_props:
                        host = ensure_unicode(host_props.get("name", "unknown"))
                        if self._is_excluded(host_mor, host_props, regexes, include_only_marked):
                            self.log.debug(
                                "Skipping VM because host %s is excluded by rule %s.", host, regexes.get('host_include')
                            )
                            continue
                    instance_tags.append('vsphere_host:{}'.format(host))
                elif isinstance(obj, vim.HostSystem):
                    vsphere_type = 'vsphere_type:host'
                    vimtype = vim.HostSystem
                    mor_type = "host"
                elif isinstance(obj, vim.Datastore):
                    vsphere_type = 'vsphere_type:datastore'
                    instance_tags.append(
                        'vsphere_datastore:{}'.format(ensure_unicode(properties.get("name", "unknown")))
                    )
                    hostname = None
                    vimtype = vim.Datastore
                    mor_type = "datastore"
                elif isinstance(obj, vim.Datacenter):
                    vsphere_type = 'vsphere_type:datacenter'
                    instance_tags.append(
                        "vsphere_datacenter:{}".format(ensure_unicode(properties.get("name", "unknown")))
                    )
                    hostname = None
                    vimtype = vim.Datacenter
                    mor_type = "datacenter"
                elif isinstance(obj, vim.ClusterComputeResource):
                    vsphere_type = 'vsphere_type:cluster'
                    instance_tags.append("vsphere_cluster:{}".format(ensure_unicode(properties.get("name", "unknown"))))
                    hostname = None
                    vimtype = vim.ClusterComputeResource
                    mor_type = "cluster"
                else:
                    vsphere_type = None

                if vsphere_type:
                    instance_tags.append(vsphere_type)

                mor = {
                    "mor_type": mor_type,
                    "mor": obj,
                    "hostname": hostname,
                    "tags": [t for t in tags + instance_tags if t.split(":", 1)[0] not in self.excluded_host_tags],
                }
                if self.excluded_host_tags:
                    mor["excluded_host_tags"] = [
                        t for t in tags + instance_tags if t.split(":", 1)[0] in self.excluded_host_tags
                    ]
                obj_list[vimtype].append(mor)

        self.log.debug("All objects with attributes cached in %s seconds.", time.time() - start)
        return obj_list
def _get_all_objs ( self , server_instance , regexes , include_only_marked , tags , use_guest_hostname = False ) : start = time . time ( ) obj_list = defaultdict ( list ) # Collect objects and their attributes all_objects = self . _collect_mors_and_attributes ( server_instance ) # Add rootFolder since it is not explored by the propertyCollector rootFolder = server_instance . content . rootFolder all_objects [ rootFolder ] = { "name" : rootFolder . name , "parent" : None } for obj , properties in all_objects . items ( ) : instance_tags = [ ] if not self . _is_excluded ( obj , properties , regexes , include_only_marked ) and isinstance ( obj , RESOURCE_TYPE_METRICS ) : if use_guest_hostname : hostname = properties . get ( "guest.hostName" , properties . get ( "name" , "unknown" ) ) else : hostname = properties . get ( "name" , "unknown" ) if properties . get ( "parent" ) : instance_tags . extend ( self . _get_parent_tags ( obj , all_objects ) ) if isinstance ( obj , vim . VirtualMachine ) : vsphere_type = 'vsphere_type:vm' vimtype = vim . VirtualMachine mor_type = "vm" power_state = properties . get ( "runtime.powerState" ) if power_state != vim . VirtualMachinePowerState . poweredOn : self . log . debug ( "Skipping VM in state %s" , ensure_unicode ( power_state ) ) continue host_mor = properties . get ( "runtime.host" ) host_props = all_objects . get ( host_mor , { } ) host = "unknown" if host_mor and host_props : host = ensure_unicode ( host_props . get ( "name" , "unknown" ) ) if self . _is_excluded ( host_mor , host_props , regexes , include_only_marked ) : self . log . debug ( "Skipping VM because host %s is excluded by rule %s." , host , regexes . get ( 'host_include' ) ) continue instance_tags . append ( 'vsphere_host:{}' . format ( host ) ) elif isinstance ( obj , vim . HostSystem ) : vsphere_type = 'vsphere_type:host' vimtype = vim . HostSystem mor_type = "host" elif isinstance ( obj , vim . Datastore ) : vsphere_type = 'vsphere_type:datastore' instance_tags . append ( 'vsphere_datastore:{}' . format ( ensure_unicode ( properties . get ( "name" , "unknown" ) ) ) ) hostname = None vimtype = vim . Datastore mor_type = "datastore" elif isinstance ( obj , vim . Datacenter ) : vsphere_type = 'vsphere_type:datacenter' instance_tags . append ( "vsphere_datacenter:{}" . format ( ensure_unicode ( properties . get ( "name" , "unknown" ) ) ) ) hostname = None vimtype = vim . Datacenter mor_type = "datacenter" elif isinstance ( obj , vim . ClusterComputeResource ) : vsphere_type = 'vsphere_type:cluster' instance_tags . append ( "vsphere_cluster:{}" . format ( ensure_unicode ( properties . get ( "name" , "unknown" ) ) ) ) hostname = None vimtype = vim . ClusterComputeResource mor_type = "cluster" else : vsphere_type = None if vsphere_type : instance_tags . append ( vsphere_type ) mor = { "mor_type" : mor_type , "mor" : obj , "hostname" : hostname , "tags" : [ t for t in tags + instance_tags if t . split ( ":" , 1 ) [ 0 ] not in self . excluded_host_tags ] , } if self . excluded_host_tags : mor [ "excluded_host_tags" ] = [ t for t in tags + instance_tags if t . split ( ":" , 1 ) [ 0 ] in self . excluded_host_tags ] obj_list [ vimtype ] . append ( mor ) self . log . debug ( "All objects with attributes cached in %s seconds." , time . time ( ) - start ) return obj_list