'Wrapper utility that returns a test subnet.'

@classmethod
def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None, ip_version=None, client=None, **kwargs):

    if (not client):
        client = cls.subnets_client
    ip_version = (ip_version if (ip_version is not None) else cls._ip_version)
    gateway_not_set = (gateway == '')
    if (ip_version == 4):
        cidr = (cidr or netaddr.IPNetwork(CONF.network.project_network_cidr))
        mask_bits = (mask_bits or CONF.network.project_network_mask_bits)
    elif (ip_version == 6):
        cidr = (cidr or netaddr.IPNetwork(CONF.network.project_network_v6_cidr))
        mask_bits = (mask_bits or CONF.network.project_network_v6_mask_bits)
    for subnet_cidr in cidr.subnet(mask_bits):
        if gateway_not_set:
            gateway_ip = str((netaddr.IPAddress(subnet_cidr) + 1))
        else:
            gateway_ip = gateway
        try:
            body = client.create_subnet(network_id=network['id'], cidr=str(subnet_cidr), ip_version=ip_version, gateway_ip=gateway_ip, **kwargs)
            break
        except lib_exc.BadRequest as e:
            is_overlapping_cidr = ('overlaps    with    another    subnet' in str(e))
            if (not is_overlapping_cidr):
                raise
    else:
        message = 'Available    CIDR    for    subnet    creation    could    not    be    found'
        raise exceptions.BuildErrorException(message)
    subnet = body['subnet']
    cls.subnets.append(subnet)
    return subnet
