mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-22 20:13:59 -07:00
Fix undefined variables, basestring usage, and some associated python3 issues
This commit is contained in:
parent
9f7b0dfc30
commit
225fa5d092
84 changed files with 652 additions and 963 deletions
|
@ -49,14 +49,16 @@ This script has been inspired by the cobbler.py inventory. thanks
|
|||
Author: Damien Garros (@dgarros)
|
||||
Version: 0.2.0
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
|
||||
try:
|
||||
import json
|
||||
import argparse
|
||||
HAS_ARGPARSE = True
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
HAS_ARGPARSE = False
|
||||
|
||||
try:
|
||||
from apstra.aosom.session import Session
|
||||
|
@ -292,6 +294,8 @@ class AosInventory(object):
|
|||
|
||||
if not HAS_AOS_PYEZ:
|
||||
raise Exception('aos-pyez is not installed. Please see details here: https://github.com/Apstra/aos-pyez')
|
||||
if not HAS_ARGPARSE:
|
||||
raise Exception('argparse is not installed. Please install the argparse library or upgrade to python-2.7')
|
||||
|
||||
# Initialize inventory
|
||||
self.inventory = dict() # A list of groups and the hosts in that group
|
||||
|
|
|
@ -170,9 +170,9 @@ from time import time
|
|||
|
||||
from ansible.constants import get_config
|
||||
from ansible.module_utils.parsing.convert_bool import boolean
|
||||
from ansible.module_utils.six import text_type
|
||||
|
||||
|
||||
NON_CALLABLES = (basestring, bool, dict, int, list, type(None))
|
||||
NON_CALLABLES = (text_type, str, bool, dict, int, list, type(None))
|
||||
|
||||
|
||||
def load_config_file():
|
||||
|
|
|
@ -38,9 +38,9 @@ import os
|
|||
import ssl
|
||||
import sys
|
||||
import time
|
||||
import ConfigParser
|
||||
|
||||
from six import text_type, string_types
|
||||
from six import integer_types, text_type, string_types
|
||||
from six.moves import configparser
|
||||
|
||||
# Disable logging message trigged by pSphere/suds.
|
||||
try:
|
||||
|
@ -64,7 +64,7 @@ from suds.sudsobject import Object as SudsObject
|
|||
class VMwareInventory(object):
|
||||
|
||||
def __init__(self, guests_only=None):
|
||||
self.config = ConfigParser.SafeConfigParser()
|
||||
self.config = configparser.SafeConfigParser()
|
||||
if os.environ.get('VMWARE_INI', ''):
|
||||
config_files = [os.environ['VMWARE_INI']]
|
||||
else:
|
||||
|
@ -210,7 +210,7 @@ class VMwareInventory(object):
|
|||
if obj_info != ():
|
||||
l.append(obj_info)
|
||||
return l
|
||||
elif isinstance(obj, (type(None), bool, int, long, float, string_types)):
|
||||
elif isinstance(obj, (type(None), bool, float) + string_types + integer_types):
|
||||
return obj
|
||||
else:
|
||||
return ()
|
||||
|
|
|
@ -23,22 +23,27 @@ $ jq '._meta.hostvars[].config' data.json | head
|
|||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import atexit
|
||||
import datetime
|
||||
import getpass
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import six
|
||||
import ssl
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
from collections import defaultdict
|
||||
from six.moves import configparser
|
||||
from time import time
|
||||
from jinja2 import Environment
|
||||
|
||||
import six
|
||||
from jinja2 import Environment
|
||||
from six import integer_types, string_types
|
||||
from six.moves import configparser
|
||||
|
||||
try:
|
||||
import argparse
|
||||
except ImportError:
|
||||
sys.exit('Error: This inventory script required "argparse" python module. Please install it or upgrade to python-2.7')
|
||||
|
||||
try:
|
||||
from pyVmomi import vim, vmodl
|
||||
|
@ -46,11 +51,6 @@ try:
|
|||
except ImportError:
|
||||
sys.exit("ERROR: This inventory script required 'pyVmomi' Python module, it was not able to load it")
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
hasvcr = False
|
||||
try:
|
||||
import vcr
|
||||
|
@ -97,10 +97,7 @@ class VMWareInventory(object):
|
|||
skip_keys = []
|
||||
groupby_patterns = []
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
safe_types = [int, bool, str, float, None]
|
||||
else:
|
||||
safe_types = [int, long, bool, str, float, None]
|
||||
safe_types = [bool, str, float, None] + list(integer_types)
|
||||
iter_types = [dict, list]
|
||||
|
||||
bad_types = ['Array', 'disabledMethod', 'declaredAlarmState']
|
||||
|
@ -489,7 +486,7 @@ class VMWareInventory(object):
|
|||
for k, v in inventory['_meta']['hostvars'].items():
|
||||
if 'customvalue' in v:
|
||||
for tv in v['customvalue']:
|
||||
if not isinstance(tv['value'], str) and not isinstance(tv['value'], unicode):
|
||||
if not isinstance(tv['value'], string_types):
|
||||
continue
|
||||
|
||||
newkey = None
|
||||
|
@ -665,12 +662,10 @@ class VMWareInventory(object):
|
|||
rdata = vobj.decode('ascii', 'ignore')
|
||||
elif issubclass(type(vobj), bool) or isinstance(vobj, bool):
|
||||
rdata = vobj
|
||||
elif issubclass(type(vobj), int) or isinstance(vobj, int):
|
||||
elif issubclass(type(vobj), integer_types) or isinstance(vobj, integer_types):
|
||||
rdata = vobj
|
||||
elif issubclass(type(vobj), float) or isinstance(vobj, float):
|
||||
rdata = vobj
|
||||
elif issubclass(type(vobj), long) or isinstance(vobj, long):
|
||||
rdata = vobj
|
||||
elif issubclass(type(vobj), list) or issubclass(type(vobj), tuple):
|
||||
rdata = []
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue