code: def vm_state(vm_=None):
      '''
      Return list of all the vms and their state.
  
      If you pass a VM name in as an argument then it will return info
      for just the named VM, otherwise it will return all VMs.
  
      CLI Example:
  
      .. code-block:: bash
  
          salt '*' virt.vm_state <vm name>
      '''
      with _get_xapi_session() as xapi:
          info = {}
  
          if vm_:
              info[vm_] = _get_record_by_label(xapi, 'VM', vm_)['power_state']
              return info
  
          for vm_ in list_domains():
              info[vm_] = _get_record_by_label(xapi, 'VM', vm_)['power_state']
          return inff vm_state(vm_=None):
      '''
      Return list of all the vms and their state.
  
      If you pass a VM name in as an argument then it will return info
      for just the named VM, otherwise it will return all VMs.
  
      CLI Example:
  
      .. code-block:: bash
  
          salt '*' virt.vm_state <vm name>
      '''
      with _get_xapi_session() as xapi:
          info = {}
  
          if vm_:
              info[vm_] = _get_record_by_label(xapi, 'VM', vm_)['power_state']
              return info
  
          for vm_ in list_domains():
              info[vm_] = _get_record_by_label(xapi, 'VM', vm_)['power_state']
          return info
docs: Return list of all the vms and their state.
  
      If you pass a VM name in as an argument then it will return info
      for just the named VM, otherwise it will return all VMs.
  
      CLI Example:
  
      .. code-block:: bash
  
          salt '*' virt.vm_state <vm name>