aws.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()
        with open('result/{}/infrastructure/terraform.tfstate'.format(self.grid_name), 'r') as json_file:
            json_data = json.load(json_file)
            for module in json_data['modules']:
                for resource, value in module['resources'].iteritems():
                    if value['type'] == 'aws_instance':
                        hostname = value['primary']['attributes']['private_dns'].split('.')[0]
                        host = '{}.node.{}'.format(hostname, self.grid_name)
                        ip = value['primary']['attributes']['private_ip']
                        hosts_entries['hosts'][str(host)] = str(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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号