1""" 2Display values only, separated by newlines 3========================================== 4 5.. versionadded:: 2015.5.0 6 7This outputter is designed for Salt CLI return data. It will do the following 8to the return dict: 9 101. Get just the values (ignoring the minion IDs). 112. Each value, if it is iterable, is split a separate line. 123. Each minion's values are separated by newlines. 13 14This results in a single string of return data containing all the values from 15the various minions. 16 17.. warning:: 18 19 As noted above, this outputter will discard the minion ID. If the minion ID 20 is important, then an outputter that returns the full return dictionary in 21 a parsable format (such as :mod:`json <salt.output.json>`, :mod:`pprint, 22 <salt.output.pprint>`, or :mod:`yaml <salt.output.yaml>`) may be more 23 suitable. 24 25 26Example 1 27~~~~~~~~~ 28 29.. code-block:: bash 30 31 salt '*' foo.bar --out=newline_values_only 32 33Input 34----- 35 36.. code-block:: python 37 38 { 39 'myminion': ['127.0.0.1', '10.0.0.1'], 40 'second-minion': ['127.0.0.1', '10.0.0.2'] 41 } 42 43Output 44------ 45 46.. code-block:: text 47 48 127.0.0.1 49 10.0.0.1 50 127.0.0.1 51 10.0.0.2 52 53Example 2 54~~~~~~~~~ 55 56.. code-block:: bash 57 58 salt '*' foo.bar --out=newline_values_only 59 60Input 61----- 62 63.. code-block:: python 64 65 { 66 'myminion': 8, 67 'second-minion': 10 68 } 69 70Output 71------ 72 73.. code-block:: python 74 75 8 76 10 77""" 78 79 80def _get_values(data): 81 # This should be able to be improved 82 # by parsing kargs from command line 83 # instantiation. 84 # But I am not sure how to do it 85 # just yet. 86 # This would enable us to toggle 87 # this functionality. 88 values = [] 89 for _, minion_values in data.items(): 90 if isinstance(minion_values, list): 91 values.extend(minion_values) 92 else: 93 values.append(minion_values) 94 return values 95 96 97def _one_level_values(data): 98 return "\n".join(_string_list(_get_values(data))) 99 100 101def _string_list(a_list): 102 return [str(item) for item in a_list] 103 104 105def output(data, **kwargs): # pylint: disable=unused-argument 106 """ 107 Display modified ret data 108 """ 109 return _one_level_values(data) 110