Fix ec2.py dynamic inventory script when pulling down RDS cluster information (#48075)
* Fixes #26481 * Pass lint tests
This commit is contained in:
parent
fcc32bcf0e
commit
60378e991b
1 changed files with 10 additions and 9 deletions
|
@ -160,6 +160,7 @@ import argparse
|
||||||
import re
|
import re
|
||||||
from time import time
|
from time import time
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from datetime import date, datetime
|
||||||
import boto
|
import boto
|
||||||
from boto import ec2
|
from boto import ec2
|
||||||
from boto import rds
|
from boto import rds
|
||||||
|
@ -242,6 +243,13 @@ class Ec2Inventory(object):
|
||||||
def _empty_inventory(self):
|
def _empty_inventory(self):
|
||||||
return {"_meta": {"hostvars": {}}}
|
return {"_meta": {"hostvars": {}}}
|
||||||
|
|
||||||
|
def _json_serial(self, obj):
|
||||||
|
"""JSON serializer for objects not serializable by default json code"""
|
||||||
|
|
||||||
|
if isinstance(obj, (datetime, date)):
|
||||||
|
return obj.isoformat()
|
||||||
|
raise TypeError("Type %s not serializable" % type(obj))
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
''' Main execution path '''
|
''' Main execution path '''
|
||||||
|
|
||||||
|
@ -728,13 +736,6 @@ class Ec2Inventory(object):
|
||||||
account_id = boto.connect_iam().get_user().arn.split(':')[4]
|
account_id = boto.connect_iam().get_user().arn.split(':')[4]
|
||||||
c_dict = {}
|
c_dict = {}
|
||||||
for c in clusters:
|
for c in clusters:
|
||||||
# remove these datetime objects as there is no serialisation to json
|
|
||||||
# currently in place and we don't need the data yet
|
|
||||||
if 'EarliestRestorableTime' in c:
|
|
||||||
del c['EarliestRestorableTime']
|
|
||||||
if 'LatestRestorableTime' in c:
|
|
||||||
del c['LatestRestorableTime']
|
|
||||||
|
|
||||||
if not self.ec2_instance_filters:
|
if not self.ec2_instance_filters:
|
||||||
matches_filter = True
|
matches_filter = True
|
||||||
else:
|
else:
|
||||||
|
@ -1701,9 +1702,9 @@ class Ec2Inventory(object):
|
||||||
string '''
|
string '''
|
||||||
|
|
||||||
if pretty:
|
if pretty:
|
||||||
return json.dumps(data, sort_keys=True, indent=2)
|
return json.dumps(data, sort_keys=True, indent=2, default=self._json_serial)
|
||||||
else:
|
else:
|
||||||
return json.dumps(data)
|
return json.dumps(data, default=self._json_serial)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue