'Creates subnet in DB, returns result, network, and ipam_subnet.'

def _create_subnet_precommit(self, context, subnet):

    s = subnet['subnet']
    cidr = s.get('cidr', constants.ATTR_NOT_SPECIFIED)
    prefixlen = s.get('prefixlen', constants.ATTR_NOT_SPECIFIED)
    has_cidr = validators.is_attr_set(cidr)
    has_prefixlen = validators.is_attr_set(prefixlen)
    if (has_cidr and has_prefixlen):
        msg = _('cidr    and    prefixlen    must    not    be    supplied    together')
        raise exc.BadRequest(resource='subnets', msg=msg)
    if has_cidr:
        net = netaddr.IPNetwork(s['cidr'])
        subnet['subnet']['cidr'] = ('%s/%s' % (net.network, net.prefixlen))
    subnetpool_id = self._get_subnetpool_id(context, s)
    if ((not subnetpool_id) and (not has_cidr)):
        msg = _('a    subnetpool    must    be    specified    in    the    absence    of    a    cidr')
        raise exc.BadRequest(resource='subnets', msg=msg)
    if subnetpool_id:
        self.ipam.validate_pools_with_subnetpool(s)
        if (subnetpool_id == constants.IPV6_PD_POOL_ID):
            if has_cidr:
                subnetpool_id = None
                self._validate_subnet(context, s)
            else:
                prefix = n_const.PROVISIONAL_IPV6_PD_PREFIX
                subnet['subnet']['cidr'] = prefix
                self._validate_subnet_for_pd(s)
    else:
        if (not has_cidr):
            msg = _('A    cidr    must    be    specified    in    the    absence    of    a    subnet    pool')
            raise exc.BadRequest(resource='subnets', msg=msg)
        self._validate_subnet(context, s)
    with db_api.context_manager.writer.using(context):
        network = self._get_network(context, subnet['subnet']['network_id'])
        (subnet, ipam_subnet) = self.ipam.allocate_subnet(context, network, subnet['subnet'], subnetpool_id)
    result = self._make_subnet_dict(subnet, context=context)
    return (result, network, ipam_subnet)
