Fixed importing the libcloud modules to give a nice error rather than a traceback.

This commit is contained in:
Toshio Kuratomi 2016-05-12 09:13:46 -07:00
parent 151df71464
commit 8cd0c432e7

View file

@ -30,18 +30,24 @@
import json import json
import os import os
import traceback import traceback
from libcloud.compute.types import Provider
from distutils.version import LooseVersion from distutils.version import LooseVersion
try:
from libcloud.compute.types import Provider
import libcloud import libcloud
from libcloud.compute.providers import get_driver from libcloud.compute.providers import get_driver
HAS_LIBCLOUD_BASE = True
except ImportError:
HAS_LIBCLOUD_BASE = False
USER_AGENT_PRODUCT="Ansible-gce" USER_AGENT_PRODUCT="Ansible-gce"
USER_AGENT_VERSION="v1" USER_AGENT_VERSION="v1"
def gce_connect(module, provider=None): def gce_connect(module, provider=None):
"""Return a Google Cloud Engine connection.""" """Return a Google Cloud Engine connection."""
if not HAS_LIBCLOUD_BASE:
module.fail_json(msg='libcloud must be installed to use this module')
service_account_email = module.params.get('service_account_email', None) service_account_email = module.params.get('service_account_email', None)
credentials_file = module.params.get('credentials_file', None) credentials_file = module.params.get('credentials_file', None)
pem_file = module.params.get('pem_file', None) pem_file = module.params.get('pem_file', None)