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
评论列表
文章目录