码迷,mamicode.com
首页 > 其他好文 > 详细

saltstack 的源码大概分析

时间:2019-03-25 16:04:37      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:environ   ret   hand   render   nio   art   ...   compile   RoCE   

下面是简单示例:

                            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 的源码大概分析

标签:environ   ret   hand   render   nio   art   ...   compile   RoCE   

原文地址:https://www.cnblogs.com/ahliucong/p/10594266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!