summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSabari Kumar Murugesan <smurugesan@vmware.com>2015-03-13 15:20:10 -0700
committerSabari Kumar Murugesan <smurugesan@vmware.com>2015-03-27 14:52:36 -0700
commitf33fe43aba241cef2f4d326b1398bb2c8b472898 (patch)
treea3980a0cd1036819e1858999dbe115e7c306e1e4
parent4fba47890d421306d2160f5fda96385d801c52ae (diff)
downloadglance_store-f33fe43aba241cef2f4d326b1398bb2c8b472898.tar.gz
Handle optional dependency in vmware store
oslo_vmware is an optional dependency for glance_store. Hence, we should be able to register the store options even if the library is not installed. There are two problems addressed here :- 1. The import error was not handled. 2. One of the store opt referenced a constant from the library. Change-Id: I234a935f33e1cf8c3d6123994447bfca2365c3bb
-rw-r--r--glance_store/_drivers/vmware_datastore.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py
index f9cec61..3dbbc86 100644
--- a/glance_store/_drivers/vmware_datastore.py
+++ b/glance_store/_drivers/vmware_datastore.py
@@ -24,12 +24,14 @@ import socket
from oslo_config import cfg
from oslo_utils import excutils
from oslo_utils import units
-from oslo_vmware import api
-from oslo_vmware import constants
-import oslo_vmware.exceptions as vexc
-from oslo_vmware.objects import datacenter as oslo_datacenter
-from oslo_vmware.objects import datastore as oslo_datastore
-from oslo_vmware import vim_util
+try:
+ from oslo_vmware import api
+ import oslo_vmware.exceptions as vexc
+ from oslo_vmware.objects import datacenter as oslo_datacenter
+ from oslo_vmware.objects import datastore as oslo_datastore
+ from oslo_vmware import vim_util
+except ImportError:
+ api = None
import six
# NOTE(jokke): simplified transition to py3, behaves like py2 xrange
@@ -66,7 +68,7 @@ _VMWARE_OPTS = [
'VMware ESX/VC server.'),
secret=True),
cfg.StrOpt('vmware_datacenter_path',
- default=constants.ESX_DATACENTER_PATH,
+ default='ha-datacenter',
help=_('DEPRECATED. Inventory path to a datacenter. '
'If the vmware_server_host specified is an ESX/ESXi, '
'the vmware_datacenter_path is optional. If specified, '
@@ -320,6 +322,10 @@ class Store(glance_store.Store):
self.api_retry_count = self.conf.glance_store.vmware_api_retry_count
self.tpoll_interval = self.conf.glance_store.vmware_task_poll_interval
self.api_insecure = self.conf.glance_store.vmware_api_insecure
+ if api is None:
+ msg = _("Missing dependencies: oslo_vmware")
+ raise exceptions.BadStoreConfiguration(
+ store_name="vmware_datastore", reason=msg)
self.session = self.reset_session()
super(Store, self).configure()