'tenant_id' field is deprecated
see : https://specs.openstack.org/openstack/neutron-specs/specs/newton/moving-to-keystone-v3.html and https://developer.openstack.org/api-ref/network/v2/index.html#api-guide Change-Id: Iab6d8ba2d8724b20a1cd4fc910f87147201aef2f
This commit is contained in:
parent
16b0445a1c
commit
46f37ad7ee
@ -40,6 +40,13 @@ LOG = logging.getLogger(__name__)
|
||||
ETCDIR = '/etc/neutron'
|
||||
|
||||
|
||||
def get_obj_topic(obj):
|
||||
topic = obj.get('project_id')
|
||||
if topic is None:
|
||||
topic = obj['tenant_id']
|
||||
return topic
|
||||
|
||||
|
||||
def etcdir(*p):
|
||||
return os.path.join(ETCDIR, *p)
|
||||
|
||||
|
@ -18,6 +18,7 @@ from neutron_lib.api import validators
|
||||
from neutron_lib import exceptions as n_exc
|
||||
|
||||
from dragonflow.common import constants as const
|
||||
from dragonflow.common import utils
|
||||
from dragonflow.db.models import l2
|
||||
from dragonflow.neutron.common import constants as df_const
|
||||
from dragonflow.neutron.common import dhcp_opt_map as opt_map
|
||||
@ -26,7 +27,7 @@ from dragonflow.neutron.common import dhcp_opt_map as opt_map
|
||||
def logical_switch_from_neutron_network(network):
|
||||
return l2.LogicalSwitch(
|
||||
id=network['id'],
|
||||
topic=network['tenant_id'],
|
||||
topic=utils.get_obj_topic(network),
|
||||
name=network.get('name'),
|
||||
network_type=network.get('provider:network_type'),
|
||||
physical_network=network.get('provider:physical_network'),
|
||||
@ -40,7 +41,7 @@ def logical_switch_from_neutron_network(network):
|
||||
def subnet_from_neutron_subnet(subnet):
|
||||
return l2.Subnet(
|
||||
id=subnet['id'],
|
||||
topic=subnet['tenant_id'],
|
||||
topic=utils.get_obj_topic(subnet),
|
||||
name=subnet.get('name'),
|
||||
enable_dhcp=subnet['enable_dhcp'],
|
||||
cidr=subnet['cidr'],
|
||||
@ -123,7 +124,7 @@ def logical_port_from_neutron_port(port):
|
||||
return l2.LogicalPort(
|
||||
id=port['id'],
|
||||
lswitch=port['network_id'],
|
||||
topic=port['tenant_id'],
|
||||
topic=utils.get_obj_topic(port),
|
||||
macs=[port['mac_address']],
|
||||
ips=[ip['ip_address'] for ip in port.get('fixed_ips', [])],
|
||||
subnets=[ip['subnet_id'] for ip in port.get('fixed_ips', [])],
|
||||
|
@ -10,13 +10,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from dragonflow.common import utils
|
||||
from dragonflow.db.models import l3
|
||||
|
||||
|
||||
def logical_router_from_neutron_router(router):
|
||||
return l3.LogicalRouter(
|
||||
id=router['id'],
|
||||
topic=router['tenant_id'],
|
||||
topic=utils.get_obj_topic(router),
|
||||
name=router.get('name'),
|
||||
version=router['revision_number'],
|
||||
routes=router.get('routes', []))
|
||||
@ -25,7 +26,7 @@ def logical_router_from_neutron_router(router):
|
||||
def build_logical_router_port(router_port_info, mac, network, unique_key):
|
||||
return l3.LogicalRouterPort(
|
||||
id=router_port_info['port_id'],
|
||||
topic=router_port_info['tenant_id'],
|
||||
topic=utils.get_obj_topic(router_port_info),
|
||||
lswitch=router_port_info['network_id'],
|
||||
mac=mac,
|
||||
network=network,
|
||||
@ -35,7 +36,7 @@ def build_logical_router_port(router_port_info, mac, network, unique_key):
|
||||
def build_floating_ip_from_neutron_floating_ip(floating_ip):
|
||||
return l3.FloatingIp(
|
||||
id=floating_ip['id'],
|
||||
topic=floating_ip['tenant_id'],
|
||||
topic=utils.get_obj_topic(floating_ip),
|
||||
name=floating_ip.get('name'),
|
||||
version=floating_ip['revision_number'],
|
||||
lrouter=floating_ip.get('router_id', None),
|
||||
|
@ -15,6 +15,7 @@ import copy
|
||||
from neutron.extensions import securitygroup as sg
|
||||
from neutron_lib import constants as n_const
|
||||
|
||||
from dragonflow.common import utils as df_utils
|
||||
from dragonflow.db.models import secgroups
|
||||
|
||||
|
||||
@ -52,9 +53,10 @@ def security_group_from_neutron_obj(secgroup):
|
||||
sg_name = secgroup.get('name')
|
||||
rules = secgroup.get('security_group_rules', [])
|
||||
rules_mdls = [security_group_rule_from_neutron_obj(rule) for rule in rules]
|
||||
topic = df_utils.get_obj_topic(secgroup)
|
||||
return secgroups.SecurityGroup(
|
||||
id=secgroup['id'],
|
||||
topic=secgroup['tenant_id'],
|
||||
topic=topic,
|
||||
name=sg_name,
|
||||
rules=rules_mdls,
|
||||
version=secgroup['revision_number'])
|
||||
|
@ -20,6 +20,8 @@ from neutron_lib import constants as n_const
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_log import log
|
||||
|
||||
from dragonflow.common import utils as df_utils
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@ -74,7 +76,9 @@ class DFDHCPModule(object):
|
||||
return None
|
||||
|
||||
def _create_dhcp_port(self, context, subnet):
|
||||
port = {'port': {'tenant_id': subnet['tenant_id'],
|
||||
subnet_project = df_utils.get_obj_topic(subnet)
|
||||
port = {'port': {'project_id': subnet_project,
|
||||
'tenant_id': subnet_project,
|
||||
'network_id': subnet['network_id'], 'name': '',
|
||||
'admin_state_up': True, 'device_id': '',
|
||||
'device_owner': n_const.DEVICE_OWNER_DHCP,
|
||||
|
@ -151,8 +151,10 @@ class DFMechDriver(api.MechanismDriver):
|
||||
rules = sg.get('security_group_rules', [])
|
||||
|
||||
for rule in rules:
|
||||
rule['topic'] = rule.get('tenant_id')
|
||||
del rule['tenant_id']
|
||||
try:
|
||||
rule['topic'] = rule.pop('project_id')
|
||||
except KeyError:
|
||||
rule['topic'] = rule.pop('tenant_id', None)
|
||||
sg_obj = neutron_secgroups.security_group_from_neutron_obj(sg)
|
||||
if event == events.AFTER_CREATE:
|
||||
self.nb_api.create(sg_obj)
|
||||
@ -166,7 +168,8 @@ class DFMechDriver(api.MechanismDriver):
|
||||
@lock_db.wrap_db_lock(lock_db.RESOURCE_ML2_SECURITY_GROUP)
|
||||
def delete_security_group(self, resource, event, trigger, **kwargs):
|
||||
sg = kwargs['security_group']
|
||||
sg_obj = secgroups.SecurityGroup(id=sg['id'], topic=sg['tenant_id'])
|
||||
topic = df_utils.get_obj_topic(sg)
|
||||
sg_obj = secgroups.SecurityGroup(id=sg['id'], topic=topic)
|
||||
self.nb_api.delete(sg_obj)
|
||||
LOG.info("DFMechDriver: delete security group %s", sg['id'])
|
||||
|
||||
@ -214,11 +217,11 @@ class DFMechDriver(api.MechanismDriver):
|
||||
def delete_network_postcommit(self, context):
|
||||
network = context.current
|
||||
network_id = network['id']
|
||||
tenant_id = network['tenant_id']
|
||||
|
||||
topic = df_utils.get_obj_topic(network)
|
||||
try:
|
||||
self.nb_api.delete(l2.LogicalSwitch(id=network_id,
|
||||
topic=tenant_id))
|
||||
topic=topic))
|
||||
except df_exceptions.DBKeyNotFound:
|
||||
LOG.debug("lswitch %s is not found in DF DB, might have "
|
||||
"been deleted concurrently", network_id)
|
||||
@ -289,8 +292,9 @@ class DFMechDriver(api.MechanismDriver):
|
||||
subnet = context.current
|
||||
network = context.network.current
|
||||
net_id = subnet['network_id']
|
||||
topic = df_utils.get_obj_topic(network)
|
||||
lswitch = self.nb_api.get(l2.LogicalSwitch(id=net_id,
|
||||
topic=network['tenant_id']))
|
||||
topic=topic))
|
||||
lswitch.version = network['revision_number']
|
||||
df_subnet = neutron_l2.subnet_from_neutron_subnet(subnet)
|
||||
lswitch.add_subnet(df_subnet)
|
||||
@ -303,8 +307,9 @@ class DFMechDriver(api.MechanismDriver):
|
||||
def update_subnet_postcommit(self, context):
|
||||
new_subnet = context.current
|
||||
network = context.network.current
|
||||
topic = df_utils.get_obj_topic(network)
|
||||
lswitch = self.nb_api.get(l2.LogicalSwitch(id=new_subnet['network_id'],
|
||||
topic=network['tenant_id']))
|
||||
topic=topic))
|
||||
lswitch.version = network['revision_number']
|
||||
subnet = lswitch.find_subnet(new_subnet['id'])
|
||||
subnet.update(neutron_l2.subnet_from_neutron_subnet(new_subnet))
|
||||
@ -324,8 +329,9 @@ class DFMechDriver(api.MechanismDriver):
|
||||
net_id)
|
||||
|
||||
try:
|
||||
topic = df_utils.get_obj_topic(network)
|
||||
lswitch = self.nb_api.get(l2.LogicalSwitch(
|
||||
id=net_id, topic=network['tenant_id']))
|
||||
id=net_id, topic=topic))
|
||||
lswitch.remove_subnet(subnet_id)
|
||||
lswitch.version = network['revision_number']
|
||||
self.nb_api.update(lswitch)
|
||||
@ -362,8 +368,9 @@ class DFMechDriver(api.MechanismDriver):
|
||||
@lock_db.wrap_db_lock(lock_db.RESOURCE_ML2_NETWORK_OR_PORT)
|
||||
def update_port_postcommit(self, context):
|
||||
updated_port = context.current
|
||||
topic = df_utils.get_obj_topic(updated_port)
|
||||
lean_port = l2.LogicalPort(id=updated_port['id'],
|
||||
topic=updated_port['tenant_id'])
|
||||
topic=topic)
|
||||
if not self.nb_api.get(lean_port):
|
||||
# REVISIT(xiaohhui): Should we unify the check before update nb db?
|
||||
LOG.debug("The port %s has been deleted from dragonflow NB DB, "
|
||||
@ -393,8 +400,9 @@ class DFMechDriver(api.MechanismDriver):
|
||||
def delete_port_postcommit(self, context):
|
||||
port = context.current
|
||||
port_id = port['id']
|
||||
topic = df_utils.get_obj_topic(port)
|
||||
lean_port = l2.LogicalPort(id=port_id,
|
||||
topic=port['tenant_id'])
|
||||
topic=topic)
|
||||
|
||||
# Update topic for FIP ports
|
||||
if lean_port.topic == '':
|
||||
|
@ -20,6 +20,7 @@ from neutron_lib import context as n_context
|
||||
from neutron_lib.services import base as service_base
|
||||
from oslo_log import log as logging
|
||||
|
||||
from dragonflow.common import utils as df_utils
|
||||
from dragonflow.db.models import bgp
|
||||
from dragonflow.db.models import core
|
||||
from dragonflow.db.models import l2
|
||||
@ -30,9 +31,18 @@ from dragonflow.neutron.services import mixins
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_project_id_from_context(context):
|
||||
try:
|
||||
project_id = context.project_id
|
||||
except AttributeError:
|
||||
project_id = context.tenant_id
|
||||
return project_id
|
||||
|
||||
|
||||
def bgp_peer_from_neutron_bgp_peer(peer):
|
||||
topic = df_utils.get_obj_topic(peer)
|
||||
return bgp.BGPPeer(id=peer.get('id'),
|
||||
topic=peer.get('tenant_id'),
|
||||
topic=topic,
|
||||
name=peer.get('name'),
|
||||
peer_ip=peer.get('peer_ip'),
|
||||
remote_as=int(peer.get('remote_as')),
|
||||
@ -41,8 +51,9 @@ def bgp_peer_from_neutron_bgp_peer(peer):
|
||||
|
||||
|
||||
def bgp_speaker_from_neutron_bgp_speaker(speaker):
|
||||
topic = df_utils.get_obj_topic(speaker)
|
||||
return bgp.BGPSpeaker(id=speaker.get('id'),
|
||||
topic=speaker.get('tenant_id'),
|
||||
topic=topic,
|
||||
name=speaker.get('name'),
|
||||
local_as=int(speaker.get('local_as')),
|
||||
peers=speaker.get('peers', []),
|
||||
@ -96,8 +107,9 @@ class DFBgpPlugin(service_base.ServicePluginBase,
|
||||
|
||||
if port_id:
|
||||
# Associate floatingip
|
||||
project_id = _get_project_id_from_context(context)
|
||||
external_ip = self._get_external_ip_of_lport(port_id,
|
||||
context.tenant_id)
|
||||
project_id)
|
||||
if not external_ip:
|
||||
return
|
||||
|
||||
@ -254,17 +266,19 @@ class DFBgpPlugin(service_base.ServicePluginBase,
|
||||
skip_send_event=True)
|
||||
|
||||
for s in speakers:
|
||||
topic = df_utils.get_obj_topic(s)
|
||||
self._remove_bgp_peer_from_bgp_speaker(context, s['id'],
|
||||
bgp_peer_id, s['tenant_id'])
|
||||
bgp_peer_id, topic)
|
||||
|
||||
@lock_db.wrap_db_lock(lock_db.RESOURCE_BGP_SPEAKER)
|
||||
def add_bgp_peer(self, context, bgp_speaker_id, bgp_peer_info):
|
||||
ret_value = super(DFBgpPlugin, self).add_bgp_peer(context,
|
||||
bgp_speaker_id,
|
||||
bgp_peer_info)
|
||||
tenant_id = context.tenant_id
|
||||
|
||||
project_id = _get_project_id_from_context(context)
|
||||
bgp_speaker = self.nb_api.get(bgp.BGPSpeaker(id=bgp_speaker_id,
|
||||
topic=tenant_id))
|
||||
topic=project_id))
|
||||
bgp_speaker.peers.append(ret_value['bgp_peer_id'])
|
||||
self.nb_api.update(bgp_speaker, skip_send_event=True)
|
||||
return ret_value
|
||||
@ -273,31 +287,32 @@ class DFBgpPlugin(service_base.ServicePluginBase,
|
||||
ret_value = super(DFBgpPlugin, self).remove_bgp_peer(context,
|
||||
bgp_speaker_id,
|
||||
bgp_peer_info)
|
||||
tenant_id = context.tenant_id
|
||||
|
||||
project_id = _get_project_id_from_context(context)
|
||||
self._remove_bgp_peer_from_bgp_speaker(context,
|
||||
bgp_speaker_id,
|
||||
ret_value['bgp_peer_id'],
|
||||
tenant_id)
|
||||
project_id)
|
||||
return ret_value
|
||||
|
||||
def add_gateway_network(self, context, bgp_speaker_id, network_info):
|
||||
ret_value = super(DFBgpPlugin, self).add_gateway_network(
|
||||
context, bgp_speaker_id, network_info)
|
||||
|
||||
tenant_id = context.tenant_id
|
||||
project_id = _get_project_id_from_context(context)
|
||||
self._update_bgp_speaker_routes(context,
|
||||
bgp_speaker_id,
|
||||
tenant_id)
|
||||
project_id)
|
||||
return ret_value
|
||||
|
||||
def remove_gateway_network(self, context, bgp_speaker_id, network_info):
|
||||
ret_value = super(DFBgpPlugin, self).remove_gateway_network(
|
||||
context, bgp_speaker_id, network_info)
|
||||
|
||||
tenant_id = context.tenant_id
|
||||
project_id = _get_project_id_from_context(context)
|
||||
self._update_bgp_speaker_routes(context,
|
||||
bgp_speaker_id,
|
||||
tenant_id)
|
||||
project_id)
|
||||
return ret_value
|
||||
|
||||
@lock_db.wrap_db_lock(lock_db.RESOURCE_BGP_SPEAKER)
|
||||
@ -333,7 +348,8 @@ class DFBgpPlugin(service_base.ServicePluginBase,
|
||||
with context.session.begin(subtransactions=True):
|
||||
query = context.session.query(bgp_db.BgpSpeaker)
|
||||
query = query.filter(*filters)
|
||||
return [{'id': x['id'], 'tenant_id': x['tenant_id']}
|
||||
|
||||
return [{'id': x['id'], 'project_id': df_utils.get_obj_topic(x)}
|
||||
for x in query.all()]
|
||||
|
||||
@lock_db.wrap_db_lock(lock_db.RESOURCE_BGP_SPEAKER)
|
||||
@ -345,9 +361,10 @@ class DFBgpPlugin(service_base.ServicePluginBase,
|
||||
self.nb_api.update(bgp_speaker, skip_send_event=True)
|
||||
|
||||
def get_advertised_routes(self, context, bgp_speaker_id):
|
||||
tenant_id = context.tenant_id
|
||||
|
||||
project_id = _get_project_id_from_context(context)
|
||||
bgp_speaker = self.nb_api.get(bgp.BGPSpeaker(id=bgp_speaker_id,
|
||||
topic=tenant_id))
|
||||
topic=project_id))
|
||||
bgp_routes = bgp_speaker.host_routes + bgp_speaker.prefix_routes
|
||||
# Translate to the format that neutron will acccept.
|
||||
return {'advertised_routes': [{'destination': r.destination,
|
||||
|
@ -37,6 +37,7 @@ from oslo_log import log
|
||||
from oslo_utils import importutils
|
||||
|
||||
from dragonflow.common import exceptions as df_exceptions
|
||||
from dragonflow.common import utils as df_utils
|
||||
from dragonflow.db.models import l2
|
||||
from dragonflow.db.models import l3
|
||||
from dragonflow.db.neutron import lockedobjects_db as lock_db
|
||||
@ -211,8 +212,9 @@ class DFL3AgentlessRouterPlugin(service_base.ServicePluginBase,
|
||||
super(DFL3AgentlessRouterPlugin, self).delete_floatingip(
|
||||
context, fip_id)
|
||||
try:
|
||||
topic = df_utils.get_obj_topic(floatingip)
|
||||
self.nb_api.delete(
|
||||
l3.FloatingIp(id=fip_id, topic=floatingip['tenant_id']),
|
||||
l3.FloatingIp(id=fip_id, topic=topic),
|
||||
)
|
||||
except df_exceptions.DBKeyNotFound:
|
||||
LOG.exception("floatingip %s is not found in DF DB", fip_id)
|
||||
@ -232,14 +234,16 @@ class DFL3AgentlessRouterPlugin(service_base.ServicePluginBase,
|
||||
cidr = netaddr.IPNetwork(subnet['cidr'])
|
||||
network = "%s/%s" % (port['fixed_ips'][0]['ip_address'],
|
||||
str(cidr.prefixlen))
|
||||
port_topic = df_utils.get_obj_topic(port)
|
||||
logical_port = self.nb_api.get(l2.LogicalPort(id=port['id'],
|
||||
topic=port['tenant_id']))
|
||||
topic=port_topic))
|
||||
|
||||
router_topic = df_utils.get_obj_topic(router)
|
||||
logical_router_port = neutron_l3.build_logical_router_port(
|
||||
router_port_info, mac=port['mac_address'],
|
||||
network=network, unique_key=logical_port.unique_key)
|
||||
lrouter = self.nb_api.get(l3.LogicalRouter(id=router_id,
|
||||
topic=router['tenant_id']))
|
||||
topic=router_topic))
|
||||
lrouter.version = router['revision_number']
|
||||
lrouter.add_router_port(logical_router_port)
|
||||
self.nb_api.update(lrouter)
|
||||
@ -254,8 +258,9 @@ class DFL3AgentlessRouterPlugin(service_base.ServicePluginBase,
|
||||
router = self.get_router(context, router_id)
|
||||
|
||||
try:
|
||||
topic = df_utils.get_obj_topic(router)
|
||||
lrouter = self.nb_api.get(l3.LogicalRouter(
|
||||
id=router_id, topic=router['tenant_id']))
|
||||
id=router_id, topic=topic))
|
||||
lrouter.remove_router_port(router_port_info['port_id'])
|
||||
lrouter.version = router['revision_number']
|
||||
self.nb_api.update(lrouter)
|
||||
|
Loading…
Reference in New Issue
Block a user