Merge "Allow default network and policy profiles"

This commit is contained in:
Jenkins 2013-09-05 22:26:49 +00:00 committed by Gerrit Code Review
commit ee023ba698
6 changed files with 71 additions and 21 deletions

View File

@ -97,10 +97,33 @@
# password=mySecretPassword
[cisco_n1k]
# integration_bridge=br-int
# enable_tunneling=True
# tunnel_bridge=br-tun
# local_ip=10.0.0.3
# tenant_network_type=local
# default_policy_profile=<my default dhcp/router policy profile name>
# poll_duration=<Time in seconds>
# (StrOpt) Specify the name of the integration bridge to which the VIFs are
# attached.
#
# integration_bridge = br-int
# (StrOpt) Name of the policy profile to be associated with a port when no
# policy profile is specified during port creates.
#
# default_policy_profile =
# Example: default_policy_profile = service_profile
# (StrOpt) Name of the policy profile to be associated with a port owned by
# network node (dhcp, router).
#
# network_node_policy_profile =
# Example: network_node_policy_profile = dhcp_pp
# (StrOpt) Name of the network profile to be associated with a network when no
# network profile is specified during network creates. Admin should pre-create
# a network profile with this name.
#
# default_network_profile =
# Example: default_network_profile = network_pool
# (StrOpt) Time in seconds for which the plugin polls the VSM for updates in
# policy profiles.
#
# poll_duration =
# Example: poll_duration = 180

View File

@ -164,9 +164,9 @@ class NetworkProfileAlreadyExists(exceptions.NeutronException):
"already exists.")
class NetworkProfileIdNotFound(exceptions.NotFound):
"""Network Profile with the given UUID cannot be found."""
message = _("Network Profile %(profile_id)s could not be found.")
class NetworkProfileNotFound(exceptions.NotFound):
"""Network Profile with the given UUID/name cannot be found."""
message = _("Network Profile %(profile)s could not be found.")
class NoMoreNetworkSegments(exceptions.NoNetworkAvailable):

View File

@ -70,8 +70,12 @@ cisco_n1k_opts = [
help=_("N1K VXLAN ID Ranges")),
cfg.StrOpt('network_vlan_ranges', default='vlan:1:4095',
help=_("N1K Network VLAN Ranges")),
cfg.StrOpt('default_network_profile', default='default_network_profile',
help=_("N1K default network profile")),
cfg.StrOpt('default_policy_profile', default='service_profile',
help=_("N1K default policy profile")),
cfg.StrOpt('network_node_policy_profile', default='dhcp_pp',
help=_("N1K policy profile for network node")),
cfg.StrOpt('poll_duration', default='10',
help=_("N1K Policy profile polling duration in seconds")),
]

View File

@ -886,7 +886,7 @@ def get_network_profile(db_session, id):
return db_session.query(
n1kv_models_v2.NetworkProfile).filter_by(id=id).one()
except exc.NoResultFound:
raise c_exc.NetworkProfileIdNotFound(profile_id=id)
raise c_exc.NetworkProfileNotFound(profile=id)
def _get_network_profiles(**kwargs):
@ -1197,7 +1197,7 @@ class NetworkProfile_db_mixin(object):
try:
get_network_profile(context.session, id)
return True
except c_exc.NetworkProfileIdNotFound(profile_id=id):
except c_exc.NetworkProfileNotFound(profile=id):
return False
def _get_segment_range(self, data):
@ -1310,6 +1310,21 @@ class NetworkProfile_db_mixin(object):
LOG.exception(msg)
raise q_exc.InvalidInput(error_message=msg)
def _get_network_profile_by_name(self, db_session, name):
"""
Retrieve network profile based on name.
:param db_session: database session
:param name: string representing the name for the network profile
:returns: network profile object
"""
with db_session.begin(subtransactions=True):
try:
return (db_session.query(n1kv_models_v2.NetworkProfile).
filter_by(name=name).one())
except exc.NoResultFound:
raise c_exc.NetworkProfileNotFound(profile=name)
class PolicyProfile_db_mixin(object):
@ -1460,7 +1475,7 @@ class PolicyProfile_db_mixin(object):
db_session = db.get_session()
with db_session.begin(subtransactions=True):
return (db_session.query(n1kv_models_v2.PolicyProfile).
filter_by(name=name).first())
filter_by(name=name).one())
def _remove_all_fake_policy_profiles(self):
"""

View File

@ -204,6 +204,7 @@ class Client(object):
"""
body = {'name': network['name'],
'id': network['id'],
'mode': 'access',
'networkSegmentPool': network_profile['name'], }
if network[providernet.NETWORK_TYPE] == c_const.NETWORK_TYPE_VLAN:
body['vlan'] = network[providernet.SEGMENTATION_ID]

View File

@ -667,16 +667,16 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
port['id'])
port[n1kv_profile.PROFILE_ID] = binding.profile_id
def _process_network_profile(self, context, attrs):
def _process_network_profile(self, context, network):
"""Validate network profile exists."""
profile_id = attrs.get(n1kv_profile.PROFILE_ID)
profile_id = network.get(n1kv_profile.PROFILE_ID)
profile_id_set = attributes.is_attr_set(profile_id)
if not profile_id_set:
raise cisco_exceptions.NetworkProfileIdNotFound(
profile_id=profile_id)
if not self.network_profile_exists(context, profile_id):
raise cisco_exceptions.NetworkProfileIdNotFound(
profile_id=profile_id)
profile_name = c_conf.CISCO_N1K.default_network_profile
net_p = self._get_network_profile_by_name(context.session,
profile_name)
profile_id = net_p['id']
network['n1kv:profile_id'] = profile_id
return profile_id
def _process_policy_profile(self, context, attrs):
@ -1218,7 +1218,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
if ('device_id' in port['port'] and port['port']['device_owner'] in
['network:dhcp', 'network:router_interface']):
p_profile_name = c_conf.CISCO_N1K.default_policy_profile
p_profile_name = c_conf.CISCO_N1K.network_node_policy_profile
p_profile = self._get_policy_profile_by_name(p_profile_name)
if p_profile:
port['port']['n1kv:profile_id'] = p_profile['id']
@ -1228,6 +1228,13 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
profile_id = port['port'].get(n1kv_profile.PROFILE_ID)
profile_id_set = attributes.is_attr_set(profile_id)
if not profile_id_set:
p_profile_name = c_conf.CISCO_N1K.default_policy_profile
p_profile = self._get_policy_profile_by_name(p_profile_name)
if p_profile:
port['port']['n1kv:profile_id'] = p_profile['id']
profile_id_set = True
if profile_id_set:
profile_id = self._process_policy_profile(context,
port['port'])