Exemplo 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)
Exemplo n.º 2
0
    def update_network(self, context, id, network):
        """
        Updates the properties of a particular Virtual 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.NetworkNotFound
        :raises: exception.NoImplementedError
        """

        if network["network"].get("admin_state_up"):
            if network['network']["admin_state_up"] is False:
                raise q_exc.NotImplementedError(_("admin_state_up=False "
                                                  "networks are not "
                                                  "supported."))
        params = {}
        params["network"] = network["network"]
        pairs = self._get_lswitch_cluster_pairs(id, context.tenant_id)

        #Only field to update in NVP is name
        if network['network'].get("name"):
            for (cluster, switches) in pairs:
                for switch in switches:
                    nvplib.update_lswitch(cluster, switch,
                                          network['network']['name'])

        LOG.debug(_("update_network() completed for tenant: %s"),
                  context.tenant_id)
        return super(NvpPluginV2, self).update_network(context, id, network)