示例#1
0
    def test_nexussvibinding_get(self):
        npbr1 = self._npb_test_obj("router", 100)
        npb21 = self._npb_test_obj(20, 100)
        self._add_to_db([npbr1, npb21])

        npb_svi = nxdb.get_nexussvi_bindings()
        self.assertEqual(len(npb_svi), 1)
        self._assert_equal(npb_svi[0], npbr1)

        npbr2 = self._npb_test_obj("router", 200)
        self._add_to_db([npbr2])
        npb_svi = nxdb.get_nexussvi_bindings()
        self.assertEqual(len(npb_svi), 2)
    def test_nexussvibinding_get(self):
        npbr1 = self._npb_test_obj('router', 100)
        npb21 = self._npb_test_obj(20, 100)
        self._add_to_db([npbr1, npb21])

        npb_svi = nxdb.get_nexussvi_bindings()
        self.assertEqual(len(npb_svi), 1)
        self._assert_equal(npb_svi[0], npbr1)

        npbr2 = self._npb_test_obj('router', 200)
        self._add_to_db([npbr2])
        npb_svi = nxdb.get_nexussvi_bindings()
        self.assertEqual(len(npb_svi), 2)
示例#3
0
    def _find_switch_for_svi(self):
        """Get a switch to create the SVI on."""
        LOG.debug(_("Grabbing a switch to create SVI"))
        nexus_switches = self._client.nexus_switches
        if conf.CISCO.svi_round_robin:
            LOG.debug(_("Using round robin to create SVI"))
            switch_dict = dict(
                (switch_ip, 0) for switch_ip, _ in nexus_switches)
            try:
                bindings = nxos_db.get_nexussvi_bindings()
                # Build a switch dictionary with weights
                for binding in bindings:
                    switch_ip = binding.switch_ip
                    if switch_ip not in switch_dict:
                        switch_dict[switch_ip] = 1
                    else:
                        switch_dict[switch_ip] += 1
                # Search for the lowest value in the dict
                if switch_dict:
                    switch_ip = min(switch_dict.items(), key=switch_dict.get)
                    return switch_ip[0]
            except cisco_exc.NexusPortBindingNotFound:
                pass

        LOG.debug(_("No round robin or zero weights, using first switch"))
        # Return the first switch in the config
        for switch_ip, attr in nexus_switches:
            return switch_ip
    def _find_switch_for_svi(self):
        """Get a switch to create the SVI on."""
        LOG.debug(_("Grabbing a switch to create SVI"))
        nexus_switches = self._client.nexus_switches
        if conf.CISCO.svi_round_robin:
            LOG.debug(_("Using round robin to create SVI"))
            switch_dict = dict(
                (switch_ip, 0) for switch_ip, _ in nexus_switches)
            try:
                bindings = nxos_db.get_nexussvi_bindings()
                # Build a switch dictionary with weights
                for binding in bindings:
                    switch_ip = binding.switch_ip
                    if switch_ip not in switch_dict:
                        switch_dict[switch_ip] = 1
                    else:
                        switch_dict[switch_ip] += 1
                # Search for the lowest value in the dict
                if switch_dict:
                    switch_ip = min(switch_dict.items(), key=switch_dict.get)
                    return switch_ip[0]
            except cisco_exc.NexusPortBindingNotFound:
                pass

        LOG.debug(_("No round robin or zero weights, using first switch"))
        # Return the first switch in the config
        for switch_ip, attr in nexus_switches:
            return switch_ip