'Initialize and validate
:param tenant_id: The tenant id who will own the subnet
:type tenant_id: str uuid
:param subnet_id: Neutron\'s subnet ID
:type subnet_id: str uuid
:param gateway_ip: An IP to reserve for the subnet gateway.
:type gateway_ip: None or convertible to netaddr.IPAddress
:param allocation_pools: The pool from which IPAM should allocate
addresses.   The allocator *may* allow allocating addresses outside
of this range if specifically requested.
:type allocation_pools: A list of netaddr.IPRange.  None if not
specified.'

def __init__(self, tenant_id, subnet_id, gateway_ip=None, allocation_pools=None):

    self._tenant_id = tenant_id
    self._subnet_id = subnet_id
    self._gateway_ip = None
    self._allocation_pools = None
    if (gateway_ip is not None):
        self._gateway_ip = netaddr.IPAddress(gateway_ip)
    if (allocation_pools is not None):
        allocation_pools = sorted(allocation_pools)
        previous = None
        for pool in allocation_pools:
            if (not isinstance(pool, netaddr.ip.IPRange)):
                raise TypeError(_('Ranges    must    be    netaddr.IPRange'))
            if (previous and (pool.first <= previous.last)):
                raise ValueError(_('Ranges    must    not    overlap'))
            previous = pool
        if (1 < len(allocation_pools)):
            first_version = allocation_pools[0].version
            last_version = allocation_pools[(-1)].version
            if (first_version != last_version):
                raise ValueError(_('Ranges    must    be    in    the    same    IP    version'))
        self._allocation_pools = allocation_pools
    if (self.gateway_ip and self.allocation_pools):
        if (self.gateway_ip.version != self.allocation_pools[0].version):
            raise ValueError(_('Gateway    IP    version    inconsistent    with    allocation    pool    version'))
