Merge "Use subqueries for rbac_entries and subnets<->network"

This commit is contained in:
Jenkins 2016-12-22 09:13:09 +00:00 committed by Gerrit Code Review
commit 060261d6a8
2 changed files with 8 additions and 8 deletions

View File

@ -151,7 +151,7 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
for route in subnet['routes']],
}
# The shared attribute for a subnet is the same as its parent network
res['shared'] = self._is_network_shared(context, subnet.networks)
res['shared'] = self._is_network_shared(context, subnet.rbac_entries)
# Call auxiliary extend functions, if any
self._apply_dict_extend_functions(attributes.SUBNETS, res, subnet)
return db_utils.resource_fields(res, fields)
@ -270,18 +270,18 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
'status': network['status'],
'subnets': [subnet['id']
for subnet in network['subnets']]}
res['shared'] = self._is_network_shared(context, network)
res['shared'] = self._is_network_shared(context, network.rbac_entries)
# Call auxiliary extend functions, if any
if process_extensions:
self._apply_dict_extend_functions(
attributes.NETWORKS, res, network)
return db_utils.resource_fields(res, fields)
def _is_network_shared(self, context, network):
def _is_network_shared(self, context, rbac_entries):
# The shared attribute for a network now reflects if the network
# is shared to the calling tenant via an RBAC entry.
matches = ('*',) + ((context.tenant_id,) if context else ())
for entry in network.rbac_entries:
for entry in rbac_entries:
if (entry.action == 'access_as_shared' and
entry.target_tenant in matches):
return True

View File

@ -186,7 +186,7 @@ class Subnet(standard_attr.HasStandardAttributes, model_base.BASEV2,
# subnets don't have their own rbac_entries, they just inherit from
# the network rbac entries
rbac_entries = orm.relationship(
rbac_db_models.NetworkRBAC, lazy='joined', uselist=True,
rbac_db_models.NetworkRBAC, lazy='subquery', uselist=True,
foreign_keys='Subnet.network_id',
primaryjoin='Subnet.network_id==NetworkRBAC.object_id')
api_collections = [attr.SUBNETS]
@ -236,13 +236,13 @@ class Network(standard_attr.HasStandardAttributes, model_base.BASEV2,
name = sa.Column(sa.String(attr.NAME_MAX_LEN))
ports = orm.relationship(Port, backref='networks')
subnets = orm.relationship(
Subnet, backref=orm.backref('networks', lazy='joined'),
lazy="joined")
Subnet, backref=orm.backref('networks', lazy='subquery'),
lazy="subquery")
status = sa.Column(sa.String(16))
admin_state_up = sa.Column(sa.Boolean)
vlan_transparent = sa.Column(sa.Boolean, nullable=True)
rbac_entries = orm.relationship(rbac_db_models.NetworkRBAC,
backref='network', lazy='joined',
backref='network', lazy='subquery',
cascade='all, delete, delete-orphan')
availability_zone_hints = sa.Column(sa.String(255))
dhcp_agents = orm.relationship(