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
|
# 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
|
||||||
old_path = sys.path
|
from chube import api as chube_api
|
||||||
sys.path = [d for d in sys.path if "ansible/plugins" not in d]
|
from chube.datacenter import Datacenter
|
||||||
from chube import *
|
from chube.linode_obj import Linode
|
||||||
sys.path = old_path
|
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()
|
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
|
||||||
|
|
Loading…
Reference in a new issue