summaryrefslogtreecommitdiff
path: root/oslo_vmware/objects
diff options
context:
space:
mode:
authorZhongcheng Lao <zlao@vmware.com>2017-05-16 11:52:02 +0800
committerZhongcheng Lao <zlao@vmware.com>2017-05-24 04:21:46 -0700
commit37f72b0db622e32bcebd86ee516a134dbd2eef9c (patch)
treeb1fc6033a422a3d2630c1786ab6a4ab86ae6560b /oslo_vmware/objects
parent37c3d53d5b9e16f6624f784a20d006f43b194d04 (diff)
downloadoslo-vmware-37f72b0db622e32bcebd86ee516a134dbd2eef9c.tar.gz
Make sure host in maintenance mode excluded from image upload
Currently when selecting host for image upload, hosts in maintenance mode will also be included. This commit adds a check for available hosts to make sure these hosts excluded from the list. Change-Id: I46e4a879245e4f9258178738da9920b34b65a187
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 cd89d4f..a0fca70 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]