summaryrefslogtreecommitdiff
path: root/oslo_vmware/objects
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-28 08:33:07 +0000
committerGerrit Code Review <review@openstack.org>2017-06-28 08:33:07 +0000
commit5b01c09e86cefddcee90ed31735e17e8261a81e5 (patch)
treebd90ee4c86f2eb98e3298117835e8486d040b857 /oslo_vmware/objects
parentc48eefee76813c1d2ab10cf1dddb2b57b34c60d0 (diff)
parent37f72b0db622e32bcebd86ee516a134dbd2eef9c (diff)
downloadoslo-vmware-5b01c09e86cefddcee90ed31735e17e8261a81e5.tar.gz
Merge "Make sure host in maintenance mode excluded from image upload"2.22.0
Diffstat (limited to 'oslo_vmware/objects')
-rw-r--r--oslo_vmware/objects/datastore.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/oslo_vmware/objects/datastore.py b/oslo_vmware/objects/datastore.py
index f61a589..2966352 100644
--- a/oslo_vmware/objects/datastore.py
+++ b/oslo_vmware/objects/datastore.py
@@ -142,7 +142,19 @@ class Datastore(object):
for host_mount in host_mounts.DatastoreHostMount:
if self.is_datastore_mount_usable(host_mount.mountInfo):
hosts.append(host_mount.key)
- return hosts
+ connectables = []
+ if hosts:
+ host_runtimes = session.invoke_api(
+ vim_util,
+ 'get_properties_for_a_collection_of_objects',
+ session.vim, 'HostSystem', hosts, ['runtime'])
+ for host_object in host_runtimes.objects:
+ host_props = vim_util.propset_dict(host_object.propSet)
+ host_runtime = host_props.get('runtime')
+ if hasattr(host_runtime, 'inMaintenanceMode') and (
+ not host_runtime.inMaintenanceMode):
+ connectables.append(host_object.obj)
+ return connectables
@staticmethod
def is_datastore_mount_usable(mount_info):
@@ -162,6 +174,9 @@ class Datastore(object):
@staticmethod
def choose_host(hosts):
+ if not hosts:
+ return None
+
i = random.SystemRandom().randrange(0, len(hosts))
return hosts[i]