It's a little hard to follow what's going on, and the rule count algorithm seems like it could improve pretty dramatically in efficiency
def _get_security_group(self, context, group_id):
group = context.session.query(models.SecurityGroup).\
filter(models.SecurityGroup.id == group_id).first()
rulelist = {'ingress': [], 'egress': []}
for rule in group.rules:
rulelist[rule.direction].append(
self._make_security_rule_dict(rule))
return {'uuid': self._query_security_group(context, group_id).nvp_id,
'logical_port_ingress_rules': rulelist['ingress'],
'logical_port_egress_rules': rulelist['egress']}
def _check_rule_count_per_port(self, context, group_id):
ports = context.session.query(models.SecurityGroup).filter(
models.SecurityGroup.id == group_id).first().get('ports', [])
groups = (set(group.id for group in port.get('security_groups', []))
for port in ports)
return max(self._check_rule_count_for_groups(
context, (self._get_security_group(context, id) for id in g))
for g in groups)
It's a little hard to follow what's going on, and the rule count algorithm seems like it could improve pretty dramatically in efficiency