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
import os
import re
import sys
import argparse
from time import time
try:
import json
except ImportError:
import simplejson as json
# chube imports 'yaml', which is also the name of an inventory plugin,
# so we remove the plugins dir from sys.path before importing it.
old_path = sys.path
sys.path = [d for d in sys.path if "ansible/plugins" not in d]
from chube import *
sys.path = old_path
try:
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
sys.path = [d for d in sys.path if d not in ('', os.getcwd(), os.path.dirname(os.path.realpath(__file__)))]
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
except Exception, e:
raise Exception("could not import chube")
load_chube_config()
# Imports for ansible
@ -166,7 +184,7 @@ class LinodeInventory(object):
try:
for node in Linode.search(status=Linode.STATUS_RUNNING):
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
print e
@ -176,7 +194,7 @@ class LinodeInventory(object):
"""Gets details about a specific node."""
try:
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
print e