Return None if no suitable datastore is found

In the case of a datastore cluster, if no datastor is found then
return None. Do not fail on a key exception for accessing a field
that does not exist

Change-Id: I036f8022e2b9f454f7cd10846b408153a18b7b60
This commit is contained in:
Gary Kotton 2019-03-03 06:52:30 -08:00
parent 507afb25b1
commit 009c5e3bfe
1 changed files with 3 additions and 0 deletions

View File

@ -61,6 +61,9 @@ def get_recommended_datastore(session, sp_spec):
"RecommendDatastores",
session.vim.service_content.storageResourceManager,
storageSpec=sp_spec)
if not hasattr(spr, 'recommendations'):
LOG.error("Unable to find suitable datastore")
return
return spr.recommendations[0].key