__init__.py 文件源码

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

项目:bridgy 作者: wagoodman 项目源码 文件源码
def inventory(config):
    inventorySet = InventorySet()

    for source, srcCfg in config.sources():
        if source == 'aws':
            # the cache directory for the original v1 config did not separate 
            # out multiple aws profiles into subdirectories
            if config.version == 1:
                cache_dir = config.inventoryDir(AwsInventory.name)
            else:
                cache_dir = config.inventoryDir(AwsInventory.name, srcCfg['name'])

            if not os.path.exists(cache_dir):
                os.mkdir(cache_dir)

            from botocore.exceptions import ProfileNotFound
            try:
                inv = AwsInventory(cache_dir, **srcCfg)
                inventorySet.add(inv)
            except ProfileNotFound:
                logger.error("Unconfigured AWS profile configured.")
                sys.exit(1)

        elif source == 'csv':
            inv = CsvInventory(path=config.inventoryDir(source, srcCfg['file']), **srcCfg)
            inventorySet.add(inv)

        elif source == 'newrelic':

            proxies = {}

            if config.dig('inventory', 'http_proxy'):
                proxies['http'] = config.dig('inventory', 'http_proxy')
            elif 'HTTP_PROXY' in os.environ:
                proxies['http'] = os.environ['HTTP_PROXY']
            elif 'http_proxy' in os.environ:
                proxies['http'] = os.environ['http_proxy']

            if config.dig('inventory', 'https_proxy'):
                proxies['https'] = config.dig('inventory', 'https_proxy')
            elif 'HTTPS_PROXY' in os.environ:
                proxies['https'] = os.environ['HTTPS_PROXY']
            elif 'https_proxy' in os.environ:
                proxies['https'] = os.environ['https_proxy']

            inv = NewRelicInventory(data_path=config.inventoryDir(NewRelicInventory.name),
                                    proxies=proxies,
                                    **srcCfg)

            inventorySet.add(inv)

    return inventorySet
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号