zoukankan      html  css  js  c++  java
  • saltstack 的源码大概分析

    下面是简单示例:

                                salt/script.py 
                                    client = salt.cli.ssh.SaltSSH()
                                    client.run()
    
                                salt/cli/ssh.py 
                                    # self.config是读取的配置文件
                                    ssh = salt.client.ssh.SSH(self.config)
                                    ssh.run()
                                
                                salt/client/ssh/__init__.py 
                                    class SSH(object):
                                        def run(self, jid=None):
                                            if self.opts.get('raw_shell', False):
                                                fun = 'ssh._raw'
                                                args = argv
                                            else:
                                                fun = argv[0] if argv else ''
                                                args = argv[1:]
                                            for ret in self.handle_ssh():
                                                pass 
                                        
                                        def handle_ssh():
                                            routine = MultiprocessingProcess(target=self.handle_routine,args=args)
                                            routine.start()
                                        def handle_routine(self, que, opts, host, target, mine=False):
                                            single = Single(...)
                                            single.run()
                                
                                salt/client/ssh/__init__.py                             
                                    class Single(object):
                                        def run(self, deploy_attempted=False):
                                            stdout, retcode = self.run_wfunc()
                                            return stdout, stderr, retcode
                                        def run_wfunc(self):
                                            
                                            # 实例化Pillar对象
                                            pillar = salt.pillar.Pillar(
                                                    opts_pkg,
                                                    opts_pkg['grains'],
                                                    opts_pkg['id'],
                                                    opts_pkg.get('environment', 'base')
                                                    )
                                            pillar_dirs = {}
                                            
                                            # pillar对象.pillar => 去三个地方获取所有pillar
                                            pillar_data = pillar.compile_pillar(pillar_dirs=pillar_dirs)
                                            
                                            print(pillar_data)
                                    
                                salt/pillar/__init__.py 
                                    class Pillar(object):
                                        
                                        def __init__(...):
                                            # 去中找自定义pillar
                                            # /var/cache/salt/master/extmods/pillar/alex.py  # [**推荐使用**]
                                            # /usr/lib/python2.7/site-packages/salt/pillar/wupeiqi.py
                                            
                                            # ['wupeqii','alex','cmd_json',.....]
                                            self.ext_pillars = salt.loader.pillars(ext_pillar_opts, self.functions)
                                            
                                    def compile_pillar(self, ext=True, pillar_dirs=None):
                                        
                                        # 1. top.sls 
                                        # 去中找自定义pillar
                                        # 2. /var/cache/salt/master/extmods/pillar/alex.py  # [**推荐使用**]
                                        # 3. /usr/lib/python2.7/site-packages/salt/pillar/wupeiqi.py
                                        
                                        pillar1 = self.render_pillar('top.cls')
                                        pillar2 = self.ext_pillar(pillar1,...)
                                        
                                        return pillar1 + pillar2
                                            
                                    def self.ext_pillar(...):
                                        return self._external_pillar_data(....)
                                    
                                    def _external_pillar_data(self, pillar, val, pillar_dirs, key):
                                        ext = self.ext_pillars[key](self.minion_id,pillar,*val)
                                        return ext 
  • 相关阅读:
    httpclient 使用问题记录:org.apache.http.HttpException: Unsupported Content-Coding:GLZip
    Gitserver端密码变更,但是本地gitconfig配置未变更账号和密码问题解决
    线程池ThreadPoolExecutor学习
    Java 网络编程
    org.apache.ibatis.binding.BindingException: Invalid bound statement Mybatis绑定错误问题解决
    Java string类
    maven3.6.2 版本 在idea 2019.2.2下遇到的问题解决记录
    python
    django-URL与视图配置
    python 的datetime模块使用
  • 原文地址:https://www.cnblogs.com/ahliucong/p/10594266.html
Copyright © 2011-2022 走看看