Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Trivialfix: Use constant value from neutron-lib
Browse files Browse the repository at this point in the history
Change-Id: Ib27e34a43bb03d5a7f0d09d6704a37b84a104e60
  • Loading branch information
Yushiro FURUKAWA committed Jul 29, 2017
1 parent 3cfe4bf commit a7ce3b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
12 changes: 6 additions & 6 deletions networking_fujitsu/ml2/cfab/mech_cfab.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#

from neutron.plugins.ml2.common import exceptions as ml2_exc
from neutron_lib.api.definitions import portbindings
from neutron_lib.api.definitions import portbindings as pb_def
from neutron_lib import constants
from neutron_lib.plugins.ml2 import api
from oslo_config import cfg
Expand All @@ -32,7 +32,7 @@
VFAB_ID_DEFAULT = "default"
VFAB_ID_MIN = 1
VFAB_ID_MAX = 3000
_SUPPORTED_NET_TYPES = ['vlan']
_SUPPORTED_NET_TYPES = [constants.TYPE_VLAN]

ML2_FUJITSU_GROUP = "fujitsu_cfab"
ML2_FUJITSU = [
Expand Down Expand Up @@ -320,18 +320,18 @@ def get_physical_net_params(self, mech_context):
def bind_port(self, context):

port = context.current
vnic_type = port['binding:vnic_type']
LOG.debug("Attempting to bind port %(port)s with vnic_type "
"%(vnic_type)s on network %(network)s",
{'port': port['id'], 'vnic_type': vnic_type,
'network': context.network.current['id']})
{'port': port['id'],
'vnic_type': port[pb_def.VIF_TYPE],
'network': port['network_id']})

if validate_baremetal_deploy(context):
params = self.get_physical_net_params(context)
segments = context.segments_to_bind
self.setup_vlan(params)
context.set_binding(segments[0][api.ID],
portbindings.VIF_TYPE_OTHER, {},
pb_def.VIF_TYPE_OTHER, {},
status=constants.PORT_STATUS_ACTIVE)


Expand Down
3 changes: 2 additions & 1 deletion networking_fujitsu/ml2/common/type_vxlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from neutron.db.models.plugins.ml2 import vxlanallocation as vxlan_model
from neutron.plugins.ml2.drivers import type_tunnel
from neutron_lib import constants


class TypeVxlan(type_tunnel.EndpointTunnelTypeDriver):
Expand All @@ -22,7 +23,7 @@ def __init__(self):
vxlan_model.VxlanEndpoints)

def get_type(self):
return "vxlan"
return constants.TYPE_VXLAN

def initialize(self):
pass
Expand Down
7 changes: 3 additions & 4 deletions networking_fujitsu/ml2/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@

import re

from neutron_lib.api.definitions import portbindings
from neutron_lib.api.definitions import portbindings as pb_def
from neutron_lib.api.definitions import provider_net
from neutron_lib.plugins.ml2 import api
from oslo_log import log as logging

LOG = logging.getLogger(__name__)
RANGE_DEFINITION = re.compile(r'(\d+)-(\d+)')
_SUPPORTED_NET_TYPES = ['vlan']


def eliminate_val(source, reject):
Expand Down Expand Up @@ -191,8 +190,8 @@ def is_baremetal(port):
:rtype: boolean
"""

vnic_type = port.get(portbindings.VNIC_TYPE, portbindings.VNIC_NORMAL)
return (vnic_type == portbindings.VNIC_BAREMETAL)
vnic_type = port.get(pb_def.VNIC_TYPE, pb_def.VNIC_NORMAL)
return (vnic_type == pb_def.VNIC_BAREMETAL)


def is_lag(local_link_information):
Expand Down
49 changes: 25 additions & 24 deletions networking_fujitsu/ml2/fossw/mech_fossw.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#

from neutron.plugins.ml2.common import exceptions as ml2_exc
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants
from neutron_lib.api.definitions import portbindings as pb_def
from neutron_lib import constants as nl_const
from neutron_lib.plugins.ml2 import api
from oslo_config import cfg
from oslo_log import helpers as log_helpers
Expand All @@ -31,7 +31,7 @@
FOSSW_VXLAN_DRIVER = DRIVER + 'fossw.fossw_vxlandriver.FOSSWVxlanDriver'
DEFAULT_VLAN = 1

_SUPPORTED_NET_TYPES = ['vlan', 'vxlan']
_SUPPORTED_NET_TYPES = [nl_const.TYPE_VLAN, nl_const.TYPE_VXLAN]

ML2_FUJITSU_GROUP = "fujitsu_fossw"
ML2_FUJITSU = [
Expand Down Expand Up @@ -127,9 +127,9 @@ def create_network_postcommit(self, net_context):
network_type = utils.get_network_type(network)
seg_id = utils.get_segmentation_id(network)

if network_type == 'vlan' and seg_id:
if network_type == nl_const.TYPE_VLAN and seg_id:
self.create_network_postcommit_vlan(seg_id)
elif network_type == 'vxlan' and seg_id:
elif network_type == nl_const.TYPE_VXLAN and seg_id:
self.create_network_postcommit_vxlan(network_id, seg_id)

LOG.info(
Expand Down Expand Up @@ -192,9 +192,9 @@ def delete_network_postcommit(self, net_context):
network_type = utils.get_network_type(network)
seg_id = utils.get_segmentation_id(network)

if network_type == 'vlan' and seg_id:
if network_type == nl_const.TYPE_VLAN and seg_id:
self.delete_network_postcommit_vlan(seg_id)
if network_type == 'vxlan' and seg_id:
if network_type == nl_const.TYPE_VXLAN and seg_id:
self.delete_network_postcommit_vxlan(net_id)
LOG.info(
"Deleted network (postcommit): network_id=%(net)s "
Expand Down Expand Up @@ -254,9 +254,9 @@ def delete_port_postcommit(self, mech_context):
network_id = port['network_id']
tenant_id = port['tenant_id']
network_type = utils.get_network_type(network)
if network_type == 'vlan' and utils.is_baremetal(port):
if network_type == nl_const.TYPE_VLAN and utils.is_baremetal(port):
self.clear_vlan(mech_context)
if network_type == 'vxlan':
if network_type == nl_const.TYPE_VXLAN:
self.clear_vxlan(mech_context)
LOG.info(
"Delete port (postcommit): port_id=%(port_id)s "
Expand All @@ -269,17 +269,17 @@ def update_port_postcommit(self, context):
method = 'update_port_postcommit'
port = context.current
network = context.network
vif_type = port['binding:vif_type']
vif_type = port[pb_def.VIF_TYPE]
network_type = utils.get_network_type(network)
seg_id = utils.get_segmentation_id(network)
if utils.is_baremetal(port):
if (vif_type == 'unbound' and
context.original['binding:vif_type'] == 'other'):
if (vif_type == pb_def.VIF_TYPE_UNBOUND and context.original[
pb_def.VIF_TYPE] == pb_def.VIF_TYPE_OTHER):
try:
# Clear vlan or vxlan from physical port for unbound port
if network_type == 'vlan':
if network_type == nl_const.TYPE_VLAN:
self.clear_vlan(context, use_original=True)
if network_type == 'vxlan':
if network_type == nl_const.TYPE_VXLAN:
self.clear_vxlan(context, use_original=True)
except Exception:
LOG.exception("Failed to clear %(network_type)s"
Expand All @@ -289,7 +289,8 @@ def update_port_postcommit(self, context):
raise ml2_exc.MechanismDriverError(method=method)
else:
# Setup vxlan from specified physical port on switch.
if network_type != 'vxlan' or vif_type == 'unbound':
if (network_type != nl_const.TYPE_VXLAN or
vif_type == pb_def.VIF_TYPE_UNBOUND):
return
# currently supports only one segment per network
# Setup VXLAN for port which bound with DHCP, router, and vms.
Expand Down Expand Up @@ -368,8 +369,9 @@ def clear_vxlan(self, context, use_original=False):
method = "clear_vxlan"
port = context.original if use_original else context.current
network = context.network
vif_type = port['binding:vif_type']
if vif_type == 'unbound' or utils.get_network_type(network) == 'flat':
vif_type = port[pb_def.VIF_TYPE]
if (vif_type == pb_def.VIF_TYPE_UNBOUND or
utils.get_network_type(network) == nl_const.TYPE_FLAT):
return
lli = utils.get_physical_connectivity(port)
try:
Expand Down Expand Up @@ -426,27 +428,26 @@ def bind_port(self, context):
network = context.network
if not is_supported(network):
return
vnic_type = port['binding:vnic_type']
LOG.debug("Attempting to bind port %(port)s with vnic_type "
"%(vnic_type)s on network %(network)s",
{'port': port['id'], 'vnic_type': vnic_type,
'network': network.current['id']})
{'port': port['id'], 'vnic_type': port[pb_def.VNIC_TYPE],
'network': port['network_id']})

network_type = utils.get_network_type(network)
to_bind = False

if network_type == 'vxlan':
if network_type == nl_const.TYPE_VXLAN:
# vxlan driver handles not only baremetal port, but vm, dhcp,
# router ports.
self.setup_vxlan(context)
to_bind = True
if utils.is_baremetal(port) and network_type == 'vlan':
if utils.is_baremetal(port) and network_type == nl_const.TYPE_VLAN:
self.setup_vlan(self.get_physical_net_params(context))
to_bind = True
if to_bind:
context.set_binding(context.segments_to_bind[0][api.ID],
portbindings.VIF_TYPE_OTHER, {},
status=constants.PORT_STATUS_ACTIVE)
pb_def.VIF_TYPE_OTHER, {},
status=nl_const.PORT_STATUS_ACTIVE)

@log_helpers.log_method_call
def setup_vxlan(self, context):
Expand Down

0 comments on commit a7ce3b5

Please sign in to comment.