returns list of rules with the existing ones filtered out
        :param group security group we need to check the rules against
        :type group boto.ec2.securitygroup.SecurityGroup
        :rtype list of Rule

def filter_existing_rules(self, rules, group):
        """returns list of rules with the existing ones filtered out
        :param group security group we need to check the rules against
        :type group boto.ec2.securitygroup.SecurityGroup
        :rtype list of Rule
        """
        tmp = []
        for rule in rules:

            def eq(x):
                # returns True if this existing AWS rule matches the one we want to create
                assert isinstance(x, boto.ec2.securitygroup.IPPermissions)
                # these are simple catches that determine if we can rule out
                # the existing rule
                group_match = False
                if rule.group_name:
                    logger.debug("Checking for possible group name match %s", x.grants[0].group_id)

                if rule.group_name and x.grants[0].group_id \
                    and rule.group_name != self.get_group(x.grants[0].group_id).name:
                    logger.debug("Group name %s didn't match %s", rule.group_name, x.grants[0].name)
                    return False

                if x.ip_protocol != rule.protocol:
                    logger.debug("ruled out due to protocol: %s vs %s", x.ip_protocol, rule.protocol)
                    return False

                if int(x.from_port) != int(rule.from_port):
                    logger.debug("ruled out due to from_port: %s vs %s", int(x.from_port), int(rule.from_port))
                    return False

                if int(x.to_port) != (rule.to_port):
                    logger.debug("ruled out due to to_port: %s vs %s", int(x.to_port), int(rule.to_port))
                    return False

                # final checks - if one of these rules matches we already have a matching rule
                # and we return True
                if rule.address and not filter(lambda y: y.cidr_ip == rule.address, x.grants ):
                    logger.debug("%s not found in grants", rule.address)
                    return False

                logger.debug("%s %s ok", rule.address, rule.group_name)
                logger.debug("port_from: %s %s", rule.from_port, x.from_port)
                logger.debug("port_to: %s %s", rule.to_port, x.to_port)
                logger.debug("group: %s %s", rule.group_name, x.to_port)
                return True

            logger.debug("Applying rules for %s", group.name)
            filtered = filter(eq, group.rules)

            if not filtered:
                logger.debug(filtered)
                logger.debug("Applying rule %s against %s", rule, group.rules)
                tmp.append(rule)
        return tmp