custom.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:cloud-deploy-grid 作者: elodina 项目源码 文件源码
def generate_group_vars_all(self):
        path = 'result/{}/group_vars/all'.format(self.grid_name)
        variables = AutoDict()
        hosts_entries = AutoDict()
        for group in self.current_groups:
            for ip in group.groupips.split(','):
                hostname = ip.replace('.','-')
                host = '{}.node.{}'.format(hostname, self.grid_name)
                hosts_entries['hosts'][str(host)] = str(ip)
            for ip in self.current_config.mastersips.split(','):
                hostname = ip.replace('.','-')
                host = '{}.node.{}'.format(hostname, self.grid_name)
                hosts_entries['hosts'][str(host)] = str(ip)
            terminal_ip = self.current_config.terminalips.split(',')[1]
            terminal_hostname = terminal_ip.replace('.','-')
            terminal_host = '{}.node.{}'.format(terminal_hostname, self.grid_name)
            hosts_entries['hosts'][str(terminal_host)] = str(terminal_ip)
        variables['hosts'] = json.dumps(hosts_entries['hosts'])
        variables['grid_name'] = self.current_grid.name
        variables['terminal_ip'] = self._nameserver()
        self._generate_template(path, variables)
        vars_json = json.loads(self.current_config.vars)
        vars_yaml = yaml.safe_dump(vars_json, default_flow_style=False)
        with open(path, "a") as yaml_file:
            yaml_file.write(vars_yaml)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号