コード例 #1
0
    def _link_default_netpartition(self, netpart_name, l2template, l3template,
                                   l3isolated, l3shared):
        params = {
            'name': netpart_name,
            'l3template': l3template,
            'l2template': l2template
        }
        (np_id, l3dom_tid,
         l2dom_tid) = self.vsdclient.link_default_netpartition(params)
        # verify that the provided zones have been created already
        shared_match, isolated_match = self.vsdclient.validate_zone_create(
            l3dom_tid, l3isolated, l3shared)
        if not shared_match or not isolated_match:
            msg = ('Default zone names must be provided for '
                   'default net-partiton')
            raise n_exc.BadRequest(resource='net_partition', msg=msg)

        # basic verifications passed. add default netpartition to the DB
        session = lib_db_api.get_writer_session()
        netpartition = nuagedb.get_net_partition_by_name(session, netpart_name)

        with session.begin():
            if netpartition:
                nuagedb.delete_net_partition(session, netpartition)
            nuagedb.add_net_partition(session, np_id, l3dom_tid, l2dom_tid,
                                      netpart_name, l3isolated, l3shared)
        self._default_np_id = np_id
コード例 #2
0
    def _validate_create_net_partition(self, context, net_part_name):
        """Sync net partition configuration between plugin and VSD"""
        # About parallelism: This method could be executed in parallel
        # by different neutron instances. The decorator
        # retry_if_session_inactive makes sure that that the method will be
        # retried when database transaction errors occur like deadlock and
        # duplicate inserts.
        self._validate_net_partition_name(net_part_name)
        session = context.session
        with session.begin(subtransactions=True):
            netpart_db = nuagedb.get_net_partition_by_name(
                session, net_part_name)
            nuage_netpart = self.vsdclient.get_netpartition_data(net_part_name)
            if nuage_netpart:
                if netpart_db:
                    # Net-partition exists in neutron and vsd
                    def_netpart = (
                        cfg.CONF.RESTPROXY.default_net_partition_name)
                    share_netpart = constants.SHARED_INFRASTRUCTURE
                    if (def_netpart == net_part_name
                            or share_netpart == net_part_name):
                        if nuage_netpart['np_id'] != netpart_db['id']:
                            msg = ("Net-partition %s exists in "
                                   "Neutron and VSD, but the id is different" %
                                   net_part_name)
                            raise n_exc.BadRequest(resource='net_partition',
                                                   msg=msg)
                        self._update_net_partition(session, net_part_name,
                                                   netpart_db, nuage_netpart)
                        LOG.info(
                            "Net-partition %s already exists,"
                            " so will just use it", net_part_name)
                        return self._make_net_partition_dict(netpart_db)
                    else:
                        if nuage_netpart['np_id'] != netpart_db['id']:
                            msg = (('Net-partition %s already exists in '
                                    'Neutron and VSD, but the id is '
                                    'different') % net_part_name)
                        else:
                            msg = (('Net-partition %s already exists in '
                                    'Neutron and VSD with same id') %
                                   net_part_name)

                        raise n_exc.BadRequest(resource='net_partition',
                                               msg=msg)

                # Net-partition exists in vsd and not in neutron
                netpart_db = NuageApi._add_net_partition(
                    session, nuage_netpart, net_part_name)
                return self._make_net_partition_dict(netpart_db)
            else:
                if netpart_db:
                    # Net-partition exists in neutron and not VSD
                    LOG.info(
                        "Existing net-partition %s will be deleted and "
                        "re-created in db", net_part_name)
                    nuagedb.delete_net_partition(session, netpart_db)

                # Net-partition does not exist in neutron and VSD
                return self._create_net_partition(session, net_part_name)
コード例 #3
0
 def _get_default_net_partition(self, context):
     def_net_part = cfg.CONF.RESTPROXY.default_net_partition_name
     net_partition = nuagedb.get_net_partition_by_name(
         context.session, def_net_part)
     if not net_partition:
         msg = _("Default net_partition is not created at the start")
         raise n_exc.BadRequest(resource='netpartition', msg=msg)
     return net_partition
コード例 #4
0
 def __init__(self):
     super(NuageFWaaSPlugin, self).__init__()
     from neutron.api import extensions as neutron_extensions
     from neutron_fwaas import extensions
     neutron_extensions.append_api_extensions_path(extensions.__path__)
     self.agent_rpc = NuageNoOpAgent()
     enterprise_name = cfg.CONF.RESTPROXY.default_net_partition_name
     netpart_db = nuagedb.get_net_partition_by_name(db_api.get_session(),
                                                    enterprise_name)
     self.enterprise_id = netpart_db.id
コード例 #5
0
 def __init__(self):
     super(NuageFWaaSPlugin, self).__init__()
     from neutron.api import extensions as neutron_extensions
     from neutron_fwaas import extensions
     neutron_extensions.append_api_extensions_path(extensions.__path__)
     self.agent_rpc = NuageNoOpAgent()
     enterprise_name = cfg.CONF.RESTPROXY.default_net_partition_name
     netpart_db = nuagedb.get_net_partition_by_name(db_api.get_session(),
                                                    enterprise_name)
     self.enterprise_id = netpart_db.id
コード例 #6
0
    def _validate_create_net_partition(self, net_part_name, session):
        nuage_netpart = self.vsdclient.get_netpartition_data(net_part_name)
        netpart_db = nuagedb.get_net_partition_by_name(session, net_part_name)

        if nuage_netpart:
            with session.begin(subtransactions=True):
                if netpart_db:
                    # Net-partition exists in neutron and vsd
                    def_netpart = (
                        cfg.CONF.RESTPROXY.default_net_partition_name)
                    if def_netpart == net_part_name:
                        if nuage_netpart['np_id'] != netpart_db['id']:
                            msg = ("Default net-partition %s exists in "
                                   "Neutron and VSD, but the id is different" %
                                   net_part_name)
                            raise n_exc.BadRequest(resource='net_partition',
                                                   msg=msg)
                        self._update_net_partition(session, netpart_db,
                                                   nuage_netpart)
                        LOG.info("Default net-partition %s already exists,"
                                 " so will just use it" % net_part_name)
                        return self._make_net_partition_dict(netpart_db)
                    else:
                        if nuage_netpart['np_id'] != netpart_db['id']:
                            msg = (('Net-partition %s already exists in '
                                    'Neutron and VSD, but the id is '
                                    'different') % net_part_name)
                        else:
                            msg = (('Net-partition %s already exists in '
                                    'Neutron and VSD with same id') %
                                   net_part_name)

                        raise n_exc.BadRequest(resource='net_partition',
                                               msg=msg)

                # Net-partition exists in vsd and not in neutron
                netpart_db = NuageApi._add_net_partition(
                    session, nuage_netpart, net_part_name)
                return self._make_net_partition_dict(netpart_db)
        else:

            if netpart_db:
                # Net-partition exists in neutron and not VSD
                LOG.info(
                    "Existing net-partition %s will be deleted and "
                    "re-created in db", net_part_name)
                nuagedb.delete_net_partition(session, netpart_db)

            # Net-partition does not exist in neutron and VSD
            return self._create_net_partition(session, net_part_name)
コード例 #7
0
 def _validate_net_partition(self, subnet, db_context):
     netpartition_db = nuagedb.get_net_partition_by_name(
         db_context.session, subnet['net_partition'])
     netpartition = self.nuageclient.get_netpartition_by_name(
         subnet['net_partition'])
     require(netpartition, "netpartition", subnet['net_partition'])
     if netpartition_db:
         if netpartition_db['id'] != netpartition['id']:
             net_partdb = nuagedb.get_net_partition_with_lock(
                 db_context.session, netpartition_db['id'])
             nuagedb.delete_net_partition(db_context.session, net_partdb)
             self._add_net_partition(db_context.session, netpartition)
     else:
         self._add_net_partition(db_context.session, netpartition)
     return netpartition['id']
コード例 #8
0
 def _get_netpartition_from_db(session, np_id_or_name):
     return (nuagedb.get_net_partition_by_id(session, np_id_or_name)
             or nuagedb.get_net_partition_by_name(session, np_id_or_name))