File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/aggregation.cpython-310.pyc
Back
o ;j� � @ s� d Z ddlZddlZddlmZ g d�Ze�e�ZG dd� d�Z G dd� dee �Z G d d � d ee �Zdd� Z d d� Ze efdd�Zde efdd�ZdS )a/ salt.utils.aggregation ~~~~~~~~~~~~~~~~~~~~~~ This library makes it possible to introspect dataset and aggregate nodes when it is instructed. .. note:: The following examples with be expressed in YAML for convenience's sake: - !aggr-scalar will refer to Scalar python function - !aggr-map will refer to Map python object - !aggr-seq will refer for Sequence python object How to instructs merging ------------------------ This yaml document has duplicate keys: .. code-block:: yaml foo: !aggr-scalar first foo: !aggr-scalar second bar: !aggr-map {first: foo} bar: !aggr-map {second: bar} baz: !aggr-scalar 42 but tagged values instruct Salt that overlapping values they can be merged together: .. code-block:: yaml foo: !aggr-seq [first, second] bar: !aggr-map {first: foo, second: bar} baz: !aggr-seq [42] Default merge strategy is keep untouched ---------------------------------------- For example, this yaml document still has duplicate keys, but does not instruct aggregation: .. code-block:: yaml foo: first foo: second bar: {first: foo} bar: {second: bar} baz: 42 So the late found values prevail: .. code-block:: yaml foo: second bar: {second: bar} baz: 42 Limitations ----------- Aggregation is permitted between tagged objects that share the same type. If not, the default merge strategy prevails. For example, these examples: .. code-block:: yaml foo: {first: value} foo: !aggr-map {second: value} bar: !aggr-map {first: value} bar: 42 baz: !aggr-seq [42] baz: [fail] qux: 42 qux: !aggr-scalar fail are interpreted like this: .. code-block:: yaml foo: !aggr-map{second: value} bar: 42 baz: [fail] qux: !aggr-seq [fail] Introspection ------------- TODO: write this part � N)�OrderedDict)� aggregate� Aggregate�Map�Scalar�Sequencec @ � e Zd ZdZdS )r z Aggregation base. N��__name__� __module__�__qualname__�__doc__� r r �J/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/aggregation.pyr r � r c @ r )r z Map aggregation. Nr r r r r r x r r c @ r )r z Sequence aggregation. Nr r r r r r ~ r r c C s t | g�S )z] Shortcut for Sequence creation >>> Scalar('foo') == Sequence(['foo']) True )r )�objr r r r � s r c C sx | sdS | du r dS t | t�rd| d fS zt| d �| dd� }}t|�|fW S ty; } zt�|� � d}~ww )a� Describe which levels are allowed to do deep merging. level can be: True all levels are True False all levels are False an int only the first levels are True, the others are False a sequence it describes which levels are True, it can be: * a list of bool and int values * a string of 0 and 1 characters )FFT)TT� r N)� isinstance�int�bool� Exception�log�warning)�level�deepZsubs�errorr r r �levelise� s ��r c C sB t | t�r| S t | t�r|| �S t | tttf�r|| �S || g�S )z0 Convert obj into an Aggregate instance )r r �dict�list�tuple�set)r � map_class�sequence_classr r r �mark� s r# Fc C s$ t |�\}}|rt| ||d�} t|||d�}t| t�rRt|t�rRt| t�r0t|t�r0t�| �}nt�|�}|�� D ]\}} || v rKt| | | |||�} | ||<