summaryrefslogtreecommitdiffstats
path: root/inventory
diff options
context:
space:
mode:
authorThomas Wiest <twiest@redhat.com>2014-12-18 11:07:13 -0500
committerThomas Wiest <twiest@redhat.com>2014-12-18 11:07:13 -0500
commit34ac7b11c72a4ef30a3c646271410578245cd582 (patch)
tree731d4169122b6f32f3b52d1e787ba7cb91b6758a /inventory
parent2c11830eb8a910ebd70a39e235d25d48708ede12 (diff)
downloadopenshift-34ac7b11c72a4ef30a3c646271410578245cd582.tar.gz
openshift-34ac7b11c72a4ef30a3c646271410578245cd582.tar.bz2
openshift-34ac7b11c72a4ef30a3c646271410578245cd582.tar.xz
openshift-34ac7b11c72a4ef30a3c646271410578245cd582.zip
changed multi_ec2.py to print the json result string instead of the python pretty print string.
Diffstat (limited to 'inventory')
-rw-r--r--inventory/.gitignore2
-rwxr-xr-xinventory/multi_ec2.py19
2 files changed, 9 insertions, 12 deletions
diff --git a/inventory/.gitignore b/inventory/.gitignore
deleted file mode 100644
index 6b11bed20..000000000
--- a/inventory/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-multi_ec2.yaml
-*pyc
diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py
index 456bda8c8..1fe18a67e 100755
--- a/inventory/multi_ec2.py
+++ b/inventory/multi_ec2.py
@@ -17,7 +17,7 @@ class MultiEc2(object):
self.config = None
self.all_ec2_results = {}
self.result = {}
- self.cache_path_cache = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache')
+ self.cache_path = os.path.expanduser('~/.ansible/tmp/multi_ec2_inventory.cache')
self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
self.config_file = os.path.join(self.file_path,"multi_ec2.yaml")
self.parse_cli_args()
@@ -167,11 +167,10 @@ class MultiEc2(object):
def is_cache_valid(self):
''' Determines if the cache files have expired, or if it is still valid '''
- if os.path.isfile(self.cache_path_cache):
- mod_time = os.path.getmtime(self.cache_path_cache)
+ if os.path.isfile(self.cache_path):
+ mod_time = os.path.getmtime(self.cache_path)
current_time = time()
if (mod_time + self.config['cache_max_age']) > current_time:
- #if os.path.isfile(self.cache_path_index):
return True
return False
@@ -190,14 +189,14 @@ class MultiEc2(object):
''' Writes data in JSON format to a file '''
json_data = self.json_format_dict(self.result, True)
- with open(self.cache_path_cache, 'w') as cache:
+ with open(self.cache_path, 'w') as cache:
cache.write(json_data)
def get_inventory_from_cache(self):
''' Reads the inventory from the cache file and returns it as a JSON
object '''
- with open(self.cache_path_cache, 'r') as cache:
+ with open(self.cache_path, 'r') as cache:
self.result = json.loads(cache.read())
def json_format_dict(self, data, pretty=False):
@@ -209,10 +208,10 @@ class MultiEc2(object):
else:
return json.dumps(data)
+ def result_str(self):
+ return self.json_format_dict(self.result, True)
+
if __name__ == "__main__":
mi = MultiEc2()
- #print mi.result
- pp = pprint.PrettyPrinter(indent=2)
- pp.pprint(mi.result)
-
+ print mi.result_str()