new_contents: """
  Property Collector helper module.
  """
  # taken from:
  # https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/tools/pchelper.py
  import pyVmomi
  
  
  # Shamelessly borrowed from:
  # https://github.com/dnaeon/py-vconnector/blob/master/src/vconnector/core.py
  def collect_properties(service_instance, view_ref, obj_type, path_set=None,
                         include_mors=False):
      """
      Collect properties for managed objects from a view ref
  
      Check the vSphere API documentation for example on retrieving
      object properties:
  
          - http://goo.gl/erbFDz
  
      Args:
          si          (ServiceInstance): ServiceInstance connection
          view_ref (pyVmomi.vim.view.*): Starting point of inventory navigation
          obj_type      (pyVmomi.vim.*): Type of managed object
          path_set               (list): List of properties to retrieve
          include_mors           (bool): If True include the managed objects
                                         refs in the result
  
      Returns:
          A list of properties for the managed objects
  
      """
      collector = service_instance.content.propertyCollector
  
      # Create object specification to define the starting point of
      # inventory navigation
      obj_spec = pyVmomi.vmodl.query.PropertyCollector.ObjectSpec()
      obj_spec.obj = view_ref
      obj_spec.skip = True
  
      # Create a traversal specification to identify the path for collection
      traversal_spec = pyVmomi.vmodl.query.PropertyCollector.TraversalSpec()
      traversal_spec.name = 'traverseEntities'
      traversal_spec.path = 'view'
      traversal_spec.skip = False
      traversal_spec.type = view_ref.__class__
      obj_spec.selectSet = [traversal_spec]
  
      # Identify the properties to the retrieved
      property_spec = pyVmomi.vmodl.query.PropertyCollector.PropertySpec()
      property_spec.type = obj_type
  
      if not path_set:
          property_spec.all = True
  
      property_spec.pathSet = path_set
  
      # Add the object and property specification to the
      # property filter specification
      filter_spec = pyVmomi.vmodl.query.PropertyCollector.FilterSpec()
      filter_spec.objectSet = [obj_spec]
      filter_spec.propSet = [property_spec]
  
      # Retrieve properties
      props = collector.RetrieveContents([filter_spec])
  
      data = []
      for obj in props:
          properties = {}
          for prop in obj.propSet:
              properties[prop.name] = prop.val
  
          if include_mors:
              properties['obj'] = obj.obj
  
          data.append(properties)
      return data
  
  
  def get_container_view(service_instance, obj_type, container=None):
      """
      Get a vSphere Container View reference to all objects of type 'obj_type'
  
      It is up to the caller to take care of destroying the View when no longer
      needed.
  
      Args:
          obj_type (list): A list of managed object types
  
      Returns:
          A container view ref to the discovered managed objects
  
      """
      if not container:
          container = service_instance.content.rootFolder
  
      view_ref = service_instance.content.viewManager.CreateContainerView(
          container=container,
          type=obj_type,
          recursive=True
      )
      return view_ref
  
subject: Add pchelper