Merge "Fix some pylint indentation warnings"
This commit is contained in:
commit
3e8f2325d6
@ -106,9 +106,9 @@ class Agent(base.NeutronDbObject):
|
||||
rb_model.RouterL3AgentBinding.router_id
|
||||
).label('count')).outerjoin(
|
||||
rb_model.RouterL3AgentBinding).group_by(
|
||||
agent_model.Agent,
|
||||
rb_model.RouterL3AgentBinding
|
||||
.l3_agent_id).order_by('count')
|
||||
agent_model.Agent,
|
||||
rb_model.RouterL3AgentBinding
|
||||
.l3_agent_id).order_by('count')
|
||||
res = query.filter(agent_model.Agent.id.in_(agent_ids)).first()
|
||||
agent_obj = cls._load_object(context, res[0])
|
||||
return agent_obj
|
||||
@ -117,12 +117,11 @@ class Agent(base.NeutronDbObject):
|
||||
def get_l3_agents_ordered_by_num_routers(cls, context, agent_ids):
|
||||
with cls.db_context_reader(context):
|
||||
query = (context.session.query(agent_model.Agent, func.count(
|
||||
rb_model.RouterL3AgentBinding.router_id)
|
||||
.label('count')).
|
||||
outerjoin(rb_model.RouterL3AgentBinding).
|
||||
group_by(agent_model.Agent).
|
||||
filter(agent_model.Agent.id.in_(agent_ids)).
|
||||
order_by('count'))
|
||||
rb_model.RouterL3AgentBinding.router_id).label('count')).
|
||||
outerjoin(rb_model.RouterL3AgentBinding).
|
||||
group_by(agent_model.Agent).
|
||||
filter(agent_model.Agent.id.in_(agent_ids)).
|
||||
order_by('count'))
|
||||
return [cls._load_object(context, record[0]) for record in query]
|
||||
|
||||
@classmethod
|
||||
@ -157,10 +156,9 @@ class Agent(base.NeutronDbObject):
|
||||
@db_api.CONTEXT_READER
|
||||
def get_agents_by_availability_zones_and_agent_type(
|
||||
cls, context, agent_type, availability_zones):
|
||||
query = context.session.query(
|
||||
agent_model.Agent).filter_by(
|
||||
query = context.session.query(agent_model.Agent).filter_by(
|
||||
agent_type=agent_type).group_by(
|
||||
agent_model.Agent.availability_zone)
|
||||
agent_model.Agent.availability_zone)
|
||||
query = query.filter(
|
||||
agent_model.Agent.availability_zone.in_(availability_zones)).all()
|
||||
agents = [cls._load_object(context, record) for record in query]
|
||||
|
@ -868,7 +868,7 @@ class NeutronDbObject(NeutronObject, metaclass=DeclarativeObject):
|
||||
parent=clsname, child=objclass.__name__)
|
||||
if len(foreign_keys.keys()) > 1:
|
||||
raise o_exc.NeutronSyntheticFieldMultipleForeignKeys(
|
||||
field=field)
|
||||
field=field)
|
||||
|
||||
synthetic_field_db_name = (
|
||||
self.fields_need_translation.get(field, field))
|
||||
@ -981,5 +981,4 @@ class NeutronDbObject(NeutronObject, metaclass=DeclarativeObject):
|
||||
cls.validate_filters(**kwargs)
|
||||
# Succeed if at least a single object matches; no need to fetch more
|
||||
return bool(obj_db_api.count(
|
||||
cls, context, query_limit=1, **cls.modify_fields_to_db(kwargs))
|
||||
)
|
||||
cls, context, query_limit=1, **cls.modify_fields_to_db(kwargs)))
|
||||
|
@ -36,7 +36,7 @@ class RouterL3AgentBinding(base.NeutronDbObject):
|
||||
'router_id': common_types.UUIDField(),
|
||||
'l3_agent_id': common_types.UUIDField(),
|
||||
'binding_index': obj_fields.IntegerField(
|
||||
default=l3agent.LOWEST_BINDING_INDEX),
|
||||
default=l3agent.LOWEST_BINDING_INDEX),
|
||||
}
|
||||
|
||||
# TODO(ihrachys) return OVO objects not models
|
||||
@ -52,16 +52,15 @@ class RouterL3AgentBinding(base.NeutronDbObject):
|
||||
@classmethod
|
||||
@db_api.CONTEXT_READER
|
||||
def get_down_router_bindings(cls, context, cutoff):
|
||||
query = (context.session.query(
|
||||
l3agent.RouterL3AgentBinding).
|
||||
query = (context.session.query(l3agent.RouterL3AgentBinding).
|
||||
join(agent_model.Agent).
|
||||
filter(agent_model.Agent.heartbeat_timestamp < cutoff,
|
||||
agent_model.Agent.admin_state_up).outerjoin(
|
||||
l3_attrs.RouterExtraAttributes,
|
||||
l3_attrs.RouterExtraAttributes.router_id ==
|
||||
l3agent.RouterL3AgentBinding.router_id).filter(
|
||||
l3_attrs.RouterExtraAttributes.ha.in_([sql.false(),
|
||||
sql.null()])))
|
||||
agent_model.Agent.admin_state_up).outerjoin(
|
||||
l3_attrs.RouterExtraAttributes,
|
||||
l3_attrs.RouterExtraAttributes.router_id ==
|
||||
l3agent.RouterL3AgentBinding.router_id).filter(
|
||||
l3_attrs.RouterExtraAttributes.ha.in_(
|
||||
[sql.false(), sql.null()])))
|
||||
bindings = [cls._load_object(context, db_obj) for db_obj in
|
||||
query.all()]
|
||||
return bindings
|
||||
|
@ -119,8 +119,7 @@ class NetworkSegmentRange(base.NeutronDbObject):
|
||||
query = self.obj_context.session.query(alloc_segmentation_id)
|
||||
query = query.filter(and_(
|
||||
alloc_segmentation_id >= self.minimum,
|
||||
alloc_segmentation_id <= self.maximum),
|
||||
not_(allocated))
|
||||
alloc_segmentation_id <= self.maximum), not_(allocated))
|
||||
if self.network_type == constants.TYPE_VLAN:
|
||||
alloc_available = query.filter(
|
||||
model.physical_network == self.physical_network).all()
|
||||
@ -141,9 +140,8 @@ class NetworkSegmentRange(base.NeutronDbObject):
|
||||
self.physical_network,
|
||||
segments_model.NetworkSegment.segmentation_id >= self.minimum,
|
||||
segments_model.NetworkSegment.segmentation_id <= self.maximum))
|
||||
.filter(
|
||||
segments_model.NetworkSegment.network_id ==
|
||||
models_v2.Network.id)).all()
|
||||
.filter(segments_model.NetworkSegment.network_id ==
|
||||
models_v2.Network.id)).all()
|
||||
return dict(alloc_used)
|
||||
|
||||
@classmethod
|
||||
|
@ -67,7 +67,7 @@ class AllowedAddressPair(base.NeutronDbObject):
|
||||
def get_allowed_address_pairs_for_ports(cls, context, port_ids):
|
||||
with db_api.CONTEXT_READER.using(context):
|
||||
query = context.session.query(models.AllowedAddressPair).filter(
|
||||
models.AllowedAddressPair.port_id.in_(port_ids))
|
||||
models.AllowedAddressPair.port_id.in_(port_ids))
|
||||
pairs = [cls._load_object(context, db_obj)
|
||||
for db_obj in query.all()]
|
||||
return pairs
|
||||
|
@ -25,11 +25,11 @@ class ExtraDhcpOpt(base.NeutronDbObject):
|
||||
db_model = models.ExtraDhcpOpt
|
||||
|
||||
fields = {
|
||||
'id': common_types.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'opt_name': obj_fields.StringField(),
|
||||
'opt_value': obj_fields.StringField(),
|
||||
'ip_version': obj_fields.IntegerField(),
|
||||
'id': common_types.UUIDField(),
|
||||
'port_id': common_types.UUIDField(),
|
||||
'opt_name': obj_fields.StringField(),
|
||||
'opt_value': obj_fields.StringField(),
|
||||
'ip_version': obj_fields.IntegerField(),
|
||||
}
|
||||
|
||||
fields_no_update = ['port_id']
|
||||
|
@ -223,12 +223,12 @@ class IPAllocation(base.NeutronDbObject):
|
||||
alloc_db = (context.session.query(models_v2.IPAllocation).
|
||||
filter_by(subnet_id=subnet_id).join(models_v2.Port).
|
||||
filter(~models_v2.Port.device_owner.
|
||||
in_(device_owner)).first())
|
||||
in_(device_owner)).first())
|
||||
else:
|
||||
alloc_db = (context.session.query(models_v2.IPAllocation).
|
||||
filter_by(subnet_id=subnet_id).join(models_v2.Port).
|
||||
filter(models_v2.Port.device_owner.
|
||||
in_(device_owner)).first())
|
||||
in_(device_owner)).first())
|
||||
if exclude and alloc_db:
|
||||
return super(IPAllocation, cls)._load_object(context, alloc_db)
|
||||
if alloc_db:
|
||||
@ -723,7 +723,7 @@ class Port(base.NeutronDbObject):
|
||||
"""Return ports with fixed IPs in a subnet"""
|
||||
return context.session.query(models_v2.Port).filter(
|
||||
models_v2.IPAllocation.port_id == models_v2.Port.id).filter(
|
||||
models_v2.IPAllocation.subnet_id == subnet_id).all()
|
||||
models_v2.IPAllocation.subnet_id == subnet_id).all()
|
||||
|
||||
@classmethod
|
||||
def get_port_from_mac_and_pci_slot(cls, context, device_mac,
|
||||
|
@ -67,7 +67,7 @@ class QosPolicyPortBinding(base.NeutronDbObject, _QosPolicyBindingMixin):
|
||||
else:
|
||||
query = query.filter(~exists().where(
|
||||
cls.db_model.port_id == models_v2.Port.id)).filter(
|
||||
models_v2.Port.network_id == network_id)
|
||||
models_v2.Port.network_id == network_id)
|
||||
return query.all()
|
||||
|
||||
|
||||
|
@ -342,11 +342,11 @@ class QosPolicy(rbac_db.NeutronRbacObject):
|
||||
|
||||
@classmethod
|
||||
def _get_bound_project_ids(cls, session, binding_db, bound_db,
|
||||
binding_db_id_column, policy_id):
|
||||
binding_db_id_column, policy_id):
|
||||
return list(itertools.chain.from_iterable(
|
||||
session.query(bound_db.project_id).join(
|
||||
binding_db, bound_db.id == binding_db_id_column).filter(
|
||||
binding_db.policy_id == policy_id).all()))
|
||||
binding_db.policy_id == policy_id).all()))
|
||||
|
||||
@classmethod
|
||||
def get_bound_project_ids(cls, context, policy_id):
|
||||
|
@ -87,10 +87,10 @@ def check_min_pps_rule_conflict(policy, rule_obj):
|
||||
# Check if we are mixing directionless and direction-oriented QoS
|
||||
# minimum packet rate rules
|
||||
if getattr(rule_obj, "direction", None) and (
|
||||
(rule_obj.direction == n_consts.ANY_DIRECTION and
|
||||
rule.direction in n_consts.VALID_DIRECTIONS) or
|
||||
(rule_obj.direction in n_consts.VALID_DIRECTIONS and
|
||||
rule.direction == n_consts.ANY_DIRECTION)):
|
||||
(rule_obj.direction == n_consts.ANY_DIRECTION and
|
||||
rule.direction in n_consts.VALID_DIRECTIONS) or
|
||||
(rule_obj.direction in n_consts.VALID_DIRECTIONS and
|
||||
rule.direction == n_consts.ANY_DIRECTION)):
|
||||
raise qos_exc.QoSRuleParameterConflict(
|
||||
rule_value=rule_obj.direction,
|
||||
policy_id=policy["id"],
|
||||
|
@ -53,7 +53,7 @@ class QosRuleType(base.NeutronObject):
|
||||
drivers_obj = [QosRuleTypeDriver(
|
||||
name=driver['name'],
|
||||
supported_parameters=driver['supported_parameters'])
|
||||
for driver in drivers]
|
||||
for driver in drivers]
|
||||
|
||||
return cls(type=rule_type_name, drivers=drivers_obj)
|
||||
|
||||
@ -67,7 +67,7 @@ class QosRuleType(base.NeutronObject):
|
||||
|
||||
rule_types = directory.get_plugin(
|
||||
alias=constants.QOS).supported_rule_types(
|
||||
all_supported=all_supported, all_rules=all_rules)
|
||||
all_supported=all_supported, all_rules=all_rules)
|
||||
return [cls(type=type_) for type_ in rule_types]
|
||||
|
||||
# we don't receive context because we don't need db access at all
|
||||
|
@ -93,8 +93,7 @@ class Reservation(base.NeutronDbObject):
|
||||
models.Reservation.expiration,
|
||||
sql.func.cast(
|
||||
sql.func.sum(models.ResourceDelta.amount),
|
||||
sqltypes.Integer)).join(
|
||||
models.Reservation)
|
||||
sqltypes.Integer)).join(models.Reservation)
|
||||
if expired:
|
||||
exp_expr = (models.Reservation.expiration < now)
|
||||
else:
|
||||
@ -103,8 +102,8 @@ class Reservation(base.NeutronDbObject):
|
||||
models.Reservation.project_id == project_id,
|
||||
models.ResourceDelta.resource.in_(resources),
|
||||
exp_expr)).group_by(
|
||||
models.ResourceDelta.resource,
|
||||
models.Reservation.expiration)
|
||||
models.ResourceDelta.resource,
|
||||
models.Reservation.expiration)
|
||||
return dict((resource, total_reserved)
|
||||
for (resource, exp, total_reserved) in resv_query)
|
||||
|
||||
|
@ -69,10 +69,10 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin,
|
||||
# session
|
||||
rbac_db_model = rbac_db_cls.db_model
|
||||
return (db_utils.model_query(context, rbac_db_model).filter(
|
||||
and_(rbac_db_model.object_id == obj_id,
|
||||
rbac_db_model.action == models.ACCESS_SHARED,
|
||||
rbac_db_model.target_project.in_(
|
||||
['*', project_id]))).count() != 0)
|
||||
and_(rbac_db_model.object_id == obj_id,
|
||||
rbac_db_model.action == models.ACCESS_SHARED,
|
||||
rbac_db_model.target_project.in_(
|
||||
['*', project_id]))).count() != 0)
|
||||
|
||||
@classmethod
|
||||
def is_shared_with_project(cls, context, obj_id, project_id):
|
||||
@ -100,9 +100,9 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin,
|
||||
rbac_db_model = cls.rbac_db_cls.db_model
|
||||
return set(itertools.chain.from_iterable(context.session.query(
|
||||
rbac_db_model.target_project).filter(
|
||||
and_(rbac_db_model.object_id == obj_id,
|
||||
rbac_db_model.action == models.ACCESS_SHARED,
|
||||
rbac_db_model.target_project != '*'))))
|
||||
and_(rbac_db_model.object_id == obj_id,
|
||||
rbac_db_model.action == models.ACCESS_SHARED,
|
||||
rbac_db_model.target_project != '*'))))
|
||||
|
||||
@classmethod
|
||||
@db_api.CONTEXT_READER
|
||||
@ -132,7 +132,7 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin,
|
||||
# for the wildcard we need to query all of the rbac entries to
|
||||
# see if any allow the object sharing
|
||||
other_target_projects = cls._get_projects_with_shared_access_to_db_obj(
|
||||
ctx_admin, obj_id)
|
||||
ctx_admin, obj_id)
|
||||
if not bound_project_ids.issubset(other_target_projects):
|
||||
raise_policy_in_use()
|
||||
|
||||
|
@ -251,13 +251,12 @@ class Subnet(base.NeutronDbObject):
|
||||
object_data = db_obj.get('dns_publish_fixed_ip', None)
|
||||
else:
|
||||
object_data = SubnetDNSPublishFixedIP.get_objects(
|
||||
self.obj_context,
|
||||
subnet_id=self.id)
|
||||
self.obj_context,
|
||||
subnet_id=self.id)
|
||||
|
||||
dns_publish_fixed_ip = False
|
||||
if object_data:
|
||||
dns_publish_fixed_ip = object_data.get(
|
||||
'dns_publish_fixed_ip')
|
||||
dns_publish_fixed_ip = object_data.get('dns_publish_fixed_ip')
|
||||
setattr(self, 'dns_publish_fixed_ip', dns_publish_fixed_ip)
|
||||
self.obj_reset_changes(['dns_publish_fixed_ip'])
|
||||
|
||||
@ -358,7 +357,7 @@ class Subnet(base.NeutronDbObject):
|
||||
|
||||
@classmethod
|
||||
def _query_filter_by_fixed_ips_segment(cls, query, fixed_ips,
|
||||
allow_multiple_segments=False):
|
||||
allow_multiple_segments=False):
|
||||
"""Excludes subnets not on the same segment as fixed_ips
|
||||
|
||||
:raises: FixedIpsSubnetsNotOnSameSegment
|
||||
@ -509,8 +508,8 @@ class Subnet(base.NeutronDbObject):
|
||||
if ignored_service_type:
|
||||
service_type_model = SubnetServiceType.db_model
|
||||
query = query.filter(~exists().where(and_(
|
||||
cls.db_model.id == service_type_model.subnet_id,
|
||||
service_type_model.service_type == ignored_service_type)))
|
||||
cls.db_model.id == service_type_model.subnet_id,
|
||||
service_type_model.service_type == ignored_service_type)))
|
||||
|
||||
# (zigo): When a subnet is created, at this point in the code,
|
||||
# its service_types aren't populated in the subnet_service_types
|
||||
|
Loading…
x
Reference in New Issue
Block a user