'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. Multiple rules are
installed to a security group in neutron using bulk support.'

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

    neutron = neutronapi.get_client(context)
    body = self._make_neutron_security_group_rules_list(vals)
    try:
        rules = neutron.create_security_group_rule(body).get('security_group_rules')
    except n_exc.NeutronClientException as e:
        exc_info = sys.exc_info()
        if (e.status_code == 404):
            LOG.exception(_LE('Neutron    Error    getting    security    group    %s'), name)
            self.raise_not_found(six.text_type(e))
        elif (e.status_code == 409):
            LOG.exception(_LE('Neutron    Error    adding    rules    to    security    group    %s'), name)
            self.raise_over_quota(six.text_type(e))
        elif (e.status_code == 400):
            LOG.exception(_LE('Neutron    Error:    %s'), e)
            self.raise_invalid_property(six.text_type(e))
        else:
            LOG.exception(_LE('Neutron    Error:'))
            six.reraise(*exc_info)
    converted_rules = []
    for rule in rules:
        converted_rules.append(self._convert_to_nova_security_group_rule_format(rule))
    return converted_rules
