'Add security group rule(s) to security group.
Note: the Nova security group API doesn\'t support adding multiple
security group rules at once but the EC2 one does. Therefore,
this function is written to support both.'

def add_rules(self, context, id, name, vals):

    try:
        objects.Quotas.check_deltas(context, {'security_group_rules': len(vals)}, id)
    except exception.OverQuota:
        msg = _('Quota    exceeded,    too    many    security    group    rules.')
        self.raise_over_quota(msg)
    msg = 'Security    group    %(name)s    added    %(protocol)s    ingress    (%(from_port)s:%(to_port)s)'
    rules = []
    for v in vals:
        rule = self.db.security_group_rule_create(context, v)
        if CONF.quota.recheck_quota:
            try:
                objects.Quotas.check_deltas(context, {'security_group_rules': 0}, id)
            except exception.OverQuota:
                self.db.security_group_rule_destroy(context, rule['id'])
                msg = _('Quota    exceeded,    too    many    security    group    rules.')
                self.raise_over_quota(msg)
        rules.append(rule)
        LOG.info(msg, {'name': name, 'protocol': rule.protocol, 'from_port': rule.from_port, 'to_port': rule.to_port})
    self.trigger_rules_refresh(context, id=id)
    return rules
