mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 10:57:36 -02:30
Update vmware module from ansible
This commit is contained in:
@@ -28,6 +28,8 @@ take precedence over options present in the INI file. An INI file is not
|
|||||||
required if these options are specified using environment variables.
|
required if these options are specified using environment variables.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@@ -37,6 +39,8 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
|
from six import text_type
|
||||||
|
|
||||||
# Disable logging message trigged by pSphere/suds.
|
# Disable logging message trigged by pSphere/suds.
|
||||||
try:
|
try:
|
||||||
from logging import NullHandler
|
from logging import NullHandler
|
||||||
@@ -95,7 +99,7 @@ class VMwareInventory(object):
|
|||||||
Saves the value to cache with the name given.
|
Saves the value to cache with the name given.
|
||||||
'''
|
'''
|
||||||
if self.config.has_option('defaults', 'cache_dir'):
|
if self.config.has_option('defaults', 'cache_dir'):
|
||||||
cache_dir = self.config.get('defaults', 'cache_dir')
|
cache_dir = os.path.expanduser(self.config.get('defaults', 'cache_dir'))
|
||||||
if not os.path.exists(cache_dir):
|
if not os.path.exists(cache_dir):
|
||||||
os.makedirs(cache_dir)
|
os.makedirs(cache_dir)
|
||||||
cache_file = os.path.join(cache_dir, name)
|
cache_file = os.path.join(cache_dir, name)
|
||||||
@@ -115,7 +119,7 @@ class VMwareInventory(object):
|
|||||||
else:
|
else:
|
||||||
cache_max_age = 0
|
cache_max_age = 0
|
||||||
cache_stat = os.stat(cache_file)
|
cache_stat = os.stat(cache_file)
|
||||||
if (cache_stat.st_mtime + cache_max_age) < time.time():
|
if (cache_stat.st_mtime + cache_max_age) >= time.time():
|
||||||
with open(cache_file) as cache:
|
with open(cache_file) as cache:
|
||||||
return json.load(cache)
|
return json.load(cache)
|
||||||
return default
|
return default
|
||||||
@@ -147,7 +151,7 @@ class VMwareInventory(object):
|
|||||||
seen = seen or set()
|
seen = seen or set()
|
||||||
if isinstance(obj, ManagedObject):
|
if isinstance(obj, ManagedObject):
|
||||||
try:
|
try:
|
||||||
obj_unicode = unicode(getattr(obj, 'name'))
|
obj_unicode = text_type(getattr(obj, 'name'))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
obj_unicode = ()
|
obj_unicode = ()
|
||||||
if obj in seen:
|
if obj in seen:
|
||||||
@@ -164,7 +168,7 @@ class VMwareInventory(object):
|
|||||||
obj_info = self._get_obj_info(val, depth - 1, seen)
|
obj_info = self._get_obj_info(val, depth - 1, seen)
|
||||||
if obj_info != ():
|
if obj_info != ():
|
||||||
d[attr] = obj_info
|
d[attr] = obj_info
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
return d
|
return d
|
||||||
elif isinstance(obj, SudsObject):
|
elif isinstance(obj, SudsObject):
|
||||||
@@ -207,8 +211,8 @@ class VMwareInventory(object):
|
|||||||
host_info[k] = v
|
host_info[k] = v
|
||||||
try:
|
try:
|
||||||
host_info['ipAddress'] = host.config.network.vnic[0].spec.ip.ipAddress
|
host_info['ipAddress'] = host.config.network.vnic[0].spec.ip.ipAddress
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print >> sys.stderr, e
|
print(e, file=sys.stderr)
|
||||||
host_info = self._flatten_dict(host_info, prefix)
|
host_info = self._flatten_dict(host_info, prefix)
|
||||||
if ('%s_ipAddress' % prefix) in host_info:
|
if ('%s_ipAddress' % prefix) in host_info:
|
||||||
host_info['ansible_ssh_host'] = host_info['%s_ipAddress' % prefix]
|
host_info['ansible_ssh_host'] = host_info['%s_ipAddress' % prefix]
|
||||||
|
|||||||
Reference in New Issue
Block a user