Ejemplo n.º 1
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 not 'multi_lswitch' 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)
Ejemplo n.º 2
0
    def create_network(self, context, network):
        """
        :returns: a sequence of mappings with the following signature:
                    {'id': UUID representing the network.
                     'name': Human-readable name identifying the network.
                     'tenant_id': Owner of network. only admin user
                                  can specify a tenant_id other than its own.
                     'admin_state_up': Sets admin state of network. if down,
                                       network does not forward packets.
                     'status': Indicates whether network is currently
                               operational (limit values to "ACTIVE", "DOWN",
                               "BUILD", and "ERROR"?
                     'subnets': Subnets associated with this network. Plan
                                to allow fully specified subnets as part of
                                network create.
                   }
        :raises: exception.NoImplementedError
        """
        net_data = network['network'].copy()
        # Process the provider network extension
        self._handle_provider_create(context, net_data)
        # Replace ATTR_NOT_SPECIFIED with None before sending to NVP
        for attr, value in network['network'].iteritems():
            if value == attributes.ATTR_NOT_SPECIFIED:
                net_data[attr] = None
        # FIXME(arosen) implement admin_state_up = False in NVP
        if net_data['admin_state_up'] is False:
            LOG.warning(_("Network with admin_state_up=False are not yet "
                          "supported by this plugin. Ignoring setting for "
                          "network %s") % net_data.get('name', '<unknown>'))
        tenant_id = self._get_tenant_id_for_create(context, net_data)
        target_cluster = self._find_target_cluster(net_data)
        lswitch = nvplib.create_lswitch(target_cluster,
                                        tenant_id,
                                        net_data.get('name'),
                                        net_data.get(pnet.NETWORK_TYPE),
                                        net_data.get(pnet.PHYSICAL_NETWORK),
                                        net_data.get(pnet.SEGMENTATION_ID))
        network['network']['id'] = lswitch['uuid']

        with context.session.begin(subtransactions=True):
            new_net = super(NvpPluginV2, self).create_network(context,
                                                              network)
            if net_data.get(pnet.NETWORK_TYPE):
                net_binding = nicira_db.add_network_binding(
                    context.session, new_net['id'],
                    net_data.get(pnet.NETWORK_TYPE),
                    net_data.get(pnet.PHYSICAL_NETWORK),
                    net_data.get(pnet.SEGMENTATION_ID))
                self._extend_network_dict_provider(context, new_net,
                                                   net_binding)
        return new_net