runbooks.py 文件源码

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

项目:automatron 作者: madflojo 项目源码 文件源码
def cache_runbooks(config, logger):
    ''' Open, read and cache runbooks '''
    all_books = {}
    runbooks = None
    if os.path.isfile(config['runbook_path'] + "/init.yml"):
        with open(config['runbook_path'] + "/init.yml") as fh:
            template = Template(fh.read())
            yml = template.render()
            runbooks = yaml.load(yml)
        if runbooks:
            for target in runbooks:
                all_books[target] = {}
                if runbooks[target]:
                    for books in runbooks[target]:
                        logger.debug("Processing book: {0}".format(books))
                        book_path = "{0}/{1}".format(config['runbook_path'], books)
                        if os.path.isdir(book_path):
                            book_path = book_path + "/init.yml"
                        if os.path.isfile(book_path) is False:
                            logger.warn("Runbook File Error: {0} is not a file".format(book_path))
                        else:
                            with open(book_path) as bh:
                                all_books[target][books] = bh.read()
                else:
                    logger.warn("Error: No runbooks specified under {0}".format(target))
    return all_books
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号