Extension driver framework for GBP
Adds support for extension drivers, similar to those in ML2, to the GBP service plugin. All GBP resource types can be extended. Partially-implements: blueprint gbp-extension-drivers Change-Id: If4e522233fae4442bb179ddabd9ac6295ca6f431
This commit is contained in:
parent
1cc7fb4689
commit
2f1be70cc7
11
etc/grouppolicy.ini
Normal file
11
etc/grouppolicy.ini
Normal file
@ -0,0 +1,11 @@
|
||||
[group_policy]
|
||||
# (ListOpt) An ordered list of policy driver entrypoints to be loaded
|
||||
# from the gbp.neutron.group_policy.policy_drivers namespace.
|
||||
# policy_drivers =
|
||||
# Example: policy_drivers = implicit_policy,resource_mapping
|
||||
|
||||
# (ListOpt) An ordered list of extension driver entrypoints to be
|
||||
# loaded from the gbp.neutron.group_policy.extension_drivers
|
||||
# namespace.
|
||||
# extension_drivers =
|
||||
# Example: extension_drivers = anewextensiondriver
|
@ -1093,10 +1093,17 @@ class GroupPolicyDbPlugin(gpolicy.GroupPolicyPluginBase,
|
||||
return self._make_policy_rule_dict(pr, fields)
|
||||
|
||||
@log.log
|
||||
def get_policy_rules(self, context, filters=None, fields=None):
|
||||
def get_policy_rules(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
marker_obj = self._get_marker_obj(context, 'policy_rule', limit,
|
||||
marker)
|
||||
return self._get_collection(context, PolicyRule,
|
||||
self._make_policy_rule_dict,
|
||||
filters=filters, fields=fields)
|
||||
filters=filters, fields=fields,
|
||||
sorts=sorts, limit=limit,
|
||||
marker_obj=marker_obj,
|
||||
page_reverse=page_reverse)
|
||||
|
||||
@log.log
|
||||
def get_policy_rules_count(self, context, filters=None):
|
||||
@ -1148,10 +1155,17 @@ class GroupPolicyDbPlugin(gpolicy.GroupPolicyPluginBase,
|
||||
return self._make_policy_rule_set_dict(prs, fields)
|
||||
|
||||
@log.log
|
||||
def get_policy_rule_sets(self, context, filters=None, fields=None):
|
||||
def get_policy_rule_sets(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
marker_obj = self._get_marker_obj(context, 'policy_rule_set', limit,
|
||||
marker)
|
||||
return self._get_collection(context, PolicyRuleSet,
|
||||
self._make_policy_rule_set_dict,
|
||||
filters=filters, fields=fields)
|
||||
filters=filters, fields=fields,
|
||||
sorts=sorts, limit=limit,
|
||||
marker_obj=marker_obj,
|
||||
page_reverse=page_reverse)
|
||||
|
||||
@log.log
|
||||
def get_policy_rule_sets_count(self, context, filters=None):
|
||||
|
@ -19,6 +19,12 @@ group_policy_opts = [
|
||||
help=_("An ordered list of group policy driver "
|
||||
"entrypoints to be loaded from the "
|
||||
"gbp.neutron.group_policy.policy_drivers namespace.")),
|
||||
cfg.ListOpt('extension_drivers',
|
||||
default=[],
|
||||
help=_("An ordered list of extension driver "
|
||||
"entrypoints to be loaded from the "
|
||||
"gbp.neutron.group_policy.extension_drivers "
|
||||
"namespace.")),
|
||||
]
|
||||
|
||||
|
||||
|
211
gbp/neutron/services/grouppolicy/extension_manager.py
Normal file
211
gbp/neutron/services/grouppolicy/extension_manager.py
Normal file
@ -0,0 +1,211 @@
|
||||
# Copyright (c) 2014 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.openstack.common import log
|
||||
from oslo.config import cfg
|
||||
import stevedore
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class ExtensionManager(stevedore.named.NamedExtensionManager):
|
||||
"""Manage extension drivers using drivers."""
|
||||
|
||||
def __init__(self):
|
||||
# Ordered list of extension drivers, defining
|
||||
# the order in which the drivers are called.
|
||||
self.ordered_ext_drivers = []
|
||||
|
||||
LOG.info(_("Configured extension driver names: %s"),
|
||||
cfg.CONF.group_policy.extension_drivers)
|
||||
super(ExtensionManager, self).__init__(
|
||||
'gbp.neutron.group_policy.extension_drivers',
|
||||
cfg.CONF.group_policy.extension_drivers,
|
||||
invoke_on_load=True,
|
||||
name_order=True)
|
||||
LOG.info(_("Loaded extension driver names: %s"), self.names())
|
||||
self._register_drivers()
|
||||
|
||||
def _register_drivers(self):
|
||||
"""Register all extension drivers.
|
||||
|
||||
This method should only be called once in the ExtensionManager
|
||||
constructor.
|
||||
"""
|
||||
for ext in self:
|
||||
self.ordered_ext_drivers.append(ext)
|
||||
LOG.info(_("Registered extension drivers: %s"),
|
||||
[driver.name for driver in self.ordered_ext_drivers])
|
||||
|
||||
def initialize(self):
|
||||
# Initialize each driver in the list.
|
||||
for driver in self.ordered_ext_drivers:
|
||||
LOG.info(_("Initializing extension driver '%s'"), driver.name)
|
||||
driver.obj.initialize()
|
||||
|
||||
def extension_aliases(self):
|
||||
exts = []
|
||||
for driver in self.ordered_ext_drivers:
|
||||
alias = driver.obj.extension_alias
|
||||
exts.append(alias)
|
||||
LOG.info(_("Got %(alias)s extension from driver '%(drv)s'"),
|
||||
{'alias': alias, 'drv': driver.name})
|
||||
return exts
|
||||
|
||||
def _call_on_ext_drivers(self, method_name, session, data, result):
|
||||
"""Helper method for calling a method across all extension drivers."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
try:
|
||||
getattr(driver.obj, method_name)(session, data, result)
|
||||
except Exception:
|
||||
LOG.exception(
|
||||
_("Extension driver '%(name)s' failed in %(method)s"),
|
||||
{'name': driver.name, 'method': method_name}
|
||||
)
|
||||
|
||||
def process_create_policy_target(self, session, data, result):
|
||||
"""Call all extension drivers during PT creation."""
|
||||
self._call_on_ext_drivers("process_create_policy_target",
|
||||
session, data, result)
|
||||
|
||||
def process_update_policy_target(self, session, data, result):
|
||||
"""Call all extension drivers during PT update."""
|
||||
self._call_on_ext_drivers("process_update_policy_target",
|
||||
session, data, result)
|
||||
|
||||
def extend_policy_target_dict(self, session, result):
|
||||
"""Call all extension drivers to extend PT dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_policy_target_dict(session, result)
|
||||
|
||||
def process_create_policy_target_group(self, session, data, result):
|
||||
"""Call all extension drivers during PTG creation."""
|
||||
self._call_on_ext_drivers("process_create_policy_target_group",
|
||||
session, data, result)
|
||||
|
||||
def process_update_policy_target_group(self, session, data, result):
|
||||
"""Call all extension drivers during PTG update."""
|
||||
self._call_on_ext_drivers("process_update_policy_target_group",
|
||||
session, data, result)
|
||||
|
||||
def extend_policy_target_group_dict(self, session, result):
|
||||
"""Call all extension drivers to extend PTG dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_policy_target_group_dict(session, result)
|
||||
|
||||
def process_create_l2_policy(self, session, data, result):
|
||||
"""Call all extension drivers during L2P creation."""
|
||||
self._call_on_ext_drivers("process_create_l2_policy",
|
||||
session, data, result)
|
||||
|
||||
def process_update_l2_policy(self, session, data, result):
|
||||
"""Call all extension drivers during L2P update."""
|
||||
self._call_on_ext_drivers("process_update_l2_policy",
|
||||
session, data, result)
|
||||
|
||||
def extend_l2_policy_dict(self, session, result):
|
||||
"""Call all extension drivers to extend L2P dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_l2_policy_dict(session, result)
|
||||
|
||||
def process_create_l3_policy(self, session, data, result):
|
||||
"""Call all extension drivers during L3P creation."""
|
||||
self._call_on_ext_drivers("process_create_l3_policy",
|
||||
session, data, result)
|
||||
|
||||
def process_update_l3_policy(self, session, data, result):
|
||||
"""Call all extension drivers during L3P update."""
|
||||
self._call_on_ext_drivers("process_update_l3_policy",
|
||||
session, data, result)
|
||||
|
||||
def extend_l3_policy_dict(self, session, result):
|
||||
"""Call all extension drivers to extend L3P dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_l3_policy_dict(session, result)
|
||||
|
||||
def process_create_policy_classifier(self, session, data, result):
|
||||
"""Call all extension drivers during PC creation."""
|
||||
self._call_on_ext_drivers("process_create_policy_classifier",
|
||||
session, data, result)
|
||||
|
||||
def process_update_policy_classifier(self, session, data, result):
|
||||
"""Call all extension drivers during PC update."""
|
||||
self._call_on_ext_drivers("process_update_policy_classifier",
|
||||
session, data, result)
|
||||
|
||||
def extend_policy_classifier_dict(self, session, result):
|
||||
"""Call all extension drivers to extend PC dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_policy_classifier_dict(session, result)
|
||||
|
||||
def process_create_policy_action(self, session, data, result):
|
||||
"""Call all extension drivers during PA creation."""
|
||||
self._call_on_ext_drivers("process_create_policy_action",
|
||||
session, data, result)
|
||||
|
||||
def process_update_policy_action(self, session, data, result):
|
||||
"""Call all extension drivers during PA update."""
|
||||
self._call_on_ext_drivers("process_update_policy_action",
|
||||
session, data, result)
|
||||
|
||||
def extend_policy_action_dict(self, session, result):
|
||||
"""Call all extension drivers to extend PA dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_policy_action_dict(session, result)
|
||||
|
||||
def process_create_policy_rule(self, session, data, result):
|
||||
"""Call all extension drivers during PR creation."""
|
||||
self._call_on_ext_drivers("process_create_policy_rule",
|
||||
session, data, result)
|
||||
|
||||
def process_update_policy_rule(self, session, data, result):
|
||||
"""Call all extension drivers during PR update."""
|
||||
self._call_on_ext_drivers("process_update_policy_rule",
|
||||
session, data, result)
|
||||
|
||||
def extend_policy_rule_dict(self, session, result):
|
||||
"""Call all extension drivers to extend PR dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_policy_rule_dict(session, result)
|
||||
|
||||
def process_create_policy_rule_set(self, session, data, result):
|
||||
"""Call all extension drivers during PRS creation."""
|
||||
self._call_on_ext_drivers("process_create_policy_rule_set",
|
||||
session, data, result)
|
||||
|
||||
def process_update_policy_rule_set(self, session, data, result):
|
||||
"""Call all extension drivers during PRS update."""
|
||||
self._call_on_ext_drivers("process_update_policy_rule_set",
|
||||
session, data, result)
|
||||
|
||||
def extend_policy_rule_set_dict(self, session, result):
|
||||
"""Call all extension drivers to extend PRS dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_policy_rule_set_dict(session, result)
|
||||
|
||||
def process_create_network_service_policy(self, session, data, result):
|
||||
"""Call all extension drivers during NSP creation."""
|
||||
self._call_on_ext_drivers("process_create_network_service_policy",
|
||||
session, data, result)
|
||||
|
||||
def process_update_network_service_policy(self, session, data, result):
|
||||
"""Call all extension drivers during NSP update."""
|
||||
self._call_on_ext_drivers("process_update_network_service_policy",
|
||||
session, data, result)
|
||||
|
||||
def extend_network_service_policy_dict(self, session, result):
|
||||
"""Call all extension drivers to extend NSP dictionary."""
|
||||
for driver in self.ordered_ext_drivers:
|
||||
driver.obj.extend_network_service_policy_dict(session, result)
|
@ -842,3 +842,409 @@ class PolicyDriver(object):
|
||||
delete it.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ExtensionDriver(object):
|
||||
"""Define stable abstract interface for Group Policy extension drivers.
|
||||
|
||||
An extension driver extends the core resources implemented by the
|
||||
group policy service plugin with additional attributes. Methods
|
||||
that process create and update operations for these resources
|
||||
validate and persist values for extended attributes supplied
|
||||
through the API. Other methods extend the resource dictionaries
|
||||
returned from the API operations with the values of the extended
|
||||
attributes.
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def initialize(self):
|
||||
"""Perform driver initialization.
|
||||
|
||||
Called after all drivers have been loaded and the database has
|
||||
been initialized. No abstract methods defined below will be
|
||||
called prior to this method being called.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abc.abstractproperty
|
||||
def extension_alias(self):
|
||||
"""Supported extension alias.
|
||||
|
||||
Return the alias identifying the Group Policy API extension
|
||||
supported by this driver.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_policy_target(self, session, data, result):
|
||||
"""Process extended attributes for policy_target creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_target data
|
||||
:param result: policy_target dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended policy_target attributes defined by this
|
||||
driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_policy_target(self, session, data, result):
|
||||
"""Process extended attributes for policy_target update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_target data
|
||||
:param result: policy_target dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended policy_target attributes defined by this
|
||||
driver. Extended attribute values, whether updated or not,
|
||||
must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_policy_target_dict(self, session, result):
|
||||
"""Add extended attributes to policy_target dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: policy_target dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a policy_target
|
||||
dictionary to be used for mechanism driver calls and/or
|
||||
returned as the result of a policy_target operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_policy_target_group(self, session, data, result):
|
||||
"""Process extended attributes for policy_target_group creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_target_group data
|
||||
:param result: policy_target_group dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended policy_target_group attributes defined by
|
||||
this driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_policy_target_group(self, session, data, result):
|
||||
"""Process extended attributes for policy_target_group update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_target_group data
|
||||
:param result: policy_target_group dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended policy_target_group attributes defined by
|
||||
this driver. Extended attribute values, whether updated or
|
||||
not, must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_policy_target_group_dict(self, session, result):
|
||||
"""Add extended attributes to policy_target_group dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: policy_target_group dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a
|
||||
policy_target_group dictionary to be used for mechanism driver
|
||||
calls and/or returned as the result of a policy_target_group
|
||||
operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_l2_policy(self, session, data, result):
|
||||
"""Process extended attributes for l2_policy creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming l2_policy data
|
||||
:param result: l2_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended l2_policy attributes defined by this
|
||||
driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_l2_policy(self, session, data, result):
|
||||
"""Process extended attributes for l2_policy update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming l2_policy data
|
||||
:param result: l2_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended l2_policy attributes defined by this
|
||||
driver. Extended attribute values, whether updated or not,
|
||||
must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_l2_policy_dict(self, session, result):
|
||||
"""Add extended attributes to l2_policy dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: l2_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a l2_policy
|
||||
dictionary to be used for mechanism driver calls and/or
|
||||
returned as the result of a l2_policy operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_l3_policy(self, session, data, result):
|
||||
"""Process extended attributes for l3_policy creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming l3_policy data
|
||||
:param result: l3_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended l3_policy attributes defined by this
|
||||
driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_l3_policy(self, session, data, result):
|
||||
"""Process extended attributes for l3_policy update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming l3_policy data
|
||||
:param result: l3_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended l3_policy attributes defined by this
|
||||
driver. Extended attribute values, whether updated or not,
|
||||
must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_l3_policy_dict(self, session, result):
|
||||
"""Add extended attributes to l3_policy dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: l3_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a l3_policy
|
||||
dictionary to be used for mechanism driver calls and/or
|
||||
returned as the result of a l3_policy operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_policy_classifier(self, session, data, result):
|
||||
"""Process extended attributes for policy_classifier creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_classifier data
|
||||
:param result: policy_classifier dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended policy_classifier attributes defined by
|
||||
this driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_policy_classifier(self, session, data, result):
|
||||
"""Process extended attributes for policy_classifier update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_classifier data
|
||||
:param result: policy_classifier dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended policy_classifier attributes defined by
|
||||
this driver. Extended attribute values, whether updated or
|
||||
not, must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_policy_classifier_dict(self, session, result):
|
||||
"""Add extended attributes to policy_classifier dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: policy_classifier dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a
|
||||
policy_classifier dictionary to be used for mechanism driver
|
||||
calls and/or returned as the result of a policy_classifier
|
||||
operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_policy_action(self, session, data, result):
|
||||
"""Process extended attributes for policy_action creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_action data
|
||||
:param result: policy_action dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended policy_action attributes defined by this
|
||||
driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_policy_action(self, session, data, result):
|
||||
"""Process extended attributes for policy_action update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_action data
|
||||
:param result: policy_action dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended policy_action attributes defined by this
|
||||
driver. Extended attribute values, whether updated or not,
|
||||
must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_policy_action_dict(self, session, result):
|
||||
"""Add extended attributes to policy_action dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: policy_action dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a policy_action
|
||||
dictionary to be used for mechanism driver calls and/or
|
||||
returned as the result of a policy_action operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_policy_rule(self, session, data, result):
|
||||
"""Process extended attributes for policy_rule creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_rule data
|
||||
:param result: policy_rule dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended policy_rule attributes defined by this
|
||||
driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_policy_rule(self, session, data, result):
|
||||
"""Process extended attributes for policy_rule update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_rule data
|
||||
:param result: policy_rule dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended policy_rule attributes defined by this
|
||||
driver. Extended attribute values, whether updated or not,
|
||||
must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_policy_rule_dict(self, session, result):
|
||||
"""Add extended attributes to policy_rule dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: policy_rule dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a policy_rule
|
||||
dictionary to be used for mechanism driver calls and/or
|
||||
returned as the result of a policy_rule operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_policy_rule_set(self, session, data, result):
|
||||
"""Process extended attributes for policy_rule_set creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_rule_set data
|
||||
:param result: policy_rule_set dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended policy_rule_set attributes defined by
|
||||
this driver. Extended attribute values must also be added to
|
||||
result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_policy_rule_set(self, session, data, result):
|
||||
"""Process extended attributes for policy_rule_set update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming policy_rule_set data
|
||||
:param result: policy_rule_set dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended policy_rule_set attributes defined by this
|
||||
driver. Extended attribute values, whether updated or not,
|
||||
must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_policy_rule_set_dict(self, session, result):
|
||||
"""Add extended attributes to policy_rule_set dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: policy_rule_set dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a
|
||||
policy_rule_set dictionary to be used for mechanism driver
|
||||
calls and/or returned as the result of a policy_rule_set
|
||||
operation.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_create_network_service_policy(self, session, data, result):
|
||||
"""Process extended attributes for network_service_policy creation.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming network_service_policy data
|
||||
:param result: network_service_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
persist any extended network_service_policy attributes defined
|
||||
by this driver. Extended attribute values must also be added
|
||||
to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def process_update_network_service_policy(self, session, data, result):
|
||||
"""Process extended attributes for network_service_policy update.
|
||||
|
||||
:param session: database session
|
||||
:param data: dictionary of incoming network_service_policy data
|
||||
:param result: network_service_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to validate and
|
||||
update any extended network_service_policy attributes defined by this
|
||||
driver. Extended attribute values, whether updated or not,
|
||||
must also be added to result.
|
||||
"""
|
||||
pass
|
||||
|
||||
def extend_network_service_policy_dict(self, session, result):
|
||||
"""Add extended attributes to network_service_policy dictionary.
|
||||
|
||||
:param session: database session
|
||||
:param result: network_service_policy dictionary to extend
|
||||
|
||||
Called inside transaction context on session to add any
|
||||
extended attributes defined by this driver to a
|
||||
network_service_policy dictionary to be used for mechanism
|
||||
driver calls and/or returned as the result of a
|
||||
network_service_policy operation.
|
||||
"""
|
||||
pass
|
||||
|
@ -16,6 +16,7 @@ from neutron.openstack.common import log as logging
|
||||
|
||||
from gbp.neutron.db.grouppolicy import group_policy_mapping_db
|
||||
from gbp.neutron.services.grouppolicy.common import exceptions as gp_exc
|
||||
from gbp.neutron.services.grouppolicy import extension_manager as ext_manager
|
||||
from gbp.neutron.services.grouppolicy import group_policy_context as p_context
|
||||
from gbp.neutron.services.grouppolicy import policy_driver_manager as manager
|
||||
|
||||
@ -31,11 +32,21 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
Most DB related works are implemented in class
|
||||
db_group_policy_mapping.GroupPolicyMappingDbMixin.
|
||||
"""
|
||||
supported_extension_aliases = ["group-policy", "group-policy-mapping"]
|
||||
_supported_extension_aliases = ["group-policy", "group-policy-mapping"]
|
||||
|
||||
@property
|
||||
def supported_extension_aliases(self):
|
||||
if not hasattr(self, '_aliases'):
|
||||
aliases = self._supported_extension_aliases[:]
|
||||
aliases += self.extension_manager.extension_aliases()
|
||||
self._aliases = aliases
|
||||
return self._aliases
|
||||
|
||||
def __init__(self):
|
||||
self.extension_manager = ext_manager.ExtensionManager()
|
||||
self.policy_driver_manager = manager.PolicyDriverManager()
|
||||
super(GroupPolicyPlugin, self).__init__()
|
||||
self.extension_manager.initialize()
|
||||
self.policy_driver_manager.initialize()
|
||||
|
||||
@log.log
|
||||
@ -44,6 +55,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin,
|
||||
self).create_policy_target(context, policy_target)
|
||||
self.extension_manager.process_create_policy_target(
|
||||
session, policy_target, result)
|
||||
policy_context = p_context.PolicyTargetContext(self, context,
|
||||
result)
|
||||
self.policy_driver_manager.create_policy_target_precommit(
|
||||
@ -65,12 +78,13 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
def update_policy_target(self, context, policy_target_id, policy_target):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
original_policy_target = super(
|
||||
GroupPolicyPlugin, self).get_policy_target(context,
|
||||
policy_target_id)
|
||||
original_policy_target = self.get_policy_target(context,
|
||||
policy_target_id)
|
||||
updated_policy_target = super(
|
||||
GroupPolicyPlugin, self).update_policy_target(
|
||||
context, policy_target_id, policy_target)
|
||||
self.extension_manager.process_update_policy_target(
|
||||
session, policy_target, updated_policy_target)
|
||||
policy_context = p_context.PolicyTargetContext(
|
||||
self, context, updated_policy_target,
|
||||
original_policy_target=original_policy_target)
|
||||
@ -102,6 +116,26 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
"failed, deleting policy_rule_set '%s'"),
|
||||
policy_target_id)
|
||||
|
||||
def get_policy_target(self, context, policy_target_id, fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_policy_target(
|
||||
context, policy_target_id, None)
|
||||
self.extension_manager.extend_policy_target_dict(session, result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_policy_targets(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_policy_targets(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_policy_target_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_policy_target_group(self, context, policy_target_group):
|
||||
session = context.session
|
||||
@ -109,6 +143,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
result = super(GroupPolicyPlugin,
|
||||
self).create_policy_target_group(
|
||||
context, policy_target_group)
|
||||
self.extension_manager.process_create_policy_target_group(
|
||||
session, policy_target_group, result)
|
||||
policy_context = p_context.PolicyTargetGroupContext(
|
||||
self, context, result)
|
||||
self.policy_driver_manager.create_policy_target_group_precommit(
|
||||
@ -131,12 +167,13 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
policy_target_group):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
original_policy_target_group = super(
|
||||
GroupPolicyPlugin, self).get_policy_target_group(
|
||||
original_policy_target_group = self.get_policy_target_group(
|
||||
context, policy_target_group_id)
|
||||
updated_policy_target_group = super(
|
||||
GroupPolicyPlugin, self).update_policy_target_group(
|
||||
context, policy_target_group_id, policy_target_group)
|
||||
self.extension_manager.process_update_policy_target_group(
|
||||
session, policy_target_group, updated_policy_target_group)
|
||||
policy_context = p_context.PolicyTargetGroupContext(
|
||||
self, context, updated_policy_target_group,
|
||||
original_policy_target_group=original_policy_target_group)
|
||||
@ -173,12 +210,36 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
"failed, deleting policy_target_group '%s'"),
|
||||
policy_target_group_id)
|
||||
|
||||
def get_policy_target_group(self, context, policy_target_group_id,
|
||||
fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_policy_target_group(
|
||||
context, policy_target_group_id, None)
|
||||
self.extension_manager.extend_policy_target_group_dict(session,
|
||||
result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_policy_target_groups(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_policy_target_groups(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_policy_target_group_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_l2_policy(self, context, l2_policy):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin,
|
||||
self).create_l2_policy(context, l2_policy)
|
||||
self.extension_manager.process_create_l2_policy(
|
||||
session, l2_policy, result)
|
||||
policy_context = p_context.L2PolicyContext(self, context, result)
|
||||
self.policy_driver_manager.create_l2_policy_precommit(
|
||||
policy_context)
|
||||
@ -198,12 +259,12 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
def update_l2_policy(self, context, l2_policy_id, l2_policy):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
original_l2_policy = super(GroupPolicyPlugin,
|
||||
self).get_l2_policy(context,
|
||||
l2_policy_id)
|
||||
original_l2_policy = self.get_l2_policy(context, l2_policy_id)
|
||||
updated_l2_policy = super(GroupPolicyPlugin,
|
||||
self).update_l2_policy(
|
||||
context, l2_policy_id, l2_policy)
|
||||
self.extension_manager.process_update_l2_policy(
|
||||
session, l2_policy, updated_l2_policy)
|
||||
policy_context = p_context.L2PolicyContext(
|
||||
self, context, updated_l2_policy,
|
||||
original_l2_policy=original_l2_policy)
|
||||
@ -234,6 +295,26 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
LOG.error(_("delete_l2_policy_postcommit "
|
||||
" failed, deleting l2_policy '%s'"), l2_policy_id)
|
||||
|
||||
def get_l2_policy(self, context, l2_policy_id, fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_l2_policy(
|
||||
context, l2_policy_id, None)
|
||||
self.extension_manager.extend_l2_policy_dict(session, result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_l2_policies(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_l2_policies(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_l2_policy_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_network_service_policy(self, context, network_service_policy):
|
||||
session = context.session
|
||||
@ -241,6 +322,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
result = super(GroupPolicyPlugin,
|
||||
self).create_network_service_policy(
|
||||
context, network_service_policy)
|
||||
self.extension_manager.process_create_network_service_policy(
|
||||
session, network_service_policy, result)
|
||||
policy_context = p_context.NetworkServicePolicyContext(
|
||||
self, context, result)
|
||||
pdm = self.policy_driver_manager
|
||||
@ -270,6 +353,9 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
updated_network_service_policy = super(
|
||||
GroupPolicyPlugin, self).update_network_service_policy(
|
||||
context, network_service_policy_id, network_service_policy)
|
||||
self.extension_manager.process_update_network_service_policy(
|
||||
session, network_service_policy,
|
||||
updated_network_service_policy)
|
||||
policy_context = p_context.NetworkServicePolicyContext(
|
||||
self, context, updated_network_service_policy,
|
||||
original_network_service_policy=
|
||||
@ -304,12 +390,37 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
" failed, deleting network_service_policy '%s'"),
|
||||
network_service_policy_id)
|
||||
|
||||
def get_network_service_policy(self, context, network_service_policy_id,
|
||||
fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_network_service_policy(
|
||||
context, network_service_policy_id, None)
|
||||
self.extension_manager.extend_network_service_policy_dict(session,
|
||||
result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_network_service_policies(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin,
|
||||
self).get_network_service_policies(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_network_service_policy_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_l3_policy(self, context, l3_policy):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin,
|
||||
self).create_l3_policy(context, l3_policy)
|
||||
self.extension_manager.process_create_l3_policy(
|
||||
session, l3_policy, result)
|
||||
policy_context = p_context.L3PolicyContext(self, context,
|
||||
result)
|
||||
self.policy_driver_manager.create_l3_policy_precommit(
|
||||
@ -330,12 +441,12 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
def update_l3_policy(self, context, l3_policy_id, l3_policy):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
original_l3_policy = super(GroupPolicyPlugin,
|
||||
self).get_l3_policy(context,
|
||||
l3_policy_id)
|
||||
original_l3_policy = self.get_l3_policy(context, l3_policy_id)
|
||||
updated_l3_policy = super(
|
||||
GroupPolicyPlugin, self).update_l3_policy(
|
||||
context, l3_policy_id, l3_policy)
|
||||
self.extension_manager.process_update_l3_policy(
|
||||
session, l3_policy, updated_l3_policy)
|
||||
policy_context = p_context.L3PolicyContext(
|
||||
self, context, updated_l3_policy,
|
||||
original_l3_policy=original_l3_policy)
|
||||
@ -371,6 +482,26 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
" failed, deleting l3_policy '%s'"), l3_policy_id)
|
||||
return True
|
||||
|
||||
def get_l3_policy(self, context, l3_policy_id, fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_l3_policy(
|
||||
context, l3_policy_id, None)
|
||||
self.extension_manager.extend_l3_policy_dict(session, result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_l3_policies(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_l3_policies(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_l3_policy_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_policy_classifier(self, context, policy_classifier):
|
||||
session = context.session
|
||||
@ -378,6 +509,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
result = super(
|
||||
GroupPolicyPlugin, self).create_policy_classifier(
|
||||
context, policy_classifier)
|
||||
self.extension_manager.process_create_policy_classifier(
|
||||
session, policy_classifier, result)
|
||||
policy_context = p_context.PolicyClassifierContext(self, context,
|
||||
result)
|
||||
self.policy_driver_manager.create_policy_classifier_precommit(
|
||||
@ -404,6 +537,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
updated_policy_classifier = super(
|
||||
GroupPolicyPlugin, self).update_policy_classifier(
|
||||
context, id, policy_classifier)
|
||||
self.extension_manager.process_update_policy_classifier(
|
||||
session, policy_classifier, updated_policy_classifier)
|
||||
policy_context = p_context.PolicyClassifierContext(
|
||||
self, context, updated_policy_classifier,
|
||||
original_policy_classifier=original_policy_classifier)
|
||||
@ -435,12 +570,36 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
"policy_driver_manager.delete_policy_classifier_postcommit"
|
||||
" failed, deleting policy_classifier '%s'"), id)
|
||||
|
||||
def get_policy_classifier(self, context, policy_classifier_id,
|
||||
fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_policy_classifier(
|
||||
context, policy_classifier_id, None)
|
||||
self.extension_manager.extend_policy_classifier_dict(session,
|
||||
result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_policy_classifiers(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_policy_classifiers(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_policy_classifier_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_policy_action(self, context, policy_action):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin,
|
||||
self).create_policy_action(context, policy_action)
|
||||
self.extension_manager.process_create_policy_action(
|
||||
session, policy_action, result)
|
||||
policy_context = p_context.PolicyActionContext(self, context,
|
||||
result)
|
||||
self.policy_driver_manager.create_policy_action_precommit(
|
||||
@ -467,6 +626,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
updated_policy_action = super(
|
||||
GroupPolicyPlugin, self).update_policy_action(context, id,
|
||||
policy_action)
|
||||
self.extension_manager.process_update_policy_action(
|
||||
session, policy_action, updated_policy_action)
|
||||
policy_context = p_context.PolicyActionContext(
|
||||
self, context, updated_policy_action,
|
||||
original_policy_action=original_policy_action)
|
||||
@ -497,6 +658,26 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
"policy_driver_manager.delete_policy_action_postcommit "
|
||||
"failed, deleting policy_action '%s'"), id)
|
||||
|
||||
def get_policy_action(self, context, policy_action_id, fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_policy_action(
|
||||
context, policy_action_id, None)
|
||||
self.extension_manager.extend_policy_action_dict(session, result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_policy_actions(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_policy_actions(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_policy_action_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_policy_rule(self, context, policy_rule):
|
||||
session = context.session
|
||||
@ -504,6 +685,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
result = super(
|
||||
GroupPolicyPlugin, self).create_policy_rule(
|
||||
context, policy_rule)
|
||||
self.extension_manager.process_create_policy_rule(
|
||||
session, policy_rule, result)
|
||||
policy_context = p_context.PolicyRuleContext(self, context,
|
||||
result)
|
||||
self.policy_driver_manager.create_policy_rule_precommit(
|
||||
@ -530,6 +713,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
updated_policy_rule = super(
|
||||
GroupPolicyPlugin, self).update_policy_rule(
|
||||
context, id, policy_rule)
|
||||
self.extension_manager.process_update_policy_rule(
|
||||
session, policy_rule, updated_policy_rule)
|
||||
policy_context = p_context.PolicyRuleContext(
|
||||
self, context, updated_policy_rule,
|
||||
original_policy_rule=original_policy_rule)
|
||||
@ -561,6 +746,26 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
"policy_driver_manager.delete_policy_rule_postcommit"
|
||||
" failed, deleting policy_rule '%s'"), id)
|
||||
|
||||
def get_policy_rule(self, context, policy_rule_id, fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_policy_rule(
|
||||
context, policy_rule_id, None)
|
||||
self.extension_manager.extend_policy_rule_dict(session, result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_policy_rules(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_policy_rules(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_policy_rule_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
||||
@log.log
|
||||
def create_policy_rule_set(self, context, policy_rule_set):
|
||||
session = context.session
|
||||
@ -568,6 +773,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
result = super(GroupPolicyPlugin,
|
||||
self).create_policy_rule_set(
|
||||
context, policy_rule_set)
|
||||
self.extension_manager.process_create_policy_rule_set(
|
||||
session, policy_rule_set, result)
|
||||
policy_context = p_context.PolicyRuleSetContext(
|
||||
self, context, result)
|
||||
self.policy_driver_manager.create_policy_rule_set_precommit(
|
||||
@ -594,6 +801,8 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
updated_policy_rule_set = super(
|
||||
GroupPolicyPlugin, self).update_policy_rule_set(
|
||||
context, id, policy_rule_set)
|
||||
self.extension_manager.process_update_policy_rule_set(
|
||||
session, policy_rule_set, updated_policy_rule_set)
|
||||
policy_context = p_context.PolicyRuleSetContext(
|
||||
self, context, updated_policy_rule_set,
|
||||
original_policy_rule_set=original_policy_rule_set)
|
||||
@ -623,3 +832,23 @@ class GroupPolicyPlugin(group_policy_mapping_db.GroupPolicyMappingDbPlugin):
|
||||
LOG.error(_(
|
||||
"policy_driver_manager.delete_policy_rule_set_postcommit "
|
||||
"failed, deleting policy_rule_set '%s'"), id)
|
||||
|
||||
def get_policy_rule_set(self, context, policy_rule_set_id, fields=None):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(GroupPolicyPlugin, self).get_policy_rule_set(
|
||||
context, policy_rule_set_id, None)
|
||||
self.extension_manager.extend_policy_rule_set_dict(session, result)
|
||||
return self._fields(result, fields)
|
||||
|
||||
def get_policy_rule_sets(self, context, filters=None, fields=None,
|
||||
sorts=None, limit=None, marker=None,
|
||||
page_reverse=False):
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
results = super(GroupPolicyPlugin, self).get_policy_rule_sets(
|
||||
context, filters, None, sorts, limit, marker, page_reverse)
|
||||
for result in results:
|
||||
self.extension_manager.extend_policy_rule_set_dict(
|
||||
session, result)
|
||||
return [self._fields(result, fields) for result in results]
|
||||
|
@ -0,0 +1,113 @@
|
||||
# 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
|
||||
from neutron.api.v2 import attributes as attr
|
||||
|
||||
from gbp.neutron.extensions import group_policy as gp
|
||||
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
gp.POLICY_TARGETS: {
|
||||
'pt_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.POLICY_TARGET_GROUPS: {
|
||||
'ptg_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.L2_POLICIES: {
|
||||
'l2p_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.L3_POLICIES: {
|
||||
'l3p_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.POLICY_CLASSIFIERS: {
|
||||
'pc_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.POLICY_ACTIONS: {
|
||||
'pa_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.POLICY_RULES: {
|
||||
'pr_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.POLICY_RULE_SETS: {
|
||||
'prs_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
gp.NETWORK_SERVICE_POLICIES: {
|
||||
'nsp_extension': {'allow_post': True,
|
||||
'allow_put': True,
|
||||
'default': attr.ATTR_NOT_SPECIFIED,
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class Test_extension(extensions.ExtensionDescriptor):
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "group policy test extension"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "test_extension"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return _("Adds test attributes to group policy resources.")
|
||||
|
||||
@classmethod
|
||||
def get_namespace(cls):
|
||||
return ("http://docs.openstack.org/ext/neutron/grouppolicy/test/"
|
||||
"test_extension/api/v1.0")
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2014-10-24T10:00:00-00:00"
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
else:
|
||||
return {}
|
@ -0,0 +1,679 @@
|
||||
# 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.
|
||||
|
||||
import sqlalchemy as sa
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.db import model_base
|
||||
|
||||
from gbp.neutron.services.grouppolicy import config
|
||||
from gbp.neutron.services.grouppolicy import group_policy_driver_api as api
|
||||
from gbp.neutron.tests.unit.services.grouppolicy import extensions as test_ext
|
||||
from gbp.neutron.tests.unit.services.grouppolicy import test_grouppolicy_plugin
|
||||
|
||||
|
||||
class ExtensionDriverTestCase(
|
||||
test_grouppolicy_plugin.GroupPolicyPluginTestCase):
|
||||
|
||||
_extension_drivers = ['test']
|
||||
|
||||
def setUp(self):
|
||||
config.cfg.CONF.set_override('extension_drivers',
|
||||
self._extension_drivers,
|
||||
group='group_policy')
|
||||
super(ExtensionDriverTestCase, self).setUp()
|
||||
|
||||
def test_pt_attr(self):
|
||||
# Test create with default value.
|
||||
pt = self.create_policy_target()
|
||||
pt_id = pt['policy_target']['id']
|
||||
val = pt['policy_target']['pt_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('policy_targets', pt_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target']['pt_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('policy_targets')
|
||||
val = res['policy_targets'][0]['pt_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
pt = self.create_policy_target(pt_extension="abc")
|
||||
pt_id = pt['policy_target']['id']
|
||||
val = pt['policy_target']['pt_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('policy_targets', pt_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target']['pt_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'policy_target': {'pt_extension': "def"}}
|
||||
req = self.new_update_request('policy_targets', data, pt_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target']['pt_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('policy_targets', pt_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target']['pt_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_ptg_attr(self):
|
||||
# Test create with default value.
|
||||
ptg = self.create_policy_target_group()
|
||||
ptg_id = ptg['policy_target_group']['id']
|
||||
val = ptg['policy_target_group']['ptg_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('policy_target_groups', ptg_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target_group']['ptg_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('policy_target_groups')
|
||||
val = res['policy_target_groups'][0]['ptg_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
ptg = self.create_policy_target_group(ptg_extension="abc")
|
||||
ptg_id = ptg['policy_target_group']['id']
|
||||
val = ptg['policy_target_group']['ptg_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('policy_target_groups', ptg_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target_group']['ptg_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'policy_target_group': {'ptg_extension': "def"}}
|
||||
req = self.new_update_request('policy_target_groups', data, ptg_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target_group']['ptg_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('policy_target_groups', ptg_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_target_group']['ptg_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_l2p_attr(self):
|
||||
# Test create with default value.
|
||||
l2p = self.create_l2_policy()
|
||||
l2p_id = l2p['l2_policy']['id']
|
||||
val = l2p['l2_policy']['l2p_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('l2_policies', l2p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l2_policy']['l2p_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('l2_policies')
|
||||
val = res['l2_policies'][0]['l2p_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
l2p = self.create_l2_policy(l2p_extension="abc")
|
||||
l2p_id = l2p['l2_policy']['id']
|
||||
val = l2p['l2_policy']['l2p_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('l2_policies', l2p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l2_policy']['l2p_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'l2_policy': {'l2p_extension': "def"}}
|
||||
req = self.new_update_request('l2_policies', data, l2p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l2_policy']['l2p_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('l2_policies', l2p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l2_policy']['l2p_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_l3p_attr(self):
|
||||
# Test create with default value.
|
||||
l3p = self.create_l3_policy()
|
||||
l3p_id = l3p['l3_policy']['id']
|
||||
val = l3p['l3_policy']['l3p_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('l3_policies', l3p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l3_policy']['l3p_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('l3_policies')
|
||||
val = res['l3_policies'][0]['l3p_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
l3p = self.create_l3_policy(l3p_extension="abc")
|
||||
l3p_id = l3p['l3_policy']['id']
|
||||
val = l3p['l3_policy']['l3p_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('l3_policies', l3p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l3_policy']['l3p_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'l3_policy': {'l3p_extension': "def"}}
|
||||
req = self.new_update_request('l3_policies', data, l3p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l3_policy']['l3p_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('l3_policies', l3p_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['l3_policy']['l3p_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_pc_attr(self):
|
||||
# Test create with default value.
|
||||
pc = self.create_policy_classifier()
|
||||
pc_id = pc['policy_classifier']['id']
|
||||
val = pc['policy_classifier']['pc_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('policy_classifiers', pc_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_classifier']['pc_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('policy_classifiers')
|
||||
val = res['policy_classifiers'][0]['pc_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
pc = self.create_policy_classifier(pc_extension="abc")
|
||||
pc_id = pc['policy_classifier']['id']
|
||||
val = pc['policy_classifier']['pc_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('policy_classifiers', pc_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_classifier']['pc_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'policy_classifier': {'pc_extension': "def"}}
|
||||
req = self.new_update_request('policy_classifiers', data, pc_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_classifier']['pc_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('policy_classifiers', pc_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_classifier']['pc_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_pa_attr(self):
|
||||
# Test create with default value.
|
||||
pa = self.create_policy_action()
|
||||
pa_id = pa['policy_action']['id']
|
||||
val = pa['policy_action']['pa_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('policy_actions', pa_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_action']['pa_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('policy_actions')
|
||||
val = res['policy_actions'][0]['pa_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
pa = self.create_policy_action(pa_extension="abc")
|
||||
pa_id = pa['policy_action']['id']
|
||||
val = pa['policy_action']['pa_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('policy_actions', pa_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_action']['pa_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'policy_action': {'pa_extension': "def"}}
|
||||
req = self.new_update_request('policy_actions', data, pa_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_action']['pa_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('policy_actions', pa_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_action']['pa_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_pr_attr(self):
|
||||
# Create necessary parameters.
|
||||
classifier = self.create_policy_classifier(
|
||||
name="class1", protocol="tcp", direction="out",
|
||||
port_range="50:100")
|
||||
classifier_id = classifier['policy_classifier']['id']
|
||||
|
||||
# Test create with default value.
|
||||
pr = self.create_policy_rule(policy_classifier_id=classifier_id)
|
||||
pr_id = pr['policy_rule']['id']
|
||||
val = pr['policy_rule']['pr_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('policy_rules', pr_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule']['pr_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('policy_rules')
|
||||
val = res['policy_rules'][0]['pr_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
pr = self.create_policy_rule(policy_classifier_id=classifier_id,
|
||||
pr_extension="abc")
|
||||
pr_id = pr['policy_rule']['id']
|
||||
val = pr['policy_rule']['pr_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('policy_rules', pr_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule']['pr_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'policy_rule': {'pr_extension': "def"}}
|
||||
req = self.new_update_request('policy_rules', data, pr_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule']['pr_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('policy_rules', pr_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule']['pr_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_prs_attr(self):
|
||||
# Test create with default value.
|
||||
prs = self.create_policy_rule_set(policy_rules=[])
|
||||
prs_id = prs['policy_rule_set']['id']
|
||||
val = prs['policy_rule_set']['prs_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('policy_rule_sets', prs_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule_set']['prs_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('policy_rule_sets')
|
||||
val = res['policy_rule_sets'][0]['prs_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
prs = self.create_policy_rule_set(policy_rules=[], prs_extension="abc")
|
||||
prs_id = prs['policy_rule_set']['id']
|
||||
val = prs['policy_rule_set']['prs_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('policy_rule_sets', prs_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule_set']['prs_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'policy_rule_set': {'prs_extension': "def"}}
|
||||
req = self.new_update_request('policy_rule_sets', data, prs_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule_set']['prs_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('policy_rule_sets', prs_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['policy_rule_set']['prs_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
def test_nsp_attr(self):
|
||||
# Test create with default value.
|
||||
nsp = self.create_network_service_policy()
|
||||
nsp_id = nsp['network_service_policy']['id']
|
||||
val = nsp['network_service_policy']['nsp_extension']
|
||||
self.assertEqual("", val)
|
||||
req = self.new_show_request('network_service_policies', nsp_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['network_service_policy']['nsp_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test list.
|
||||
res = self._list('network_service_policies')
|
||||
val = res['network_service_policies'][0]['nsp_extension']
|
||||
self.assertEqual("", val)
|
||||
|
||||
# Test create with explict value.
|
||||
nsp = self.create_network_service_policy(nsp_extension="abc")
|
||||
nsp_id = nsp['network_service_policy']['id']
|
||||
val = nsp['network_service_policy']['nsp_extension']
|
||||
self.assertEqual("abc", val)
|
||||
req = self.new_show_request('network_service_policies', nsp_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['network_service_policy']['nsp_extension']
|
||||
self.assertEqual("abc", val)
|
||||
|
||||
# Test update.
|
||||
data = {'network_service_policy': {'nsp_extension': "def"}}
|
||||
req = self.new_update_request('network_service_policies', data, nsp_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['network_service_policy']['nsp_extension']
|
||||
self.assertEqual("def", val)
|
||||
req = self.new_show_request('network_service_policies', nsp_id)
|
||||
res = self.deserialize(self.fmt, req.get_response(self.ext_api))
|
||||
val = res['network_service_policy']['nsp_extension']
|
||||
self.assertEqual("def", val)
|
||||
|
||||
|
||||
class TestPolicyTargetExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_policy_target_extension'
|
||||
pt_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_policy_targets.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestPolicyTargetGroupExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_policy_target_group_extension'
|
||||
ptg_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_policy_target_groups.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestL2PolicyExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_l2_policy_extension'
|
||||
l2p_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_l2_policies.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestL3PolicyExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_l3_policy_extension'
|
||||
l3p_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_l3_policies.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestPolicyClassifierExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_policy_classifier_extension'
|
||||
pc_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_policy_classifiers.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestPolicyActionExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_policy_action_extension'
|
||||
pa_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_policy_actions.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestPolicyRuleExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_policy_rule_extension'
|
||||
pr_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_policy_rules.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestPolicyRuleSetExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_policy_rule_set_extension'
|
||||
prs_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_policy_rule_sets.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestNetworkServicePolicyExtension(model_base.BASEV2):
|
||||
__tablename__ = 'test_network_service_policy_extension'
|
||||
nsp_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('gp_network_service_policies.id',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True)
|
||||
value = sa.Column(sa.String(64))
|
||||
|
||||
|
||||
class TestExtensionDriver(api.ExtensionDriver):
|
||||
_supported_extension_alias = 'test_extension'
|
||||
|
||||
def initialize(self):
|
||||
# self.network_extension = 'Test_Network_Extension'
|
||||
# self.subnet_extension = 'Test_Subnet_Extension'
|
||||
# self.port_extension = 'Test_Port_Extension'
|
||||
extensions.append_api_extensions_path(test_ext.__path__)
|
||||
|
||||
@property
|
||||
def extension_alias(self):
|
||||
return self._supported_extension_alias
|
||||
|
||||
def process_create_policy_target(self, session, data, result):
|
||||
value = data['policy_target']['pt_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestPolicyTargetExtension(pt_id=result['id'],
|
||||
value=value)
|
||||
session.add(record)
|
||||
result['pt_extension'] = value
|
||||
|
||||
def process_update_policy_target(self, session, data, result):
|
||||
record = (session.query(TestPolicyTargetExtension).
|
||||
filter_by(pt_id=result['id']).
|
||||
one())
|
||||
value = data['policy_target'].get('pt_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['pt_extension'] = record.value
|
||||
|
||||
def extend_policy_target_dict(self, session, result):
|
||||
record = (session.query(TestPolicyTargetExtension).
|
||||
filter_by(pt_id=result['id']).
|
||||
one())
|
||||
result['pt_extension'] = record.value
|
||||
|
||||
def process_create_policy_target_group(self, session, data, result):
|
||||
value = data['policy_target_group']['ptg_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestPolicyTargetGroupExtension(ptg_id=result['id'],
|
||||
value=value)
|
||||
session.add(record)
|
||||
result['ptg_extension'] = value
|
||||
|
||||
def process_update_policy_target_group(self, session, data, result):
|
||||
record = (session.query(TestPolicyTargetGroupExtension).
|
||||
filter_by(ptg_id=result['id']).
|
||||
one())
|
||||
value = data['policy_target_group'].get('ptg_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['ptg_extension'] = record.value
|
||||
|
||||
def extend_policy_target_group_dict(self, session, result):
|
||||
record = (session.query(TestPolicyTargetGroupExtension).
|
||||
filter_by(ptg_id=result['id']).
|
||||
one())
|
||||
result['ptg_extension'] = record.value
|
||||
|
||||
def process_create_l2_policy(self, session, data, result):
|
||||
value = data['l2_policy']['l2p_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestL2PolicyExtension(l2p_id=result['id'], value=value)
|
||||
session.add(record)
|
||||
result['l2p_extension'] = value
|
||||
|
||||
def process_update_l2_policy(self, session, data, result):
|
||||
record = (session.query(TestL2PolicyExtension).
|
||||
filter_by(l2p_id=result['id']).
|
||||
one())
|
||||
value = data['l2_policy'].get('l2p_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['l2p_extension'] = record.value
|
||||
|
||||
def extend_l2_policy_dict(self, session, result):
|
||||
record = (session.query(TestL2PolicyExtension).
|
||||
filter_by(l2p_id=result['id']).
|
||||
one())
|
||||
result['l2p_extension'] = record.value
|
||||
|
||||
def process_create_l3_policy(self, session, data, result):
|
||||
value = data['l3_policy']['l3p_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestL3PolicyExtension(l3p_id=result['id'], value=value)
|
||||
session.add(record)
|
||||
result['l3p_extension'] = value
|
||||
|
||||
def process_update_l3_policy(self, session, data, result):
|
||||
record = (session.query(TestL3PolicyExtension).
|
||||
filter_by(l3p_id=result['id']).
|
||||
one())
|
||||
value = data['l3_policy'].get('l3p_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['l3p_extension'] = record.value
|
||||
|
||||
def extend_l3_policy_dict(self, session, result):
|
||||
record = (session.query(TestL3PolicyExtension).
|
||||
filter_by(l3p_id=result['id']).
|
||||
one())
|
||||
result['l3p_extension'] = record.value
|
||||
|
||||
def process_create_policy_classifier(self, session, data, result):
|
||||
value = data['policy_classifier']['pc_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestPolicyClassifierExtension(pc_id=result['id'], value=value)
|
||||
session.add(record)
|
||||
result['pc_extension'] = value
|
||||
|
||||
def process_update_policy_classifier(self, session, data, result):
|
||||
record = (session.query(TestPolicyClassifierExtension).
|
||||
filter_by(pc_id=result['id']).
|
||||
one())
|
||||
value = data['policy_classifier'].get('pc_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['pc_extension'] = record.value
|
||||
|
||||
def extend_policy_classifier_dict(self, session, result):
|
||||
record = (session.query(TestPolicyClassifierExtension).
|
||||
filter_by(pc_id=result['id']).
|
||||
one())
|
||||
result['pc_extension'] = record.value
|
||||
|
||||
def process_create_policy_action(self, session, data, result):
|
||||
value = data['policy_action']['pa_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestPolicyActionExtension(pa_id=result['id'], value=value)
|
||||
session.add(record)
|
||||
result['pa_extension'] = value
|
||||
|
||||
def process_update_policy_action(self, session, data, result):
|
||||
record = (session.query(TestPolicyActionExtension).
|
||||
filter_by(pa_id=result['id']).
|
||||
one())
|
||||
value = data['policy_action'].get('pa_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['pa_extension'] = record.value
|
||||
|
||||
def extend_policy_action_dict(self, session, result):
|
||||
record = (session.query(TestPolicyActionExtension).
|
||||
filter_by(pa_id=result['id']).
|
||||
one())
|
||||
result['pa_extension'] = record.value
|
||||
|
||||
def process_create_policy_rule(self, session, data, result):
|
||||
value = data['policy_rule']['pr_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestPolicyRuleExtension(pr_id=result['id'], value=value)
|
||||
session.add(record)
|
||||
result['pr_extension'] = value
|
||||
|
||||
def process_update_policy_rule(self, session, data, result):
|
||||
record = (session.query(TestPolicyRuleExtension).
|
||||
filter_by(pr_id=result['id']).
|
||||
one())
|
||||
value = data['policy_rule'].get('pr_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['pr_extension'] = record.value
|
||||
|
||||
def extend_policy_rule_dict(self, session, result):
|
||||
record = (session.query(TestPolicyRuleExtension).
|
||||
filter_by(pr_id=result['id']).
|
||||
one())
|
||||
result['pr_extension'] = record.value
|
||||
|
||||
def process_create_policy_rule_set(self, session, data, result):
|
||||
value = data['policy_rule_set']['prs_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestPolicyRuleSetExtension(prs_id=result['id'], value=value)
|
||||
session.add(record)
|
||||
result['prs_extension'] = value
|
||||
|
||||
def process_update_policy_rule_set(self, session, data, result):
|
||||
record = (session.query(TestPolicyRuleSetExtension).
|
||||
filter_by(prs_id=result['id']).
|
||||
one())
|
||||
value = data['policy_rule_set'].get('prs_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['prs_extension'] = record.value
|
||||
|
||||
def extend_policy_rule_set_dict(self, session, result):
|
||||
record = (session.query(TestPolicyRuleSetExtension).
|
||||
filter_by(prs_id=result['id']).
|
||||
one())
|
||||
result['prs_extension'] = record.value
|
||||
|
||||
def process_create_network_service_policy(self, session, data, result):
|
||||
value = data['network_service_policy']['nsp_extension']
|
||||
if not attributes.is_attr_set(value):
|
||||
value = ''
|
||||
record = TestNetworkServicePolicyExtension(nsp_id=result['id'],
|
||||
value=value)
|
||||
session.add(record)
|
||||
result['nsp_extension'] = value
|
||||
|
||||
def process_update_network_service_policy(self, session, data, result):
|
||||
record = (session.query(TestNetworkServicePolicyExtension).
|
||||
filter_by(nsp_id=result['id']).
|
||||
one())
|
||||
value = data['network_service_policy'].get('nsp_extension')
|
||||
if value and value != record.value:
|
||||
record.value = value
|
||||
result['nsp_extension'] = record.value
|
||||
|
||||
def extend_network_service_policy_dict(self, session, result):
|
||||
record = (session.query(TestNetworkServicePolicyExtension).
|
||||
filter_by(nsp_id=result['id']).
|
||||
one())
|
||||
result['nsp_extension'] = record.value
|
@ -31,6 +31,8 @@ console_scripts=
|
||||
neutron.service_plugins =
|
||||
group_policy = gbp.neutron.services.grouppolicy.plugin:GroupPolicyPlugin
|
||||
servicechain = gbp.neutron.services.servicechain.servicechain_plugin:ServiceChainPlugin
|
||||
gbp.neutron.group_policy.extension_drivers =
|
||||
test = gbp.neutron.tests.unit.services.grouppolicy.test_extension_driver_api:TestExtensionDriver
|
||||
gbp.neutron.group_policy.policy_drivers =
|
||||
dummy = gbp.neutron.services.grouppolicy.drivers.dummy_driver:NoopDriver
|
||||
implicit_policy = gbp.neutron.services.grouppolicy.drivers.implicit_policy:ImplicitPolicyDriver
|
||||
@ -43,6 +45,7 @@ gbp.neutron.servicechain.servicechain_drivers =
|
||||
dummy = gbp.neutron.services.servicechain.drivers.dummy_driver:NoopDriver
|
||||
simplechain_driver = gbp.neutron.services.servicechain.drivers.simplechain_driver:SimpleChainDriver
|
||||
oneconvergence_servicechain_driver = gbp.neutron.services.servicechain.drivers.oneconvergence_servicechain_driver:OneconvergenceServiceChainDriver
|
||||
|
||||
[build_sphinx]
|
||||
source-dir = doc/source
|
||||
build-dir = doc/build
|
||||
|
Loading…
x
Reference in New Issue
Block a user