@@ -0,0 +1,2091 @@
+'''%0ARead in the roster from a flat file using the renderer system%0A'''%0A%0A# Import python libs%0Aimport os%0Aimport fnmatch%0Aimport re%0A%0A# Import Salt libs%0Aimport salt.loader%0Afrom salt.template import compile_template%0A%0Adef targets(tgt, tgt_type='glob', **kwargs):%0A    '''%0A    Return the targets from the flat yaml file, checks opts for location but%0A    defaults to /etc/salt/roster%0A    '''%0A    template = os.path.join(__opts__%5B'conf_file'%5D, 'roster')%0A    rend = salt.loader.render(__opts__, %7B%7D)%0A    raw = compile_template(template, rend, __opts__%5B'renderer'%5D, **kwargs)%0A    rmatcher = RosterMatcher(raw, tgt, tgt_type, 'ipv4')%0A    return rmatcher.targets()%0A%0A%0Aclass RosterMatcher(object):%0A    '''%0A    Matcher for the roster data structure%0A    '''%0A    def __init__(self, raw, tgt, tgt_type, ipv='ipv4'):%0A        self.tgt = tgt%0A        self.tgt_type = tgt_type%0A        self.raw = raw%0A        self.ipv = ipv%0A%0A    def targets(self):%0A        '''%0A        Execute the correct tgt_type routine and return%0A        '''%0A        try:%0A            return getattr(self, 'ret_%7B0%7D_minions'.format(self.tgt_type))()%0A        except AttributeError:%0A            return %7B%7D%0A%0A    def ret_glob_minions(self):%0A        '''%0A        Return minions that match via glob%0A        '''%0A        minions = %7B%7D%0A        for minion in self.raw:%0A            if fnmatch.fnmatch(minion, self.tgt):%0A                ip = self.get_ip(minion)%0A                if ip:%0A                    minions%5Bminion%5D = ip%0A%0A    def ret_pcre_minions(self):%0A        '''%0A        Return minions that match via pcre%0A        '''%0A        minions = %7B%7D%0A        for minion in self.raw:%0A            if re.match(self.tgt, minion):%0A                ip = self.get_ip(minion)%0A                if ip:%0A                    minions%5Bminion%5D = ip%0A%0A    def get_ip(self, minion):%0A        '''%0A        Return the configured ip%0A        '''%0A        if isinstance(self.raw%5Bminion%5D, basestring):%0A            return self.raw%5Bminion%5D%0A        if isinstance(self.raw%5Bminion%5D, dict):%0A            if self.ipv in self.raw%5Bminion%5D:%0A                return self.raw%5Bminion%5D%5Bself.ipv%5D%0A        return False%0A%0A

Add flat roster management