Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion gbpservice/nfp/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,12 @@ def load_nfp_modules(conf, controller):
modules_dir = base_module.__path__[0]
try:
files = os.listdir(modules_dir)
for pyfile in set([f for f in files if f.endswith(".py")]):
pyfiles = set([f for f in files if f.endswith(".py")])
for pyfile in pyfiles:
module_name = pyfile.strip('.py')
nsd_module_name = module_name + '_NSD.py'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want to skip _NSD.py here ?
can this file be put outside of 'modules/' folder ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It its not a module, it should not be in 'modules' folder.

if nsd_module_name in pyfiles:
continue
try:
pymodule = __import__(conf.nfp_modules_path,
globals(), locals(),
Expand Down
2 changes: 1 addition & 1 deletion gbpservice/nfp/orchestrator/config_drivers/heat_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def _create_firewall_template(self, auth_token,
subnets = consumer['subnets']

# Skip the stitching PTG
if ptg['proxied_group_id']:
if ptg.get('proxied_group_id'):
continue

fw_template_properties.update({'name': ptg['id'][:3]})
Expand Down
130 changes: 130 additions & 0 deletions gbpservice/nfp/orchestrator/db/nfp_db_NSD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from gbpservice.nfp.orchestrator.db.nfp_db import NFPDbBase

from gbpservice.nfp.orchestrator.db import common_db_mixin
from gbpservice.nfp.orchestrator.db import nfp_db_model

from gbpservice.nfp.core import log as nfp_logging
LOG = nfp_logging.getLogger(__name__)


class NFPDbBaseNSD(NFPDbBase):
def __init__(self, *args, **kwargs):
super(NFPDbBaseNSD, self).__init__(*args, **kwargs)

def _set_plugged_in_port_for_nfd_interface(self, session, nfd_interface_db,
interface, is_update=False):
plugged_in_port_id = interface.get('plugged_in_port_id')
if not plugged_in_port_id:
if not is_update:
nfd_interface_db.plugged_in_port_id = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets discuss on how to avoid the duplicate code. Looks like we have two files with enterprise stuff in enterprise file.

return
with session.begin(subtransactions=True):
port_info_db = nfp_db_model.PortInfo(
id=plugged_in_port_id['id'],
port_model=plugged_in_port_id['port_model'],
port_classification=plugged_in_port_id['port_classification'],
port_role=plugged_in_port_id['port_role'])
if is_update:
session.merge(port_info_db)
else:
session.add(port_info_db)
session.flush()
nfd_interface_db.plugged_in_port_id = port_info_db['id']
del interface['plugged_in_port_id']


def create_network_function_device_interface(self, session,
nfd_interface):
with session.begin(subtransactions=True):
mapped_real_port_id = nfd_interface.get('mapped_real_port_id')
nfd_interface_db = nfp_db_model.NetworkFunctionDeviceInterface(
id=(nfd_interface.get('id') or uuidutils.generate_uuid()),
tenant_id=nfd_interface['tenant_id'],
interface_position=nfd_interface['interface_position'],
mapped_real_port_id=mapped_real_port_id,
network_function_device_id=(
nfd_interface['network_function_device_id']))
self._set_plugged_in_port_for_nfd_interface(
session, nfd_interface_db, nfd_interface)
session.add(nfd_interface_db)

return self._make_network_function_device_interface_dict(
nfd_interface_db)

def update_network_function_device_interface(self, session,
nfd_interface_id,
updated_nfd_interface):
with session.begin(subtransactions=True):
nfd_interface_db = self._get_network_function_device_interface(
session, nfd_interface_id)
self._set_plugged_in_port_for_nfd_interface(
session, nfd_interface_db, updated_nfd_interface,
is_update=True)
nfd_interface_db.update(updated_nfd_interface)
return self._make_network_function_device_interface_dict(
nfd_interface_db)

def delete_network_function_device_interface(
self, session, network_function_device_interface_id):
with session.begin(subtransactions=True):
network_function_device_interface_db = (
self._get_network_function_device_interface(
session, network_function_device_interface_id))
if network_function_device_interface_db.plugged_in_port_id:
self.delete_port_info(
session,
network_function_device_interface_db.plugged_in_port_id)
session.delete(network_function_device_interface_db)

def _get_network_function_device_interface(self, session,
network_function_device_id):
try:
return self._get_by_id(
session,
nfp_db_model.NetworkFunctionDeviceInterface,
network_function_device_id)
except exc.NoResultFound:
raise nfp_exc.NetworkFunctionDeviceNotFound(
network_function_device_id=network_function_device_id)

def get_network_function_device_interface(
self, session, network_function_device_interface_id,
fields=None):
network_function_device_interface = (
self._get_network_function_device_interface(
session, network_function_device_interface_id))
return self._make_network_function_device_interface_dict(
network_function_device_interface, fields)

def get_network_function_device_interfaces(self, session, filters=None,
fields=None, sorts=None,
limit=None, marker=None,
page_reverse=False):
marker_obj = self._get_marker_obj(
'network_function_device_interfaces', limit, marker)
return self._get_collection(
session,
nfp_db_model.NetworkFunctionDeviceInterface,
self._make_network_function_device_interface_dict,
filters=filters, fields=fields,
sorts=sorts, limit=limit,
marker_obj=marker_obj,
page_reverse=page_reverse)


def _make_network_function_device_interface_dict(self, nfd_interface,
fields=None):
res = {'id': nfd_interface['id'],
'tenant_id': nfd_interface['tenant_id'],
'plugged_in_port_id': nfd_interface['plugged_in_port_id'],
'interface_position': nfd_interface['interface_position'],
'mapped_real_port_id': nfd_interface['mapped_real_port_id'],
'network_function_device_id': (
nfd_interface['network_function_device_id']),
}
return res





49 changes: 49 additions & 0 deletions gbpservice/nfp/orchestrator/db/nfp_db_model_NSD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from neutron.db import model_base


class PortInfo(BASE, model_base.HasId, model_base.HasTenant):
"""Represents the Port Information"""
__tablename__ = 'nfp_port_infos'

port_model = sa.Column(sa.Enum(nfp_constants.NEUTRON_PORT,
nfp_constants.GBP_PORT,
name='port_model'))
port_classification = sa.Column(sa.Enum(nfp_constants.PROVIDER,
nfp_constants.CONSUMER,
nfp_constants.MANAGEMENT,
nfp_constants.MONITOR,
nfp_constants.ADVANCE_SHARING,
name='port_classification'))
port_role = sa.Column(sa.Enum(nfp_constants.ACTIVE_PORT,
nfp_constants.STANDBY_PORT,
nfp_constants.MASTER_PORT,
name='port_role'),
nullable=True)



class NetworkFunctionDeviceInterface(BASE, model_base.HasId, model_base.HasTenant):
"""Represents the Network Function Device"""
__tablename__ = 'nfp_network_function_device_interfaces'

plugged_in_port_id = sa.Column(sa.String(36),
sa.ForeignKey('nfp_port_infos.id',
ondelete='SET NULL'),
nullable=True)
interface_position = sa.Column(sa.Integer(), nullable=False)
mapped_real_port_id = sa.Column(sa.String(36),
sa.ForeignKey('nfp_port_infos.id',
ondelete='SET NULL'),
nullable=True)
network_function_device_id = sa.Column(
sa.String(36),
sa.ForeignKey('nfp_network_function_devices.id',
ondelete='SET NULL'),
nullable=False)







Loading