importer.py 文件源码

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

项目:foreman-yml 作者: adfinis-sygroup 项目源码 文件源码
def process_template_combination_attribute(self):
        ptlist = self.fm.provisioning_templates.index(per_page=99999)['results']
        envlist = self.fm.environments.index(per_page=99999)['results']
        for pt in self.get_config_section('provisioning-template'):

            msg = ""

            pt_id = False
            for ptc in ptlist:
                if (ptc['name'] == pt['name']):
                    pt_id = ptc['id']
            if not pt_id:
                log.log(log.LOG_WARN, "Cannot resolve Provisioning template '{0}' ".format(pt['name']) )
                continue

            if 'template_combination_attribute' not in pt or pt['template-combination-attribute'] is None:
                continue
            else:
                linklist = pt['template-combination-attribute']

            for item in linklist:
                env_id = False
                hg_id = False
                for envc in envlist:
                    try:
                        if (item['enviroment'] == envc['name']):
                            env_id = envc['id']
                    except KeyError:
                        env_id = False
                try:
                    hg_id = self.fm.hostgroups.show(item['hostgroup'])['id']
                except:
                    hg_id = False

                if hg_id is not False or env_id is not False:

                    pt_api_arr = {
                        "template_combinations_attributes": [ {} ]
                    }

                    if hg_id is not False:
                        pt_api_arr["template_combinations_attributes"][0]["hostgroup_id"] = hg_id

                    if env_id is not False:
                        pt_api_arr["template_combinations_attributes"][0]["environment_id"] = env_id

                    try:
                        self.fm.provisioning_templates.update(pt_api_arr, pt_id)
                    except ForemanException as e:
                        msg = self.get_api_error_msg(e)
                        log.log(log.LOG_WARN, "Cannot link provisioning template '{0}' api says: '{1}'".format(pt['name'], msg) )
                        continue
                else:
                    log.log(log.LOG_WARN, "Cannot link provisioning template '{0}', at least hostgroup needs to be valid".format(pt['name'], msg) )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号