Correct overly broad import from chube in linode inventory script
Fixes #4875
This commit is contained in:
parent
b8f627d1d5
commit
bf251e3dbf
1 changed files with 26 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue