From 0457b96cd5b5252010208ee8f74d0a3da49573b2 Mon Sep 17 00:00:00 2001 From: Thomas Wiest Date: Thu, 8 Jan 2015 12:39:33 -0500 Subject: added opssh.py --- inventory/multi_ec2.py | 1 + 1 file changed, 1 insertion(+) (limited to 'inventory/multi_ec2.py') diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index d8c2dc854..c60bb50d2 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# vim: expandtab:tabstop=4:shiftwidth=4 from time import time import argparse -- cgit v1.2.3 From ee96928a2d1c21c5d2319418f4cf6ca774a3e010 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Thu, 5 Feb 2015 16:02:36 -0500 Subject: Attempting to only refresh cache when doing --list on ossh. --- inventory/multi_ec2.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'inventory/multi_ec2.py') diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index c60bb50d2..499264267 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -43,9 +43,15 @@ class MultiEc2(object): else: raise RuntimeError("Could not find valid ec2 credentials in the environment.") + if self.args.cache_only: + # get data from disk + result = self.get_inventory_from_cache() + if not result: + self.get_inventory() + self.write_to_cache() # if its a host query, fetch and do not cache - if self.args.host: + elif self.args.host: self.get_inventory() elif not self.is_cache_valid(): # go fetch the inventories and cache them if cache is expired @@ -186,6 +192,8 @@ class MultiEc2(object): ''' Command line argument processing ''' parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on a provider') + parser.add_argument('--cache-only', action='store_true', default=False, + help='Fetch cached only instances (default: False)') parser.add_argument('--list', action='store_true', default=True, help='List instances (default: True)') parser.add_argument('--host', action='store', default=False, @@ -203,9 +211,14 @@ class MultiEc2(object): ''' Reads the inventory from the cache file and returns it as a JSON object ''' + if not os.path.isfile(self.cache_path): + return None + with open(self.cache_path, 'r') as cache: self.result = json.loads(cache.read()) + return True + def json_format_dict(self, data, pretty=False): ''' Converts a dict to a JSON object and dumps it as a formatted string ''' -- cgit v1.2.3