HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/tops/__pycache__/mongo.cpython-310.pyc
o

�N�g��@sjdZddlZddlZzddlZdZWneydZYnwdddddd�Zd	d
�Ze�e	�Z
dd�ZdS)
a
Read tops data from a mongodb collection

This module will load tops data from a mongo collection. It uses the node's id
for lookups.

Salt Master Mongo Configuration
===============================

The module shares the same base mongo connection variables as
:py:mod:`salt.returners.mongo_return`. These variables go in your master
config file.

   * ``mongo.db`` - The mongo database to connect to. Defaults to ``'salt'``.
   * ``mongo.host`` - The mongo host to connect to. Supports replica sets by
     specifying all hosts in the set, comma-delimited. Defaults to ``'salt'``.
   * ``mongo.port`` - The port that the mongo database is running on. Defaults
     to ``27017``.
   * ``mongo.user`` - The username for connecting to mongo. Only required if
     you are using mongo authentication. Defaults to ``''``.
   * ``mongo.password`` - The password for connecting to mongo. Only required
     if you are using mongo authentication. Defaults to ``''``.


Configuring the Mongo Tops Subsystem
====================================

.. code-block:: yaml

  master_tops:
    mongo:
      collection: tops
      id_field: _id
      re_replace: ""
      re_pattern: \.example\.com
      states_field: states
      environment_field: environment


Module Documentation
====================
�NTF�salt�i�i)�mongo.db�
mongo.host�mongo.password�
mongo.port�
mongo.usercCstsdSdS)NF�mongo)�HAS_PYMONGO�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/tops/mongo.py�__virtual__@sr
cKs�td}td}tdd�dd�}tdd�dd�}tdd�d	d
�}tdd�dd
�}tdd�dd
�}tdd�dd�}t�d||�t�||�}	t�dtd�|	td}
t�d�}t�d�}|ry|ryt�d|�|
�||�|dd}
|r�t�	|||
�}
t�d||
�|
|j
||
i||gd�}|r�||vr�||vr�||}nd}t�d�|||iSt�d|�iS)a{
    Connect to a mongo database and read per-node tops data.

    Parameters:
        * `collection`: The mongodb collection to read data from. Defaults to
          ``'tops'``.
        * `id_field`: The field in the collection that represents an individual
          minion id. Defaults to ``'_id'``.
        * `re_pattern`: If your naming convention in the collection is shorter
          than the minion id, you can use this to trim the name.
          `re_pattern` will be used to match the name, and `re_replace` will
          be used to replace it. Backrefs are supported as they are in the
          Python standard library. If ``None``, no mangling of the name will
          be performed - the collection will be searched with the entire
          minion id. Defaults to ``None``.
        * `re_replace`: Use as the replacement value in node ids matched with
          `re_pattern`. Defaults to ''. Feel free to use backreferences here.
        * `states_field`: The name of the field providing a list of states.
        * `environment_field`: The name of the field providing the environment.
          Defaults to ``environment``.
    rrZmaster_topsr	�
collectionZtops�id_fieldZ_id�
re_patternr�
re_replace�states_fieldZstates�environment_field�environmentz&connecting to %s:%s for mongo ext_topszusing database '%s'rrrzauthenticating as '%s'�opts�idz=ext_tops.mongo: looking up tops def for {'%s': '%s'} in mongo)Z
projection�basez0ext_tops.mongo: found document, returning statesz2ext_tops.mongo: no document found in collection %s)�__opts__�get�log�info�pymongoZMongoClient�debugZauthenticate�re�subZfind_one)�kwargs�host�portrrrrrr�connZmdb�user�passwordZ	minion_id�resultrrrr�topJsL�

��

r')�__doc__�loggingrrr
�ImportErrorrr
�	getLogger�__name__rr'rrrr�<module>s$+��