Example #1
0
def is_valid_dvswitch(session, cluster_mor, dvs_name):
    """
       Check if DVS is present for the cluster specified in conf.
       Also validate if DVS is attached to all the hosts in the 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(_("DVS not present on host %s") % host.value)
                        return
            return hosts_in_cluster
    else:
        LOG.error(_("Switch not present"))
 def test_get_host_mors_for_cluster_exc(self):
     vim_exc = error_util.VimException("Session closed",
                                       Exception("Session error"))
     with mock.patch.object(self.session, "_call_method",
                            side_effect=vim_exc):
         host_mor = resource_util.get_host_mors_for_cluster(self.session,
                                                            None)
         self.assertFalse(host_mor)
 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)