saltstack 的源码大概分析

Posted ahliucong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 

 

以上是关于saltstack 的源码大概分析的主要内容,如果未能解决你的问题,请参考以下文章

Android 逆向整体加固脱壳 ( DEX 优化流程分析 | DexPrepare.cpp 中 dvmOptimizeDexFile() 方法分析 | /bin/dexopt 源码分析 )(代码片段

Android 事件分发事件分发源码分析 ( Activity 中各层级的事件传递 | Activity -> PhoneWindow -> DecorView -> ViewGroup )(代码片段

使用saltstack编译安装nginx

首发分析 | SaltStack远程执行代码多个高危漏洞透析(CVE-2021-25281/25282/25283)

《Docker 源码分析》全球首发啦!

漏洞更新SaltStack 多个高危漏洞(含漏洞分析及深信服解决方案)