def is_valid_dvswitch(session, cluster_mor, dvs_name): """Validate a DVS. Check if DVS exists for a cluster specified in conf. Also validate if DVS is attached to all hosts in a cluster. """ dvs_mor = get_dvs_mor_by_name(session, dvs_name) if dvs_mor: dvs_config = session._call_method( vim_util, "get_dynamic_property", dvs_mor, "DistributedVirtualSwitch", "config.host") # Get all the host attached to given VDS dvs_host_members = dvs_config[0] dvs_attached_host_ids = [] for dvs_host_member in dvs_host_members: dvs_attached_host_ids.append(dvs_host_member.config.host.value) # Get all the hosts present in the cluster hosts_in_cluster = resource_util.get_host_mors_for_cluster( session, cluster_mor) # Check if the host on which OVSvApp VM is hosted is a part of DVSwitch if hosts_in_cluster: for host in hosts_in_cluster: hostname = resource_util.get_hostname_for_host_mor( session, host) if hostname == cfg.CONF.VMWARE.esx_hostname: if host.value not in dvs_attached_host_ids: LOG.error(_LE("DVS not present on" "host %s"), host.value) return False return hosts_in_cluster else: LOG.error(_LE("DVS not present %s"), dvs_name) return False
def test_get_host_mors_for_cluster(self): cluster_mor = resource_util.get_cluster_mor_for_vm( self.session, fake_vmware_api.Constants.VM_UUID) self.assertTrue(cluster_mor) host_mor = resource_util.get_host_mors_for_cluster( self.session, cluster_mor) self.assertTrue(host_mor) self.assertTrue(isinstance(host_mor, list))
def test_get_host_mors_for_cluster_with_invalid_mor(self): host_mor = resource_util.get_host_mors_for_cluster(self.session, None) self.assertFalse(host_mor)