'Select rules from the security groups the port is member of.'

def _select_sg_rules_for_port(self, port, direction):

    port_sg_ids = port.get('security_groups', [])
    port_rules = []
    for sg_id in port_sg_ids:
        for rule in self.sg_rules.get(sg_id, []):
            if (rule['direction'] == direction):
                if self.enable_ipset:
                    port_rules.append(rule)
                else:
                    port_rules.extend(self._expand_sg_rule_with_remote_ips(rule, port, direction))
    return port_rules
