def output(data, **kwargs): # pylint: disable=unused-argument ''' The HighState Outputter is only meant to be used with the state.highstate function, or a function that returns highstate return data. ''' # Discard retcode in dictionary as present in orchestrate data local_masters = [ key for key in data.keys() if key.endswith('.local_master') ] orchestrator_output = 'retcode' in data.keys() and len(local_masters) == 1 if orchestrator_output: del data['retcode'] # If additional information is passed through via the "data" dictionary to # the highstate outputter, such as "outputter" or "retcode", discard it. # We only want the state data that was passed through, if it is wrapped up # in the "data" key, as the orchestrate runner does. See Issue #31330, # pull request #27838, and pull request #27175 for more information. if 'data' in data: data = data.pop('data') indent_level = kwargs.get('indent_level', 1) ret = [ _format_host(host, hostdata, indent_level=indent_level)[0] for host, hostdata in six.iteritems(data) ] if ret: return "\n".join(ret) log.error( 'Data passed to highstate outputter is not a valid highstate return: %s', data) # We should not reach here, but if we do return empty string return ''
def output(data, **kwargs): # pylint: disable=unused-argument """ The HighState Outputter is only meant to be used with the state.highstate function, or a function that returns highstate return data. """ # If additional information is passed through via the "data" dictionary to # the highstate outputter, such as "outputter" or "retcode", discard it. # We only want the state data that was passed through, if it is wrapped up # in the "data" key, as the orchestrate runner does. See Issue #31330, # pull request #27838, and pull request #27175 for more information. # account for envelope data if being passed lookup_jid ret if isinstance(data, dict) and "return" in data: data = data["return"] if isinstance(data, dict) and "data" in data: data = data["data"] # account for envelope data if being passed lookup_jid ret if isinstance(data, dict) and len(data.keys()) == 1: _data = next(iter(data.values())) if isinstance(_data, dict): if "jid" in _data and "fun" in _data: data = _data.get("return", {}).get("data", data) # output() is recursive, if we aren't passed a dict just return it if isinstance(data, int) or isinstance(data, str): return data if data is None: return "None" # Discard retcode in dictionary as present in orchestrate data local_masters = [key for key in data.keys() if key.endswith("_master")] orchestrator_output = "retcode" in data.keys() and len(local_masters) == 1 if orchestrator_output: del data["retcode"] # pre-process data if state_compress_ids is set if __opts__.get("state_compress_ids", False): data = _compress_ids(data) indent_level = kwargs.get("indent_level", 1) ret = [ _format_host(host, hostdata, indent_level=indent_level)[0] for host, hostdata in data.items() ] if ret: return "\n".join(ret) log.error( "Data passed to highstate outputter is not a valid highstate return: %s", data) # We should not reach here, but if we do return empty string return ""
def output(data, **kwargs): # pylint: disable=unused-argument ''' The HighState Outputter is only meant to be used with the state.highstate function, or a function that returns highstate return data. ''' if len(data.keys()) == 1: # account for nested orchs via saltutil.runner if 'return' in data: data = data['return'] # account for envelope data if being passed lookup_jid ret if isinstance(data, dict): _data = next(iter(data.values())) if 'jid' in _data and 'fun' in _data: data = _data['return'] # output() is recursive, if we aren't passed a dict just return it if isinstance(data, int) or isinstance(data, six.string_types): return data # Discard retcode in dictionary as present in orchestrate data local_masters = [key for key in data.keys() if key.endswith('_master')] orchestrator_output = 'retcode' in data.keys() and len(local_masters) == 1 if orchestrator_output: del data['retcode'] # If additional information is passed through via the "data" dictionary to # the highstate outputter, such as "outputter" or "retcode", discard it. # We only want the state data that was passed through, if it is wrapped up # in the "data" key, as the orchestrate runner does. See Issue #31330, # pull request #27838, and pull request #27175 for more information. if 'data' in data: data = data.pop('data') indent_level = kwargs.get('indent_level', 1) ret = [ _format_host(host, hostdata, indent_level=indent_level)[0] for host, hostdata in six.iteritems(data) ] if ret: return "\n".join(ret) log.error( 'Data passed to highstate outputter is not a valid highstate return: %s', data) # We should not reach here, but if we do return empty string return ''