Пример #1
0
    def get_network(self, context, id, fields=None):
        with context.session.begin(subtransactions=True):
            network = self._get_network(context, id)
            net_result = self._make_network_dict(network, None)
            self._extend_network_dict_provider(context, net_result)
            self._extend_network_port_security_dict(context, net_result)

        # verify the fabric status of the corresponding
        # logical switch(es) in nvp
        try:
            # FIXME(salvatore-orlando): This is not going to work unless
            # nova_id is stored in db once multiple clusters are enabled
            cluster = self._find_target_cluster(network)
            # Returns multiple lswitches if provider network.
            lswitches = nvplib.get_lswitches(cluster, id)
            for lswitch in lswitches:
                lswitch_status = (lswitch['_relations']['LogicalSwitchStatus']
                                  ['fabric_status'])
                if not lswitch_status:
                    net_result['status'] = constants.NET_STATUS_DOWN
                    break
            else:
                net_result['status'] = constants.NET_STATUS_ACTIVE
        except Exception:
            err_msg = _("Unable to get lswitches")
            LOG.exception(err_msg)
            raise nvp_exc.NvpPluginException(err_msg=err_msg)

        # Don't do field selection here otherwise we won't be able
        # to add provider networks fields
        return self._fields(net_result, fields)
Пример #2
0
 def _handle_lswitch_selection(self, cluster, network,
                               network_binding, max_ports,
                               allow_extra_lswitches):
     lswitches = nvplib.get_lswitches(cluster, network.id)
     try:
         # TODO find main_ls too!
         return [ls for ls in lswitches
                 if (ls['_relations']['LogicalSwitchStatus']
                     ['lport_count'] < max_ports)].pop(0)
     except IndexError:
         # Too bad, no switch available
         LOG.debug(_("No switch has available ports (%d checked)"),
                   len(lswitches))
     if allow_extra_lswitches:
         main_ls = [ls for ls in lswitches if ls['uuid'] == network.id]
         tag_dict = dict((x['scope'], x['tag']) for x in main_ls[0]['tags'])
         if 'multi_lswitch' not in tag_dict:
             nvplib.update_lswitch(cluster,
                                   main_ls[0]['uuid'],
                                   main_ls[0]['display_name'],
                                   network['tenant_id'],
                                   tags=[{'tag': 'True',
                                          'scope': 'multi_lswitch'}])
         selected_lswitch = nvplib.create_lswitch(
             cluster, network.tenant_id,
             "%s-ext-%s" % (network.name, len(lswitches)),
             network_binding.binding_type,
             network_binding.tz_uuid,
             network_binding.vlan_id,
             network.id)
         return selected_lswitch
     else:
         LOG.error(_("Maximum number of logical ports reached for "
                     "logical network %s"), network.id)
         raise nvp_exc.NvpNoMorePortsException(network=network.id)
Пример #3
0
 def test_exhaust_ports_bridged_network(self):
     cfg.CONF.set_override('max_lp_per_bridged_ls', 1, group="NVP")
     providernet_args = {pnet.NETWORK_TYPE: 'flat',
                         pnet.PHYSICAL_NETWORK: 'tzuuid'}
     with self.network(name='testnet',
                       providernet_args=providernet_args,
                       arg_list=(pnet.NETWORK_TYPE,
                                 pnet.PHYSICAL_NETWORK,
                                 pnet.SEGMENTATION_ID)) as net:
         with self.subnet(network=net) as sub:
             with self.port(subnet=sub):
                 with self.port(subnet=sub):
                     plugin = manager.QuantumManager.get_plugin()
                     ls = nvplib.get_lswitches(plugin.default_cluster,
                                               net['network']['id'])
                     self.assertEqual(len(ls), 2)
Пример #4
0
 def _get_lswitch_cluster_pairs(self, netw_id, tenant_id):
     """Figure out the set of lswitches on each cluster that maps to this
        network id"""
     pairs = []
     for c in self.clusters.itervalues():
         lswitches = []
         try:
             results = nvplib.get_lswitches(c, netw_id)
             lswitches.extend([ls['uuid'] for ls in results])
         except q_exc.NetworkNotFound:
             continue
         pairs.append((c, lswitches))
     if len(pairs) == 0:
         raise q_exc.NetworkNotFound(net_id=netw_id)
     LOG.debug(_("Returning pairs for network: %s"), pairs)
     return pairs
Пример #5
0
 def test_exhaust_ports_bridged_network(self):
     cfg.CONF.set_override('max_lp_per_bridged_ls', 1, group="NVP")
     providernet_args = {
         pnet.NETWORK_TYPE: 'flat',
         pnet.PHYSICAL_NETWORK: 'tzuuid'
     }
     with self.network(name='testnet',
                       providernet_args=providernet_args,
                       arg_list=(pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK,
                                 pnet.SEGMENTATION_ID)) as net:
         with self.subnet(network=net) as sub:
             with self.port(subnet=sub):
                 with self.port(subnet=sub):
                     plugin = manager.QuantumManager.get_plugin()
                     ls = nvplib.get_lswitches(plugin.default_cluster,
                                               net['network']['id'])
                     self.assertEqual(len(ls), 2)