]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow default network and policy profiles
authorAbhishek Raut <abhraut@cisco.com>
Sat, 31 Aug 2013 00:39:26 +0000 (17:39 -0700)
committerAbhishek Raut <abhraut@cisco.com>
Thu, 5 Sep 2013 19:36:10 +0000 (12:36 -0700)
Allow for default network/policy profile to be used if
no network/policy profile is specified during network/port creation
in the Cisco N1KV plugin.

Change-Id: I6120abb5abb9a869eb7310453cf27dd8f72bfd1d
Closes-Bug: #1218588

etc/neutron/plugins/cisco/cisco_plugins.ini
neutron/plugins/cisco/common/cisco_exceptions.py
neutron/plugins/cisco/common/config.py
neutron/plugins/cisco/db/n1kv_db_v2.py
neutron/plugins/cisco/n1kv/n1kv_client.py
neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py

index bce23b74659c71b9470643ec310ca5e6582d6ca3..50e6fc52ed42617580e5e1eda452503bd983bfad 100644 (file)
 # 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
index a37dd8b382e60d4040d2d7d6b499234d5b195e96..5b55aabe6c151b264b7364a37a57aa9a18b6a926 100644 (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):
index 7a44a336ee0e413e46f90473873d20a280aa5834..a7c8953ee0c2cb323e4a0020764f0eca49457abf 100644 (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")),
 ]
index 2f6cd33c895c58c42534505eff3a7c5bbb9aaf2f..7527f41c37a21cb3250a98a0e430e229c4649d31 100644 (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):
         """
index 3f7b9bee659d95ac11fb5389de3751a43df270ca..69e9c4f78d5139f2e0314046aeb40aabf35e3a25 100644 (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]
index 61d603bcfab274d15fc37f28561dd3ec1c790ba2..ed00c50c5549a18f9a878a9b630fc57abd989d34 100644 (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'])