Skip to content

Commit

Permalink
* Fix broken indentation in vmware inventory (ansible#16177)
Browse files Browse the repository at this point in the history
* Allow script to be a symlink without breaking ini path.
  • Loading branch information
jctanner committed Jun 7, 2016
1 parent f9803bf commit aa5c8ed
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions contrib/inventory/vmware_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def read_settings(self):

''' Reads the settings from the vmware_inventory.ini file '''

scriptbasename = os.path.realpath(__file__)
scriptbasename = __file__
scriptbasename = os.path.basename(scriptbasename)
scriptbasename = scriptbasename.replace('.py', '')

Expand All @@ -181,7 +181,7 @@ def read_settings(self):
'port': 443,
'username': '',
'password': '',
'ini_path': os.path.join(os.path.dirname(os.path.realpath(__file__)), '%s.ini' % scriptbasename),
'ini_path': os.path.join(os.path.dirname(__file__), '%s.ini' % scriptbasename),
'cache_name': 'ansible-vmware',
'cache_path': '~/.ansible/tmp',
'cache_max_age': 3600,
Expand Down Expand Up @@ -279,17 +279,14 @@ def get_instances(self):
context.verify_mode = ssl.CERT_NONE
kwargs['sslContext'] = context


self.debugl("### RUNNING WITHOUT VCR")
instances = self._get_instances(kwargs)

self.debugl("### INSTANCES RETRIEVED")
return instances


def _get_instances(self, inkwargs):

''' Make API calls without VCR fixtures '''
''' Make API calls '''

instances = []
si = SmartConnect(**inkwargs)
Expand Down Expand Up @@ -399,6 +396,7 @@ def instances_to_inventory(self, instances):
for hf in self.host_filters:
if not hf:
continue
self.debugl('FILTER: %s' % hf)
filter_map = self.create_template_mapping(inventory, hf, dtype='boolean')
for k,v in filter_map.iteritems():
if not v:
Expand Down Expand Up @@ -437,7 +435,9 @@ def create_template_mapping(self, inventory, pattern, dtype='string'):
except Exception as e:
self.debugl(str(e))
#import epdb; epdb.st()
if dtype == 'integer':
if not newkey:
continue
elif dtype == 'integer':
newkey = int(newkey)
elif dtype == 'boolean':
if newkey.lower() == 'false':
Expand Down Expand Up @@ -484,7 +484,7 @@ def facts_from_vobj(self, vobj, level=0):
if self.lowerkeys:
k = k.lower()

rdata[k] = self._process_object_types(v, level=level)
rdata[k] = self._process_object_types(v, level=level)

else:

Expand All @@ -511,7 +511,7 @@ def facts_from_vobj(self, vobj, level=0):
if self.lowerkeys:
method = method.lower()

rdata[method] = self._process_object_types(methodToCall, level=level)
rdata[method] = self._process_object_types(methodToCall, level=level)

return rdata

Expand Down Expand Up @@ -554,8 +554,7 @@ def _process_object_types(self, vobj, level=0):

if not rdata:
rdata = None
return rdata

return rdata

def get_host_info(self, host):

Expand Down

0 comments on commit aa5c8ed

Please sign in to comment.