importer.py 文件源码

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

项目:foreman-yml 作者: adfinis-sygroup 项目源码 文件源码
def process_config_provisioningtpl(self):
        log.log(log.LOG_INFO, "Processing Provisioning Templates")
        # fm.provisioning_templates.show(name) does not work as expected, we need to iterate over fm.provisioning_templates.index()
        ptlist = self.fm.provisioning_templates.index(per_page=99999)['results']
        for pt in self.get_config_section('provisioning-template'):
            try:
                self.validator.provt(pt)
            except MultipleInvalid as e:
                log.log(log.LOG_WARN, "Cannot create Provisioning Template '{0}': YAML validation Error: {1}".format(pt['name'], e))
                continue

            pt_id = False
            for ptc in ptlist:
                if (ptc['name'] == pt['name']):
                    pt_id = ptc['id']
                    log.log(log.LOG_DEBUG, "Provisioning Template '{0}' (id={1}) already present.".format(pt['name'], pt_id))
            if not pt_id:
                log.log(log.LOG_INFO, "Create Provisioning Template '{0}'".format(pt['name']))
                pt_tpl = {
                    'name':             pt['name'],
                    'template':         pt['template'],
                    'snippet':          pt['snippet'],
                    'audit_comment':    pt['audit-comment'],
                    'template_kind_id': pt['template-kind-id'],
                    'locked':           pt['locked']
                }
                os_ids = []
                for osc in pt['os']:
                    try:
                        os_id = self.fm.operatingsystems.show(osc['name'])['id']
                        os_ids.append(os_id)
                    except:
                        log.log(log.LOG_WARN, "Cannot link OS '{0}' to Provisioning Template '{1}'".format(osc['name'],pt['name']))
                pt_tpl = {
                    'name':                 pt['name'],
                    'template':             pt['template'],
                    'snippet':              pt['snippet'],
                    'audit_comment':        pt['audit-comment'],
                    'template_kind_id':     pt['template-kind-id'],
                    'locked':               pt['locked'],
                    'operatingsystem_ids':  os_ids
                }
                prtes = self.fm.provisioning_templates.create(provisioning_template=pt_tpl)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号