1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Correct overly broad import from chube in linode inventory script

Fixes #4875
This commit is contained in:
James Cammarata 2014-03-07 14:35:18 -06:00
parent b8f627d1d5
commit bf251e3dbf

View file

@ -71,21 +71,39 @@ just adapted that for Linode.
###################################################################### ######################################################################
# Standard imports # Standard imports
import os
import re import re
import sys import sys
import argparse import argparse
from time import time from time import time
try: try:
import json import json
except ImportError: except ImportError:
import simplejson as json import simplejson as json
# chube imports 'yaml', which is also the name of an inventory plugin, try:
# so we remove the plugins dir from sys.path before importing it. from chube import load_chube_config
from chube import api as chube_api
from chube.datacenter import Datacenter
from chube.linode_obj import Linode
except:
try:
# remove local paths and other stuff that may
# cause an import conflict, as chube is sensitive
# to name collisions on importing
old_path = sys.path old_path = sys.path
sys.path = [d for d in sys.path if "ansible/plugins" not in d] sys.path = [d for d in sys.path if d not in ('', os.getcwd(), os.path.dirname(os.path.realpath(__file__)))]
from chube import *
from chube import load_chube_config
from chube import api as chube_api
from chube.datacenter import Datacenter
from chube.linode_obj import Linode
sys.path = old_path sys.path = old_path
except Exception, e:
raise Exception("could not import chube")
load_chube_config() load_chube_config()
# Imports for ansible # Imports for ansible
@ -166,7 +184,7 @@ class LinodeInventory(object):
try: try:
for node in Linode.search(status=Linode.STATUS_RUNNING): for node in Linode.search(status=Linode.STATUS_RUNNING):
self.add_node(node) self.add_node(node)
except api.linode_api.ApiError, e: except chube_api.linode_api.ApiError, e:
print "Looks like Linode's API is down:" print "Looks like Linode's API is down:"
print print
print e print e
@ -176,7 +194,7 @@ class LinodeInventory(object):
"""Gets details about a specific node.""" """Gets details about a specific node."""
try: try:
return Linode.find(api_id=linode_id) return Linode.find(api_id=linode_id)
except api.linode_api.ApiError, e: except chube_api.linode_api.ApiError, e:
print "Looks like Linode's API is down:" print "Looks like Linode's API is down:"
print print
print e print e