• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python template.compile_template函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中salt.template.compile_template函数的典型用法代码示例。如果您正苦于以下问题:Python compile_template函数的具体用法?Python compile_template怎么用?Python compile_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了compile_template函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: render_pstate

 def render_pstate(self, sls, env, mods):
     """
     Collect a single pillar sls file and render it
     """
     err = ""
     errors = []
     fn_ = self.client.get_state(sls, env)
     if not fn_:
         errors.append(
             ("Specified SLS {0} in environment {1} is not" " available on the salt master").format(sls, env)
         )
     state = None
     try:
         state = compile_template(fn_, self.rend, self.opts["renderer"], env, sls)
     except Exception as exc:
         errors.append(("Rendering SLS {0} failed, render error:\n{1}".format(sls, exc)))
     mods.add(sls)
     nstate = None
     if state:
         if not isinstance(state, dict):
             errors.append(("SLS {0} does not render to a dictionary".format(sls)))
         else:
             if "include" in state:
                 if not isinstance(state["include"], list):
                     err = "Include Declaration in SLS {0} is not formed " "as a list".format(sls)
                     errors.append(err)
                 else:
                     for sub_sls in state.pop("include"):
                         if sub_sls not in mods:
                             nstate, mods, err = self.render_pstate(sub_sls, env, mods)
                         if nstate:
                             state.update(nstate)
                         if err:
                             errors += err
     return state, mods, errors
开发者ID:Barrybaby,项目名称:salt,代码行数:35,代码来源:__init__.py


示例2: query

def query(key, value=None, service=None, profile=None):  # pylint: disable=W0613
    '''
    Get a value from the REST interface
    '''
    comps = key.split('?')
    key = comps[0]
    key_vars = {}
    for pair in comps[1].split('&'):
        pair_key, pair_val = pair.split('=')
        key_vars[pair_key] = pair_val

    renderer = __opts__.get('renderer', 'yaml_jinja')
    rend = salt.loader.render(__opts__, {})
    blacklist = __opts__.get('renderer_blacklist')
    whitelist = __opts__.get('renderer_whitelist')
    url = compile_template(
        ':string:',
        rend,
        renderer,
        blacklist,
        whitelist,
        input_data=profile[key]['url'],
        **key_vars
    )

    result = http.query(
        url,
        decode=True,
        **key_vars
    )

    return result['dict']
开发者ID:bryson,项目名称:salt,代码行数:32,代码来源:rest.py


示例3: render

    def render(self, template, opts=None, filename=None):
        if opts:
            self.config.update(opts)

        if not filename:
            filename = ".".join([str(uuid.uuid4()), "sls"])
        full_path = self.write_template_file(filename, template)

        state = salt.state.State(self.config)
        return compile_template(full_path, state.rend, state.opts["renderer"])
开发者ID:AccelerationNet,项目名称:salt,代码行数:10,代码来源:pyobjects_test.py


示例4: targets

def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    template = get_roster_file(__opts__)

    rend = salt.loader.render(__opts__, {})
    raw = compile_template(template, rend, __opts__['renderer'], **kwargs)
    rmatcher = RosterMatcher(raw, tgt, tgt_type, 'ipv4')
    return rmatcher.targets()
开发者ID:dmyerscough,项目名称:salt,代码行数:11,代码来源:flat.py


示例5: _render

def _render(template, render, renderer, template_dict, opts):
    '''
    Render a template
    '''
    if render:
        if template_dict is None:
            template_dict = {}
        if not renderer:
            renderer = opts.get('renderer', 'yaml_jinja')
        rend = salt.loader.render(opts, {})
        return compile_template(template, rend, renderer, **template_dict)
    with salt.utils.fopen(template, 'r') as fh_:
        return fh_.read()
开发者ID:iquaba,项目名称:salt,代码行数:13,代码来源:http.py


示例6: render_pstate

 def render_pstate(self, sls, env, mods):
     '''
     Collect a single pillar sls file and render it
     '''
     err = ''
     errors = []
     fn_ = self.client.get_state(sls, env).get('dest', False)
     if not fn_:
         msg = ('Specified SLS {0!r} in environment {1!r} is not'
                ' available on the salt master').format(sls, env)
         log.error(msg)
         errors.append(msg)
     state = None
     try:
         state = compile_template(
             fn_, self.rend, self.opts['renderer'], env, sls)
     except Exception as exc:
         msg = 'Rendering SLS {0!r} failed, render error:\n{1}'.format(
             sls, exc
         )
         log.error(msg)
         errors.append(msg)
     mods.add(sls)
     nstate = None
     if state:
         if not isinstance(state, dict):
             msg = 'SLS {0!r} does not render to a dictionary'.format(sls)
             log.error(msg)
             errors.append(msg)
         else:
             if 'include' in state:
                 if not isinstance(state['include'], list):
                     msg = ('Include Declaration in SLS {0!r} is not '
                            'formed as a list'.format(sls))
                     log.error(msg)
                     errors.append(msg)
                 else:
                     for sub_sls in state.pop('include'):
                         if sub_sls not in mods:
                             nstate, mods, err = self.render_pstate(
                                     sub_sls,
                                     env,
                                     mods
                                     )
                         if nstate:
                             state.update(nstate)
                         if err:
                             errors += err
     return state, mods, errors
开发者ID:jaypei,项目名称:salt,代码行数:49,代码来源:__init__.py


示例7: targets

def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    if os.path.isfile(__opts__['conf_file']) or not os.path.exists(__opts__['conf_file']):
        template = os.path.join(
                os.path.dirname(__opts__['conf_file']),
                'roster')
    else:
        template = os.path.join(__opts__['conf_file'], 'roster')
    rend = salt.loader.render(__opts__, {})
    raw = compile_template(template, rend, __opts__['renderer'], **kwargs)
    rmatcher = RosterMatcher(raw, tgt, tgt_type, 'ipv4')
    return rmatcher.targets()
开发者ID:jslatts,项目名称:salt,代码行数:15,代码来源:flat.py


示例8: targets

def targets(tgt, tgt_type='glob', **kwargs):
    '''
    Return the targets from the flat yaml file, checks opts for location but
    defaults to /etc/salt/roster
    '''
    template = get_roster_file(__opts__)

    rend = salt.loader.render(__opts__, {})
    raw = compile_template(template,
                           rend,
                           __opts__['renderer'],
                           __opts__['renderer_blacklist'],
                           __opts__['renderer_whitelist'],
                           **kwargs)
    conditioned_raw = {}
    for minion in raw:
        conditioned_raw[str(minion)] = raw[minion]
    rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
    return rmatcher.targets()
开发者ID:bryson,项目名称:salt,代码行数:19,代码来源:flat.py


示例9: get_tops

    def get_tops(self):
        '''
        Gather the top files
        '''
        tops = collections.defaultdict(list)
        include = collections.defaultdict(list)
        done = collections.defaultdict(list)
        errors = []
        # Gather initial top files
        try:
            if self.opts['environment']:
                tops[self.opts['environment']] = [
                        compile_template(
                            self.client.cache_file(
                                self.opts['state_top'],
                                self.opts['environment']
                                ),
                            self.rend,
                            self.opts['renderer'],
                            self.opts['environment']
                            )
                        ]
            else:
                for env in self._get_envs():
                    tops[env].append(
                            compile_template(
                                self.client.cache_file(
                                    self.opts['state_top'],
                                    env
                                    ),
                                self.rend,
                                self.opts['renderer'],
                                env=env
                                )
                            )
        except Exception as exc:
            errors.append(
                    ('Rendering Primary Top file failed, render error:\n{0}'
                        .format(exc)))

        # Search initial top files for includes
        for env, ctops in tops.items():
            for ctop in ctops:
                if not 'include' in ctop:
                    continue
                for sls in ctop['include']:
                    include[env].append(sls)
                ctop.pop('include')
        # Go through the includes and pull out the extra tops and add them
        while include:
            pops = []
            for env, states in include.items():
                pops.append(env)
                if not states:
                    continue
                for sls in states:
                    if sls in done[env]:
                        continue
                    try:
                        tops[env].append(
                                compile_template(
                                    self.client.get_state(
                                        sls,
                                        env
                                        ),
                                    self.rend,
                                    self.opts['renderer'],
                                    env=env
                                    )
                                )
                    except Exception as exc:
                        errors.append(
                                ('Rendering Top file {0} failed, render error'
                                 ':\n{1}').format(sls, exc))
                    done[env].append(sls)
            for env in pops:
                if env in include:
                    include.pop(env)

        return tops, errors
开发者ID:FireHost,项目名称:salt,代码行数:80,代码来源:__init__.py


示例10: render_pstate

    def render_pstate(self, sls, saltenv, mods, defaults=None):
        '''
        Collect a single pillar sls file and render it
        '''
        if defaults is None:
            defaults = {}
        err = ''
        errors = []
        fn_ = self.client.get_state(sls, saltenv).get('dest', False)
        if not fn_:
            if sls in self.ignored_pillars.get(saltenv, []):
                log.debug('Skipping ignored and missing SLS \'{0}\' in'
                          ' environment \'{1}\''.format(sls, saltenv))
                return None, mods, errors
            elif self.opts['pillar_roots'].get(saltenv):
                msg = ('Specified SLS \'{0}\' in environment \'{1}\' is not'
                       ' available on the salt master').format(sls, saltenv)
                log.error(msg)
                errors.append(msg)
            else:
                msg = ('Specified SLS \'{0}\' in environment \'{1}\' was not '
                       'found. '.format(sls, saltenv))
                if self.opts.get('__git_pillar', False) is True:
                    msg += (
                        'This is likely caused by a git_pillar top file '
                        'containing an environment other than the one for the '
                        'branch in which it resides. Each git_pillar '
                        'branch/tag must have its own top file.'
                    )
                else:
                    msg += (
                        'This could be because SLS \'{0}\' is in an '
                        'environment other than \'{1}\', but \'{1}\' is '
                        'included in that environment\'s Pillar top file. It '
                        'could also be due to environment \'{1}\' not being '
                        'defined in \'pillar_roots\'.'.format(sls, saltenv)
                    )
                log.debug(msg)
                # return state, mods, errors
                return None, mods, errors
        state = None
        try:
            state = compile_template(fn_,
                                     self.rend,
                                     self.opts['renderer'],
                                     self.opts['renderer_blacklist'],
                                     self.opts['renderer_whitelist'],
                                     saltenv,
                                     sls,
                                     _pillar_rend=True,
                                     **defaults)
        except Exception as exc:
            msg = 'Rendering SLS \'{0}\' failed, render error:\n{1}'.format(
                sls, exc
            )
            log.critical(msg)
            if self.opts.get('pillar_safe_render_error', True):
                errors.append(
                    'Rendering SLS \'{0}\' failed. Please see master log for '
                    'details.'.format(sls)
                )
            else:
                errors.append(msg)
        mods.add(sls)
        nstate = None
        if state:
            if not isinstance(state, dict):
                msg = 'SLS \'{0}\' does not render to a dictionary'.format(sls)
                log.error(msg)
                errors.append(msg)
            else:
                if 'include' in state:
                    if not isinstance(state['include'], list):
                        msg = ('Include Declaration in SLS \'{0}\' is not '
                               'formed as a list'.format(sls))
                        log.error(msg)
                        errors.append(msg)
                    else:
                        for sub_sls in state.pop('include'):
                            if isinstance(sub_sls, dict):
                                sub_sls, v = next(six.iteritems(sub_sls))
                                defaults = v.get('defaults', {})
                                key = v.get('key', None)
                            else:
                                key = None
                            if sub_sls not in mods:
                                nstate, mods, err = self.render_pstate(
                                        sub_sls,
                                        saltenv,
                                        mods,
                                        defaults
                                        )
                                if nstate:
                                    if key:
                                        nstate = {
                                            key: nstate
                                        }

                                    state = merge(
                                        state,
#.........这里部分代码省略.........
开发者ID:bryson,项目名称:salt,代码行数:101,代码来源:__init__.py


示例11: get_tops

    def get_tops(self):
        '''
        Gather the top files
        '''
        tops = collections.defaultdict(list)
        include = collections.defaultdict(list)
        done = collections.defaultdict(list)
        errors = []
        # Gather initial top files
        try:
            if self.opts['pillarenv']:
                tops[self.opts['pillarenv']] = [
                        compile_template(
                            self.client.cache_file(
                                self.opts['state_top'],
                                self.opts['pillarenv']
                                ),
                            self.rend,
                            self.opts['renderer'],
                            self.opts['renderer_blacklist'],
                            self.opts['renderer_whitelist'],
                            self.opts['pillarenv'],
                            _pillar_rend=True,
                            )
                        ]
            else:
                for saltenv in self._get_envs():
                    if self.opts.get('pillar_source_merging_strategy', None) == "none":
                        if self.saltenv and saltenv != self.saltenv:
                            continue
                        if not self.saltenv and not saltenv == 'base':
                            continue
                    top = self.client.cache_file(
                            self.opts['state_top'],
                            saltenv
                            )
                    if top:
                        tops[saltenv].append(
                                compile_template(
                                    top,
                                    self.rend,
                                    self.opts['renderer'],
                                    self.opts['renderer_blacklist'],
                                    self.opts['renderer_whitelist'],
                                    saltenv=saltenv,
                                    _pillar_rend=True,
                                    )
                                )
        except Exception as exc:
            errors.append(
                    ('Rendering Primary Top file failed, render error:\n{0}'
                        .format(exc)))
            log.error('Pillar rendering failed for minion {0}: '.format(self.minion_id),
                    exc_info=True)

        # Search initial top files for includes
        for saltenv, ctops in six.iteritems(tops):
            for ctop in ctops:
                if 'include' not in ctop:
                    continue
                for sls in ctop['include']:
                    include[saltenv].append(sls)
                ctop.pop('include')
        # Go through the includes and pull out the extra tops and add them
        while include:
            pops = []
            for saltenv, states in six.iteritems(include):
                pops.append(saltenv)
                if not states:
                    continue
                for sls in states:
                    if sls in done[saltenv]:
                        continue
                    try:
                        tops[saltenv].append(
                                compile_template(
                                    self.client.get_state(
                                        sls,
                                        saltenv
                                        ).get('dest', False),
                                    self.rend,
                                    self.opts['renderer'],
                                    self.opts['renderer_blacklist'],
                                    self.opts['renderer_whitelist'],
                                    saltenv=saltenv,
                                    _pillar_rend=True,
                                    )
                                )
                    except Exception as exc:
                        errors.append(
                                ('Rendering Top file {0} failed, render error'
                                 ':\n{1}').format(sls, exc))
                    done[saltenv].append(sls)
            for saltenv in pops:
                if saltenv in include:
                    include.pop(saltenv)

        return tops, errors
开发者ID:bryson,项目名称:salt,代码行数:98,代码来源:__init__.py


示例12: render_pstate

 def render_pstate(self, sls, saltenv, mods, defaults=None):
     '''
     Collect a single pillar sls file and render it
     '''
     if defaults is None:
         defaults = {}
     err = ''
     errors = []
     fn_ = self.client.get_state(sls, saltenv).get('dest', False)
     if not fn_:
         if self.opts['pillar_roots'].get(saltenv):
             msg = ('Specified SLS {0!r} in environment {1!r} is not'
                    ' available on the salt master').format(sls, saltenv)
             log.error(msg)
             errors.append(msg)
         else:
             log.debug('Specified SLS {0!r} in environment {1!r} is not'
                       ' found, which might be due to environment {1!r}'
                       ' not being present in "pillar_roots" yet!'
                       .format(sls, saltenv))
             # return state, mods, errors
             return None, mods, errors
     state = None
     try:
         state = compile_template(
             fn_, self.rend, self.opts['renderer'], saltenv, sls, **defaults)
     except Exception as exc:
         msg = 'Rendering SLS {0!r} failed, render error:\n{1}'.format(
             sls, exc
         )
         log.critical(msg)
         errors.append(msg)
     mods.add(sls)
     nstate = None
     if state:
         if not isinstance(state, dict):
             msg = 'SLS {0!r} does not render to a dictionary'.format(sls)
             log.error(msg)
             errors.append(msg)
         else:
             if 'include' in state:
                 if not isinstance(state['include'], list):
                     msg = ('Include Declaration in SLS {0!r} is not '
                            'formed as a list'.format(sls))
                     log.error(msg)
                     errors.append(msg)
                 else:
                     for sub_sls in state.pop('include'):
                         if isinstance(sub_sls, dict):
                             sub_sls, v = sub_sls.iteritems().next()
                             defaults = v.get('defaults', {})
                             key = v.get('key', None)
                         else:
                             key = None
                         if sub_sls not in mods:
                             nstate, mods, err = self.render_pstate(
                                     sub_sls,
                                     saltenv,
                                     mods,
                                     defaults
                                     )
                         if nstate:
                             if key:
                                 state[key] = nstate
                             else:
                                 state.update(nstate)
                         if err:
                             errors += err
     return state, mods, errors
开发者ID:AccelerationNet,项目名称:salt,代码行数:69,代码来源:__init__.py


示例13: returner

def returner(ret):
    '''
    Send an email with the data
    '''

    _options = _get_options(ret)
    from_addr = _options.get('from')
    to_addrs = _options.get('to')
    host = _options.get('host')
    port = _options.get('port')
    user = _options.get('username')
    passwd = _options.get('password')
    subject = _options.get('subject')
    gpgowner = _options.get('gpgowner')
    fields = _options.get('fields').split(',') if 'fields' in _options else []
    smtp_tls = _options.get('tls')

    renderer = _options.get('renderer', __opts__.get('renderer', 'yaml_jinja'))
    rend = salt.loader.render(__opts__, {})

    if not port:
        port = 25
    log.debug('SMTP port has been set to {0}'.format(port))
    for field in fields:
        if field in ret:
            subject += ' {0}'.format(ret[field])
    subject = compile_template(':string:', rend, renderer, input_data=subject, **ret)
    log.debug("smtp_return: Subject is '{0}'".format(subject))

    template = _options.get('template')
    if template:
        content = compile_template(template, rend, renderer, **ret)
    else:
        template = ('id: {{id}}\r\n'
                    'function: {{fun}}\r\n'
                    'function args: {{fun_args}}\r\n'
                    'jid: {{jid}}\r\n'
                    'return: {{return}}\r\n')
        content = compile_template(':string:', rend, renderer, input_data=template, **ret)

    if HAS_GNUPG and gpgowner:
        gpg = gnupg.GPG(gnupghome=os.path.expanduser('~{0}/.gnupg'.format(gpgowner)),
                        options=['--trust-model always'])
        encrypted_data = gpg.encrypt(content, to_addrs)
        if encrypted_data.ok:
            log.debug('smtp_return: Encryption successful')
            content = str(encrypted_data)
        else:
            log.error('smtp_return: Encryption failed, only an error message will be sent')
            content = 'Encryption failed, the return data was not sent.\r\n\r\n{0}\r\n{1}'.format(
                    encrypted_data.status, encrypted_data.stderr)

    message = ('From: {0}\r\n'
               'To: {1}\r\n'
               'Date: {2}\r\n'
               'Subject: {3}\r\n'
               '\r\n'
               '{4}').format(from_addr,
                             to_addrs,
                             formatdate(localtime=True),
                             subject,
                             content)

    log.debug('smtp_return: Connecting to the server...')
    server = smtplib.SMTP(host, int(port))
    server.set_debuglevel = 'debug'
    if smtp_tls is True:
        server.starttls()
        log.debug('smtp_return: TLS enabled')
    if user and passwd:
        server.login(user, passwd)
        log.debug('smtp_return: Authenticated')
    server.sendmail(from_addr, to_addrs, message)
    log.debug('smtp_return: Message sent.')
    server.quit()
开发者ID:DaveQB,项目名称:salt,代码行数:75,代码来源:smtp_return.py


示例14: render_pstate

 def render_pstate(self, sls, saltenv, mods, defaults=None):
     """
     Collect a single pillar sls file and render it
     """
     if defaults is None:
         defaults = {}
     err = ""
     errors = []
     fn_ = self.client.get_state(sls, saltenv).get("dest", False)
     if not fn_:
         if self.opts["pillar_roots"].get(saltenv):
             msg = ("Specified SLS {0!r} in environment {1!r} is not" " available on the salt master").format(
                 sls, saltenv
             )
             log.error(msg)
             errors.append(msg)
         else:
             log.debug(
                 "Specified SLS {0!r} in environment {1!r} is not"
                 " found, which might be due to environment {1!r}"
                 ' not being present in "pillar_roots" yet!'.format(sls, saltenv)
             )
             # return state, mods, errors
             return None, mods, errors
     state = None
     try:
         state = compile_template(fn_, self.rend, self.opts["renderer"], saltenv, sls, **defaults)
     except Exception as exc:
         msg = "Rendering SLS {0!r} failed, render error:\n{1}".format(sls, exc)
         log.critical(msg)
         errors.append(msg)
     mods.add(sls)
     nstate = None
     if state:
         if not isinstance(state, dict):
             msg = "SLS {0!r} does not render to a dictionary".format(sls)
             log.error(msg)
             errors.append(msg)
         else:
             if "include" in state:
                 if not isinstance(state["include"], list):
                     msg = "Include Declaration in SLS {0!r} is not " "formed as a list".format(sls)
                     log.error(msg)
                     errors.append(msg)
                 else:
                     for sub_sls in state.pop("include"):
                         if isinstance(sub_sls, dict):
                             sub_sls, v = sub_sls.iteritems().next()
                             defaults = v.get("defaults", {})
                             key = v.get("key", None)
                         else:
                             key = None
                         if sub_sls not in mods:
                             nstate, mods, err = self.render_pstate(sub_sls, saltenv, mods, defaults)
                         if nstate:
                             if key:
                                 state[key] = nstate
                             else:
                                 state.update(nstate)
                         if err:
                             errors += err
     return state, mods, errors
开发者ID:bemehow,项目名称:salt,代码行数:62,代码来源:__init__.py


示例15: render_pstate

    def render_pstate(self, sls, saltenv, mods, defaults=None):
        '''
        Collect a single pillar sls file and render it
        '''
        if defaults is None:
            defaults = {}
        err = ''
        errors = []
        fn_ = self.client.get_state(sls, saltenv).get('dest', False)
        if not fn_:
            if sls in self.ignored_pillars.get(saltenv, []):
                log.debug('Skipping ignored and missing SLS {0!r} in'
                          ' environment {1!r}'.format(sls, saltenv))
                return None, mods, errors
            elif self.opts['pillar_roots'].get(saltenv):
                msg = ('Specified SLS {0!r} in environment {1!r} is not'
                       ' available on the salt master').format(sls, saltenv)
                log.error(msg)
                errors.append(msg)
            else:
                log.debug('Specified SLS {0!r} in environment {1!r} is not'
                          ' found, which might be due to environment {1!r}'
                          ' not being present in "pillar_roots" yet!'
                          .format(sls, saltenv))
                # return state, mods, errors
                return None, mods, errors
        state = None
        try:
            state = compile_template(
                fn_, self.rend, self.opts['renderer'], saltenv, sls, _pillar_rend=True, **defaults)
        except Exception as exc:
            msg = 'Rendering SLS {0!r} failed, render error:\n{1}'.format(
                sls, exc
            )
            log.critical(msg)
            if self.opts.get('pillar_safe_render_error', True):
                errors.append('Rendering SLS \'{0}\' failed. Please see master log for details.'.format(sls))
            else:
                errors.append(msg)
        mods.add(sls)
        nstate = None
        if state:
            if not isinstance(state, dict):
                msg = 'SLS {0!r} does not render to a dictionary'.format(sls)
                log.error(msg)
                errors.append(msg)
            else:
                if 'include' in state:
                    if not isinstance(state['include'], list):
                        msg = ('Include Declaration in SLS {0!r} is not '
                               'formed as a list'.format(sls))
                        log.error(msg)
                        errors.append(msg)
                    else:
                        for sub_sls in state.pop('include'):
                            if isinstance(sub_sls, dict):
                                sub_sls, v = next(six.iteritems(sub_sls))
                                defaults = v.get('defaults', {})
                                key = v.get('key', None)
                            else:
                                key = None
                            if sub_sls not in mods:
                                nstate, mods, err = self.render_pstate(
                                        sub_sls,
                                        saltenv,
                                        mods,
                                        defaults
                                        )
                            if nstate:
                                if key:
                                    nstate = {
                                        key: nstate
                                    }

                                state = merge(
                                    state,
                                    nstate,
                                    self.merge_strategy,
                                    self.opts.get('renderer', 'yaml'))

                            if err:
                                errors += err
        return state, mods, errors
开发者ID:DaveQB,项目名称:salt,代码行数:83,代码来源:__init__.py


示例16: test_compile_template_bad_type

 def test_compile_template_bad_type(self):
     '''
     Test to ensure that unsupported types cannot be passed to the template compiler
     '''
     ret = template.compile_template(['1', '2', '3'], None, None)
     self.assertDictEqual(ret, {})
开发者ID:AccelerationNet,项目名称:salt,代码行数:6,代码来源:template_test.py


示例17: get_tops

    def get_tops(self):
        """
        Gather the top files
        """
        tops = collections.defaultdict(list)
        include = collections.defaultdict(list)
        done = collections.defaultdict(list)
        errors = []
        # Gather initial top files
        try:
            if self.opts["environment"]:
                tops[self.opts["environment"]] = [
                    compile_template(
                        self.client.cache_file(self.opts["state_top"], self.opts["environment"]),
                        self.rend,
                        self.opts["renderer"],
                        self.opts["environment"],
                    )
                ]
            else:
                for saltenv in self._get_envs():
                    tops[saltenv].append(
                        compile_template(
                            self.client.cache_file(self.opts["state_top"], saltenv),
                            self.rend,
                            self.opts["renderer"],
                            saltenv=saltenv,
                        )
                    )
        except Exception as exc:
            errors.append(("Rendering Primary Top file failed, render error:\n{0}".format(exc)))

        # Search initial top files for includes
        for saltenv, ctops in tops.items():
            for ctop in ctops:
                if "include" not in ctop:
                    continue
                for sls in ctop["include"]:
                    include[saltenv].append(sls)
                ctop.pop("include")
        # Go through the includes and pull out the extra tops and add them
        while include:
            pops = []
            for saltenv, states in include.items():
                pops.append(saltenv)
                if not states:
                    continue
                for sls in states:
                    if sls in done[saltenv]:
                        continue
                    try:
                        tops[saltenv].append(
                            compile_template(
                                self.client.get_state(sls, saltenv).get("dest", False),
                                self.rend,
                                self.opts["renderer"],
                                saltenv=saltenv,
                            )
                        )
                    except Exception as exc:
                        errors.append(("Rendering Top file {0} failed, render error" ":\n{1}").format(sls, exc))
                    done[saltenv].append(sls)
            for saltenv in pops:
                if saltenv in include:
                    include.pop(saltenv)

        return tops, errors
开发者ID:bemehow,项目名称:salt,代码行数:67,代码来源:__init__.py



注:本文中的salt.template.compile_template函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.check_or_die函数代码示例发布时间:2022-05-27
下一篇:
Python git._fail函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap