Skip to content

Commit

Permalink
VNETEE-441 - Remove hp references
Browse files Browse the repository at this point in the history
Changed the 'hp' driver name to other convention name to be used for BNP enablement
also supported devstack and configuration to enable the  hpe driver .
  • Loading branch information
selvakumars2 committed Feb 17, 2016
1 parent 6cef1fe commit bca8c2c
Show file tree
Hide file tree
Showing 13 changed files with 505 additions and 41 deletions.
11 changes: 0 additions & 11 deletions baremetal_network_provisioning/db/bm_nw_provision_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,3 @@ def get_bnp_phys_switch_ports_by_switch_id(context, switch_id):
LOG.error('no ports found for physical switch %s', switch_id)
return
return switch_ports


def get_all_bnp_swport_mappings(context):
"""Get all switch port mappings."""
try:
query = context.session.query(models.BNPSwitchPortMapping)
swport_map = query.all()
except exc.NoResultFound:
LOG.error(_LE("no switch port mapping found"))
return
return swport_map
10 changes: 4 additions & 6 deletions baremetal_network_provisioning/ml2/extensions/bnp_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ def delete(self, request, id, **kwargs):
context = request.context
self._check_admin(context)
switch = db.get_bnp_phys_switch(context, id)
portmaps = db.get_all_bnp_swport_mappings(context)
for portmap in portmaps:
switch_id = portmap['switch_id']
if id == switch_id:
raise webob.exc.HTTPConflict(
_("Switch id %s has active port mappings") % id)
portmap = db.get_bnp_switch_port_map_by_switchid(context, id)
if portmap:
raise webob.exc.HTTPConflict(
_("Switch id %s has active port mappings") % id)
if not switch:
raise webob.exc.HTTPNotFound(
_("Switch %s does not exist") % id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


LOG = logging.getLogger(__name__)
hp_opts = [
hpe_opts = [
cfg.StrOpt('base_url',
help=_("Base HTTP URL of SDN controller")),
cfg.StrOpt('auth_token',
Expand All @@ -45,7 +45,7 @@
help=_("Timeout in seconds to wait for SDN HTTP request"
"completion.")),
]
cfg.CONF.register_opts(hp_opts, "default")
cfg.CONF.register_opts(hpe_opts, "default")


class HPNetworkProvisioningDriver(api.NetworkProvisioningApi):
Expand Down
40 changes: 40 additions & 0 deletions baremetal_network_provisioning/ml2/hpeironicextensiondriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2015 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from neutron.api import extensions as neutron_extensions
from neutron.plugins.ml2 import driver_api as api

from baremetal_network_provisioning.ml2 import extensions

from oslo_log import log as logging

LOG = logging.getLogger(__name__)


class HPEIronicExtensionDriver(api.ExtensionDriver):
_supported_extension_aliases = 'bnp-switch'

def initialize(self):
neutron_extensions.append_api_extensions_path(extensions.__path__)
LOG.info(_("HPIronicExtensionDriver initialization complete"))

@property
def extension_alias(self):
"""Supported extension alias.
identifying the core API extension supported
by this BNP driver
"""
return self._supported_extension_aliases
203 changes: 203 additions & 0 deletions baremetal_network_provisioning/ml2/mechanism_hpe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Copyright (c) 2015 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import importutils

from neutron.common import constants as n_const
from neutron.extensions import portbindings
from neutron.plugins.common import constants
from neutron.plugins.ml2 import driver_api as api

from baremetal_network_provisioning.common import constants as hp_const


LOG = logging.getLogger(__name__)
hpe_opts = [
cfg.StrOpt('net_provisioning_driver',
default='baremetal_network_provisioning.ml2'
'.hp_network_provisioning_driver.HPNetworkProvisioningDriver',
help=_("Driver to provision networks on the switches in"
"the cloud fabric")),
]
cfg.CONF.register_opts(hpe_opts, "ml2_hpe")


class HPEMechanismDriver(api.MechanismDriver):
"""Ml2 Mechanism front-end driver interface for bare
metal provisioning.
"""

def initialize(self):
self.conf = cfg.CONF
self._load_drivers()
self.vif_type = hp_const.HP_VIF_TYPE
self.vif_details = {portbindings.CAP_PORT_FILTER: True}

def _load_drivers(self):
"""Loads back end network provision driver from configuration."""
driver_obj = self.conf.ml2_hpe.net_provisioning_driver
if not driver_obj:
raise SystemExit(_('A network provisioning driver'
'must be specified'))
self.np_driver = importutils.import_object(driver_obj)

def create_port_precommit(self, context):
"""create_port_precommit."""
if not self._is_port_of_interest(context):
return
port_dict = self._construct_port(context)
try:
self.np_driver.create_port(port_dict)
except Exception as e:
raise e

def create_port_postcommit(self, context):
"""create_port_postcommit."""
pass

def update_port_precommit(self, context):
"""update_port_precommit."""
vnic_type = self._get_vnic_type(context)
profile = self._get_binding_profile(context)
if vnic_type != portbindings.VNIC_BAREMETAL or not profile:
return
port_dict = self._construct_port(context)
host_id = context.current['binding:host_id']
bind_port_dict = port_dict.get('port')
bind_port_dict['host_id'] = host_id
self.np_driver.update_port(port_dict)

def update_port_postcommit(self, context):
"""update_port_postcommit."""
pass

def delete_port_precommit(self, context):
"""delete_port_postcommit."""
vnic_type = self._get_vnic_type(context)
port_id = context.current['id']
if vnic_type == portbindings.VNIC_BAREMETAL:
self.np_driver.delete_port(port_id)

def delete_port_postcommit(self, context):
pass

def bind_port(self, context):
"""bind_port for claiming the ironic port."""
LOG.debug("HPMechanismDriver Attempting to bind port %(port)s on "
"network %(network)s",
{'port': context.current['id'],
'network': context.network.current['id']})
port_id = context.current['id']
for segment in context.segments_to_bind:
segmentation_id = segment.get(api.SEGMENTATION_ID)
if self._is_vlan_segment(segment, context):
port_status = n_const.PORT_STATUS_ACTIVE
if not self._is_port_of_interest(context):
return
host_id = context.current['binding:host_id']
if host_id:
port = self._construct_port(context, segmentation_id)
b_status = self.np_driver.bind_port_to_segment(port)
if b_status == hp_const.BIND_SUCCESS:
context.set_binding(segment[api.ID],
self.vif_type,
self.vif_details,
status=port_status)
LOG.debug("port bound using segment for port %(port)s",
{'port': port_id})
return
else:
LOG.debug("port binding pass for %(segment)s",
{'segment': segment})
return
else:
LOG.debug("Ignoring %(seg)s for port %(port)s",
{'seg': segmentation_id,
'port': port_id})
return

def _is_vlan_segment(self, segment, context):
"""Verify a segment is valid for the HP MechanismDriver.
Verify the requested segment is supported by HP and return True or
False to indicate this to callers.
"""
network_type = segment[api.NETWORK_TYPE]
if network_type in [constants.TYPE_VLAN]:
return True
else:
False

def _construct_port(self, context, segmentation_id=None):
""""Contruct port dict."""
port = context.current
port_id = port['id']
network_id = port['network_id']
is_lag = False
bind_port_dict = None
profile = self._get_binding_profile(context)
local_link_information = profile.get('local_link_information')
host_id = context.current['binding:host_id']
LOG.debug("_construct_port local link info %(local_info)s",
{'local_info': local_link_information})
if local_link_information and len(local_link_information) > 1:
is_lag = True
port_dict = {'port':
{'id': port_id,
'network_id': network_id,
'is_lag': is_lag,
'switchports': local_link_information,
'host_id': host_id
}
}
if segmentation_id:
bind_port_dict = port_dict.get('port')
bind_port_dict['segmentation_id'] = segmentation_id
bind_port_dict['access_type'] = hp_const.ACCESS
else:
return port_dict
final_dict = {'port': bind_port_dict}
LOG.debug("final port dict %(final_dict)s",
{'final_dict': final_dict})
return final_dict

def _get_binding_profile(self, context):
"""get binding profile from port context."""
profile = context.current.get(portbindings.PROFILE, {})
if not profile:
LOG.debug("Missing profile in port binding")
return profile

def _get_vnic_type(self, context):
"""get vnic type for baremetal."""
vnic_type = context.current.get(portbindings.VNIC_TYPE, "")
if not vnic_type:
return None
else:
return vnic_type

def _is_port_of_interest(self, context):
vnic_type = self._get_vnic_type(context)
binding_profile = self._get_binding_profile(context)
if vnic_type != portbindings.VNIC_BAREMETAL or not binding_profile:
return False
local_link_information = binding_profile.get('local_link_information')
if not local_link_information:
LOG.debug("local_link_information list does not exist in profile")
return False
return True
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,3 @@ def test_update_bnp_phys_swport_status(self):
port_updt = self.ctx.session.query(models.BNPPhysicalSwitchPort).all()
self.assertNotEqual(port_dict['port_status'],
port_updt[0]['port_status'])

def test_get_all_bnp_sw_port_mappings(self):
"""Test test_get_all_bnp_sw_port_mappings method."""
port_map = self._get_bnp_switch_port_map_dict()
db.add_bnp_switch_port_map(self.ctx, port_map)
mappings = db.get_all_bnp_swport_mappings(self.ctx)
actual_switch_id = mappings[0]['switch_id']
self.assertEqual(actual_switch_id, '3456')
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestBnpSwitches(test_plugin.NeutronDbPluginV2TestCase,
testlib_api.WebTestCase):

fmt = 'json'
_mechanism_drivers = ['hp']
_mechanism_drivers = ['hpe_bnp']
_ext_drivers = 'bnp_ext_driver'

def setUp(self):
Expand Down Expand Up @@ -104,15 +104,15 @@ def _update_switch(self, data, switch_id):

def _delete_switch(self, switch_id):
with contextlib.nested(
mock.patch.object(db, 'get_all_bnp_swport_mappings',
mock.patch.object(db, 'get_bnp_switch_port_map_by_switchid',
return_value=[])):
delete_req = self.new_delete_request('bnp-switches',
switch_id)
self.bnp_wsgi_controller.delete(delete_req, switch_id)

def _delete_switch_with_active_mappings(self, switch_id):
with contextlib.nested(
mock.patch.object(db, 'get_all_bnp_swport_mappings',
mock.patch.object(db, 'get_bnp_switch_port_map_by_switchid',
return_value=[{'switch_id': switch_id}])):
delete_req = self.new_delete_request('bnp-switches',
switch_id)
Expand Down
Loading

0 comments on commit bca8c2c

Please sign in to comment.