コード例 #1
0
 def merge_tops(self, tops):
     '''
     Cleanly merge the top files
     '''
     top = collections.defaultdict(OrderedDict)
     orders = collections.defaultdict(OrderedDict)
     for ctops in tops.values():
         for ctop in ctops:
             for saltenv, targets in ctop.items():
                 if saltenv == 'include':
                     continue
                 for tgt in targets:
                     matches = []
                     states = OrderedDict()
                     orders[saltenv][tgt] = 0
                     for comp in ctop[saltenv][tgt]:
                         if isinstance(comp, dict):
                             if 'match' in comp:
                                 matches.append(comp)
                             if 'order' in comp:
                                 order = comp['order']
                                 if not isinstance(order, int):
                                     try:
                                         order = int(order)
                                     except ValueError:
                                         order = 0
                                 orders[saltenv][tgt] = order
                         if isinstance(comp, string_types):
                             states[comp] = True
                     top[saltenv][tgt] = matches
                     top[saltenv][tgt].extend(list(states.keys()))
     return self.sort_top_targets(top, orders)
コード例 #2
0
ファイル: __init__.py プロジェクト: AccelerationNet/salt
 def merge_tops(self, tops):
     '''
     Cleanly merge the top files
     '''
     top = collections.defaultdict(dict)
     orders = collections.defaultdict(dict)
     for ctops in tops.values():
         for ctop in ctops:
             for saltenv, targets in ctop.items():
                 if saltenv == 'include':
                     continue
                 for tgt in targets:
                     matches = []
                     states = OrderedDict()
                     orders[saltenv][tgt] = 0
                     for comp in ctop[saltenv][tgt]:
                         if isinstance(comp, dict):
                             if 'match' in comp:
                                 matches.append(comp)
                             if 'order' in comp:
                                 order = comp['order']
                                 if not isinstance(order, int):
                                     try:
                                         order = int(order)
                                     except ValueError:
                                         order = 0
                                 orders[saltenv][tgt] = order
                         if isinstance(comp, string_types):
                             states[comp] = True
                     top[saltenv][tgt] = matches
                     top[saltenv][tgt].extend(list(states.keys()))
     return self.sort_top_targets(top, orders)
コード例 #3
0
def _prompt_choice(var_name, options):
    '''
    Prompt the user to choose between a list of options, index each one by adding an enumerator
    based on https://github.com/audreyr/cookiecutter/blob/master/cookiecutter/prompt.py#L51

    :param var_name: The question to ask the user
    :type  var_name: ``str``

    :param options: A list of options
    :type  options: ``list`` of ``tupple``

    :rtype: ``tuple``
    :returns: The selected user
    '''
    choice_map = OrderedDict((u'{0}'.format(i), value)
                             for i, value in enumerate(options, 1)
                             if value[0] != 'test')
    choices = choice_map.keys()
    default = u'1'

    choice_lines = [
        u'{0} - {1} - {2}'.format(c[0], c[1][0], c[1][1])
        for c in choice_map.items()
    ]
    prompt = u'\n'.join(
        (u'Select {0}:'.format(var_name), u'\n'.join(choice_lines),
         u'Choose from {0}'.format(u', '.join(choices))))

    user_choice = click.prompt(prompt,
                               type=click.Choice(choices),
                               default=default)
    return choice_map[user_choice]
コード例 #4
0
ファイル: extend.py プロジェクト: nicholasmhughes/salt
def _prompt_choice(var_name, options):
    """
    Prompt the user to choose between a list of options, index each one by adding an enumerator
    based on https://github.com/audreyr/cookiecutter/blob/master/cookiecutter/prompt.py#L51

    :param var_name: The question to ask the user
    :type  var_name: ``str``

    :param options: A list of options
    :type  options: ``list`` of ``tupple``

    :rtype: ``tuple``
    :returns: The selected user
    """
    choice_map = OrderedDict(
        ("{}".format(i), value)
        for i, value in enumerate(options, 1)
        if value[0] != "test"
    )
    choices = choice_map.keys()
    default = "1"

    choice_lines = [
        "{} - {} - {}".format(c[0], c[1][0], c[1][1]) for c in choice_map.items()
    ]
    prompt = "\n".join(
        (
            "Select {}:".format(var_name),
            "\n".join(choice_lines),
            "Choose from {}".format(", ".join(choices)),
        )
    )

    user_choice = click.prompt(prompt, type=click.Choice(choices), default=default)
    return choice_map[user_choice]
コード例 #5
0
ファイル: extend.py プロジェクト: bryson/salt
def _prompt_choice(var_name, options):
    '''
    Prompt the user to choose between a list of options, index each one by adding an enumerator
    based on https://github.com/audreyr/cookiecutter/blob/master/cookiecutter/prompt.py#L51

    :param var_name: The question to ask the user
    :type  var_name: ``str``

    :param options: A list of options
    :type  options: ``list`` of ``tupple``

    :rtype: ``tuple``
    :returns: The selected user
    '''
    choice_map = OrderedDict(
        (u'{0}'.format(i), value) for i, value in enumerate(options, 1) if value[0] != 'test'
    )
    choices = choice_map.keys()
    default = u'1'

    choice_lines = [u'{0} - {1} - {2}'.format(c[0], c[1][0], c[1][1]) for c in choice_map.items()]
    prompt = u'\n'.join((
        u'Select {0}:'.format(var_name),
        u'\n'.join(choice_lines),
        u'Choose from {0}'.format(u', '.join(choices))
    ))

    user_choice = click.prompt(
        prompt, type=click.Choice(choices), default=default
    )
    return choice_map[user_choice]
コード例 #6
0
 def merge_tops(self, tops):
     '''
     Cleanly merge the top files
     '''
     top = collections.defaultdict(OrderedDict)
     orders = collections.defaultdict(OrderedDict)
     for ctops in six.itervalues(tops):
         for ctop in ctops:
             for saltenv, targets in six.iteritems(ctop):
                 if saltenv == 'include':
                     continue
                 for tgt in targets:
                     matches = []
                     states = OrderedDict()
                     orders[saltenv][tgt] = 0
                     ignore_missing = False
                     # handle a pillar sls target written in shorthand form
                     if isinstance(ctop[saltenv][tgt], six.string_types):
                         ctop[saltenv][tgt] = [ctop[saltenv][tgt]]
                     for comp in ctop[saltenv][tgt]:
                         if isinstance(comp, dict):
                             if 'match' in comp:
                                 matches.append(comp)
                             if 'order' in comp:
                                 order = comp['order']
                                 if not isinstance(order, int):
                                     try:
                                         order = int(order)
                                     except ValueError:
                                         order = 0
                                 orders[saltenv][tgt] = order
                             if comp.get('ignore_missing', False):
                                 ignore_missing = True
                         if isinstance(comp, six.string_types):
                             states[comp] = True
                     if ignore_missing:
                         if saltenv not in self.ignored_pillars:
                             self.ignored_pillars[saltenv] = []
                         self.ignored_pillars[saltenv].extend(states.keys())
                     top[saltenv][tgt] = matches
                     top[saltenv][tgt].extend(states)
     return self.sort_top_targets(top, orders)
コード例 #7
0
ファイル: __init__.py プロジェクト: bryson/salt
 def merge_tops(self, tops):
     '''
     Cleanly merge the top files
     '''
     top = collections.defaultdict(OrderedDict)
     orders = collections.defaultdict(OrderedDict)
     for ctops in six.itervalues(tops):
         for ctop in ctops:
             for saltenv, targets in six.iteritems(ctop):
                 if saltenv == 'include':
                     continue
                 for tgt in targets:
                     matches = []
                     states = OrderedDict()
                     orders[saltenv][tgt] = 0
                     ignore_missing = False
                     for comp in ctop[saltenv][tgt]:
                         if isinstance(comp, dict):
                             if 'match' in comp:
                                 matches.append(comp)
                             if 'order' in comp:
                                 order = comp['order']
                                 if not isinstance(order, int):
                                     try:
                                         order = int(order)
                                     except ValueError:
                                         order = 0
                                 orders[saltenv][tgt] = order
                             if comp.get('ignore_missing', False):
                                 ignore_missing = True
                         if isinstance(comp, six.string_types):
                             states[comp] = True
                     if ignore_missing:
                         if saltenv not in self.ignored_pillars:
                             self.ignored_pillars[saltenv] = []
                         self.ignored_pillars[saltenv].extend(states.keys())
                     top[saltenv][tgt] = matches
                     top[saltenv][tgt].extend(states)
     return self.sort_top_targets(top, orders)
コード例 #8
0
ファイル: __init__.py プロジェクト: unix196/salt
 def merge_tops(self, tops):
     """
     Cleanly merge the top files
     """
     top = collections.defaultdict(OrderedDict)
     orders = collections.defaultdict(OrderedDict)
     for ctops in tops.values():
         for ctop in ctops:
             for saltenv, targets in ctop.items():
                 if saltenv == "include":
                     continue
                 for tgt in targets:
                     matches = []
                     states = OrderedDict()
                     orders[saltenv][tgt] = 0
                     ignore_missing = False
                     for comp in ctop[saltenv][tgt]:
                         if isinstance(comp, dict):
                             if "match" in comp:
                                 matches.append(comp)
                             if "order" in comp:
                                 order = comp["order"]
                                 if not isinstance(order, int):
                                     try:
                                         order = int(order)
                                     except ValueError:
                                         order = 0
                                 orders[saltenv][tgt] = order
                             if comp.get("ignore_missing", False):
                                 ignore_missing = True
                         if isinstance(comp, str):
                             states[comp] = True
                     if ignore_missing:
                         if saltenv not in self.ignored_pillars:
                             self.ignored_pillars[saltenv] = []
                         self.ignored_pillars[saltenv].extend(states.keys())
                     top[saltenv][tgt] = matches
                     top[saltenv][tgt].extend(states)
     return self.sort_top_targets(top, orders)
コード例 #9
0
ファイル: mysql.py プロジェクト: AccelerationNet/salt
    def process_results(self, rows):
        '''
            This function takes a list of database results and iterates over,
            merging them in to a dict form.
        '''
        listify = OrderedDict()
        listify_dicts = OrderedDict()
        for ret in rows:
            # crd is the Current Return Data level, to make this non-recursive.
            crd = self.focus
            # Walk and create dicts above the final layer
            for i in range(0, self.depth-1):
                # At the end we'll use listify to find values to make a list of
                if i+1 in self.with_lists:
                    if id(crd) not in listify:
                        listify[id(crd)] = []
                        listify_dicts[id(crd)] = crd
                    if ret[i] not in listify[id(crd)]:
                        listify[id(crd)].append(ret[i])
                if ret[i] not in crd:
                    # Key missing
                    crd[ret[i]] = {}
                    crd = crd[ret[i]]
                else:
                    # Check type of collision
                    ty = type(crd[ret[i]])
                    if ty is list:
                        # Already made list
                        temp = {}
                        crd[ret[i]].append(temp)
                        crd = temp
                    elif ty is not dict:
                        # Not a list, not a dict
                        if self.as_list:
                            # Make list
                            temp = {}
                            crd[ret[i]] = [crd[ret[i]], temp]
                            crd = temp
                        else:
                            # Overwrite
                            crd[ret[i]] = {}
                            crd = crd[ret[i]]
                    else:
                        # dict, descend.
                        crd = crd[ret[i]]

            # If this test is true, the penultimate field is the key
            if self.depth == self.num_fields - 1:
                nk = self.num_fields-2  # Aka, self.depth-1
                # Should we and will we have a list at the end?
                if ((self.as_list and (ret[nk] in crd)) or
                        (nk+1 in self.with_lists)):
                    if ret[nk] in crd:
                        if type(crd[ret[nk]]) is not list:
                            crd[ret[nk]] = [crd[ret[nk]]]
                        # if it's already a list, do nothing
                    else:
                        crd[ret[nk]] = []
                    crd[ret[nk]].append(ret[self.num_fields-1])
                else:
                    # No clobber checks then
                    crd[ret[nk]] = ret[self.num_fields-1]
            else:
                # Otherwise, the field name is the key but we have a spare.
                # The spare results because of {c: d} vs {c: {"d": d, "e": e }}
                # So, make that last dict
                if ret[self.depth-1] not in crd:
                    crd[ret[self.depth-1]] = {}
                # This bit doesn't escape listify
                if self.depth in self.with_lists:
                    if id(crd) not in listify:
                        listify[id(crd)] = []
                        listify_dicts[id(crd)] = crd
                    if ret[self.depth-1] not in listify[id(crd)]:
                        listify[id(crd)].append(ret[self.depth-1])
                crd = crd[ret[self.depth-1]]
                # Now for the remaining keys, we put them in to the dict
                for i in range(self.depth, self.num_fields):
                    nk = self.field_names[i]
                    # Listify
                    if i+1 in self.with_lists:
                        if id(crd) not in listify:
                            listify[id(crd)] = []
                            listify_dicts[id(crd)] = crd
                        if nk not in listify[id(crd)]:
                            listify[id(crd)].append(nk)
                    # Collision detection
                    if self.as_list and (nk in crd):
                        # Same as before...
                        if type(crd[nk]) is list:
                            crd[nk].append(ret[i])
                        else:
                            crd[nk] = [crd[nk], ret[i]]
                    else:
                        crd[nk] = ret[i]
        # Get key list and work backwards.  This is inner-out processing
        ks = listify_dicts.keys()
        ks.reverse()
        for i in ks:
            d = listify_dicts[i]
            for k in listify[i]:
                if type(d[k]) is dict:
                    d[k] = d[k].values()
                elif type(d[k]) is not list:
                    d[k] = [d[k]]
コード例 #10
0
    def process_results(self, rows):
        '''
            This function takes a list of database results and iterates over,
            merging them into a dict form.
        '''
        listify = OrderedDict()
        listify_dicts = OrderedDict()
        for ret in rows:
            # crd is the Current Return Data level, to make this non-recursive.
            crd = self.focus
            # Walk and create dicts above the final layer
            for i in range(0, self.depth - 1):
                # At the end we'll use listify to find values to make a list of
                if i + 1 in self.with_lists:
                    if id(crd) not in listify:
                        listify[id(crd)] = []
                        listify_dicts[id(crd)] = crd
                    if ret[i] not in listify[id(crd)]:
                        listify[id(crd)].append(ret[i])
                if ret[i] not in crd:
                    # Key missing
                    crd[ret[i]] = {}
                    crd = crd[ret[i]]
                else:
                    # Check type of collision
                    ty = type(crd[ret[i]])
                    if ty is list:
                        # Already made list
                        temp = {}
                        crd[ret[i]].append(temp)
                        crd = temp
                    elif ty is not dict:
                        # Not a list, not a dict
                        if self.as_list:
                            # Make list
                            temp = {}
                            crd[ret[i]] = [crd[ret[i]], temp]
                            crd = temp
                        else:
                            # Overwrite
                            crd[ret[i]] = {}
                            crd = crd[ret[i]]
                    else:
                        # dict, descend.
                        crd = crd[ret[i]]

            # If this test is true, the penultimate field is the key
            if self.depth == self.num_fields - 1:
                nk = self.num_fields - 2  # Aka, self.depth-1
                # Should we and will we have a list at the end?
                if ((self.as_list and (ret[nk] in crd))
                        or (nk + 1 in self.with_lists)):
                    if ret[nk] in crd:
                        if not isinstance(crd[ret[nk]], list):
                            crd[ret[nk]] = [crd[ret[nk]]]
                        # if it's already a list, do nothing
                    else:
                        crd[ret[nk]] = []
                    crd[ret[nk]].append(ret[self.num_fields - 1])
                else:
                    if not self.ignore_null or ret[self.num_fields -
                                                   1] is not None:
                        crd[ret[nk]] = ret[self.num_fields - 1]
            else:
                # Otherwise, the field name is the key but we have a spare.
                # The spare results because of {c: d} vs {c: {"d": d, "e": e }}
                # So, make that last dict
                if ret[self.depth - 1] not in crd:
                    crd[ret[self.depth - 1]] = {}
                # This bit doesn't escape listify
                if self.depth in self.with_lists:
                    if id(crd) not in listify:
                        listify[id(crd)] = []
                        listify_dicts[id(crd)] = crd
                    if ret[self.depth - 1] not in listify[id(crd)]:
                        listify[id(crd)].append(ret[self.depth - 1])
                crd = crd[ret[self.depth - 1]]
                # Now for the remaining keys, we put them into the dict
                for i in range(self.depth, self.num_fields):
                    nk = self.field_names[i]
                    # Listify
                    if i + 1 in self.with_lists:
                        if id(crd) not in listify:
                            listify[id(crd)] = []
                            listify_dicts[id(crd)] = crd
                        if nk not in listify[id(crd)]:
                            listify[id(crd)].append(nk)
                    # Collision detection
                    if self.as_list and (nk in crd):
                        # Same as before...
                        if isinstance(crd[nk], list):
                            crd[nk].append(ret[i])
                        else:
                            crd[nk] = [crd[nk], ret[i]]
                    else:
                        if not self.ignore_null or ret[i] is not None:
                            crd[nk] = ret[i]
        # Get key list and work backwards.  This is inner-out processing
        ks = list(listify_dicts.keys())
        ks.reverse()
        for i in ks:
            d = listify_dicts[i]
            for k in listify[i]:
                if isinstance(d[k], dict):
                    d[k] = list(d[k].values())
                elif isinstance(d[k], list):
                    d[k] = [d[k]]
コード例 #11
0
ファイル: kinds.py プロジェクト: arizvisa/saltstack-salt
# -*- coding: utf-8 -*-
"""
Application Kinds of Salt apps.
These are used to indicate what kind of Application is using RAET
"""
from __future__ import absolute_import, unicode_literals

from collections import namedtuple

from salt.utils.odict import OrderedDict

# Python equivalent of an enum
APPL_KINDS = OrderedDict([("master", 0), ("minion", 1), ("syndic", 2),
                          ("caller", 3)])
APPL_KIND_NAMES = OrderedDict(
    (v, k) for k, v in list(APPL_KINDS.items()))  # inverse map
ApplKind = namedtuple("ApplKind", list(APPL_KINDS.keys()))
applKinds = ApplKind(**APPL_KINDS)
コード例 #12
0
ファイル: kinds.py プロジェクト: MalloZup/salt-2
# -*- coding: utf-8 -*-
'''
Application Kinds of Salt apps.
These are used to indicate what kind of Application is using RAET
'''
from __future__ import absolute_import, unicode_literals
from collections import namedtuple
from salt.utils.odict import OrderedDict

# Python equivalent of an enum
APPL_KINDS = OrderedDict([('master', 0),
                          ('minion', 1),
                          ('syndic', 2),
                          ('caller', 3)])
APPL_KIND_NAMES = OrderedDict((v, k) for k, v in list(APPL_KINDS.items()))  # inverse map
ApplKind = namedtuple('ApplKind', list(APPL_KINDS.keys()))
applKinds = ApplKind(**APPL_KINDS)
コード例 #13
0
ファイル: kinds.py プロジェクト: DaveQB/salt
# -*- coding: utf-8 -*-
'''
Application Kinds of Salt apps.
These are used to indicate what kind of Application is using RAET
'''
from __future__ import absolute_import
from collections import namedtuple
from salt.utils.odict import OrderedDict

# Python equivalent of an enum
APPL_KINDS = OrderedDict([('master', 0),
                          ('minion', 1),
                          ('syndic', 2),
                          ('caller', 3)])
APPL_KIND_NAMES = OrderedDict((v, k) for k, v in list(APPL_KINDS.items()))  # inverse map
ApplKind = namedtuple('ApplKind', list(APPL_KINDS.keys()))
applKinds = ApplKind(**APPL_KINDS)
コード例 #14
0
ファイル: __init__.py プロジェクト: dlax/salt
# -*- coding: utf-8 -*-
'''
The daemons package is used to store implimentations of the Salt Master and
Minion enabling different transports.
'''

# Import Python Libs
from collections import namedtuple

# Import Salt Libs
from salt.utils.odict import OrderedDict

# Python equivalent of an enum
APPL_KINDS = OrderedDict([('master', 0), ('minion', 1), ('syndic', 2),
                          ('call', 3)])
APPL_KIND_NAMES = OrderedDict(
    (v, k) for k, v in APPL_KINDS.iteritems())  # inverse map
ApplKind = namedtuple('ApplKind', APPL_KINDS.keys())
applKinds = ApplKind(**APPL_KINDS)