Register extending function for security-group rule extension

It is only because of recent changes in Neutron that now an extension can
register an extending function for the security-group-rule resource.
This patch will use this mechanism to add additional params to a
security-group-rule whenever required, without the need to
override the mixin methods.

Change-Id: If81490ebfc7a45de69e79d4a18754464cfec3e27
This commit is contained in:
Roey Chen 2016-03-06 03:55:00 -08:00 committed by garyk
parent 63a12ec964
commit 3045ed74fc
1 changed files with 10 additions and 9 deletions

View File

@ -15,7 +15,8 @@
from sqlalchemy.orm import exc
from neutron.api.v2 import attributes as attr
from neutron.db import securitygroups_db as secgroup_db
from neutron.db import db_base_plugin_v2
from neutron.extensions import securitygroup as ext_sg
from neutron_lib import exceptions as nexception
from vmware_nsx._i18n import _
from vmware_nsx.db import nsxv_models
@ -56,12 +57,12 @@ class ExtendedSecurityGroupRuleMixin(object):
sgr[ext_loip.LOCAL_IP_PREFIX] = properties.local_ip_prefix
return sgr
def _make_security_group_rule_dict(self, rule_db, fields=None):
res = secgroup_db.SecurityGroupDbMixin._make_security_group_rule_dict(
self, rule_db, fields=None)
if rule_db.ext_properties:
res[ext_loip.LOCAL_IP_PREFIX] = (
rule_db.ext_properties.local_ip_prefix)
db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
ext_sg.SECURITYGROUPRULES, ['_extend_security_group_rule_with_params'])
def _extend_security_group_rule_with_params(self, sg_rule_res, sg_rule_db):
if sg_rule_db.ext_properties:
sg_rule_res[ext_loip.LOCAL_IP_PREFIX] = (
sg_rule_db.ext_properties.local_ip_prefix)
else:
res[ext_loip.LOCAL_IP_PREFIX] = None
return self._fields(res, fields)
sg_rule_res[ext_loip.LOCAL_IP_PREFIX] = None