From 1b5eb30a1869af63ab0117d6d22f9d5842470b4b Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Sun, 13 Apr 2014 22:25:33 -0500 Subject: [PATCH] Simplify how ID is obtained No need to force the user to submit the ID, just grab it from grains. Still allows for minion ID to be passed on the CLI. --- salt/modules/match.py | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/salt/modules/match.py b/salt/modules/match.py index 82802a406b..8b86a65819 100644 --- a/salt/modules/match.py +++ b/salt/modules/match.py @@ -1,24 +1,9 @@ # -*- coding: utf-8 -*- ''' The match module allows for match routines to be run and determine target specs - -.. warning:: - - Since :doc:`Pillar ` data is compiled on the master, - some of these functions require the minion ID to be overridden to - succesfully match them in Pillar SLS files. These functions are: - - * :mod:`match.compound ` - * :mod:`match.glob ` - * :mod:`match.list ` - * :mod:`match.pcre ` - - This ability is new in the upcoming Helium release, and currently only - available in the development branch of Salt. ''' # Import python libs -import copy import logging # Import salt libs @@ -47,12 +32,14 @@ def compound(tgt, minion_id=None): salt '*' match.compound 'L@cheese,foo and *' ''' - opts = copy.deepcopy(__opts__) + opts = {} opts['grains'] = __grains__ if minion_id is not None: if not isinstance(minion_id, string_types): minion_id = str(minion_id) - opts['id'] = minion_id + else: + minion_id = __grains__['id'] + opts['id'] = minion_id matcher = salt.minion.Matcher(opts, __salt__) try: return matcher.compound_match(tgt) @@ -181,12 +168,12 @@ def list_(tgt, minion_id=None): salt '*' match.list 'server1,server2' ''' - opts = copy.deepcopy(__opts__) if minion_id is not None: if not isinstance(minion_id, string_types): minion_id = str(minion_id) - opts['id'] = minion_id - matcher = salt.minion.Matcher(opts, __salt__) + else: + minion_id = __grains__['id'] + matcher = salt.minion.Matcher({'id': minion_id}, __salt__) try: return matcher.list_match(tgt) except Exception as exc: @@ -209,12 +196,12 @@ def pcre(tgt, minion_id=None): salt '*' match.pcre '.*' ''' - opts = copy.deepcopy(__opts__) if minion_id is not None: if not isinstance(minion_id, string_types): minion_id = str(minion_id) - opts['id'] = minion_id - matcher = salt.minion.Matcher(opts, __salt__) + else: + minion_id = __grains__['id'] + matcher = salt.minion.Matcher({'id': minion_id}, __salt__) try: return matcher.pcre_match(tgt) except Exception as exc: @@ -237,12 +224,12 @@ def glob(tgt, minion_id=None): salt '*' match.glob '*' ''' - opts = copy.deepcopy(__opts__) if minion_id is not None: if not isinstance(minion_id, string_types): minion_id = str(minion_id) - opts['id'] = minion_id - matcher = salt.minion.Matcher(opts, __salt__) + else: + minion_id = __grains__['id'] + matcher = salt.minion.Matcher({'id': minion_id}, __salt__) try: return matcher.glob_match(tgt) except Exception as exc: