def _make_subnet(self, n, cidr_prefix, network_id):
     session = self.context.session
     subnet = models_v2.Subnet(tenant_id='fake-tenant-id',
                               name='test-subnet-{0}'.format(n),
                               network_id=network_id,
                               ip_version=4,
                               cidr='{0}.0/24'.format(cidr_prefix),
                               gateway_ip='{0}.1'.format(cidr_prefix),
                               enable_dhcp=True,
                               shared=False)
     session.add(subnet)
     session.flush()
     ippool = models_v2.IPAllocationPool(
         subnet_id=subnet['id'],
         first_ip='{0}.1'.format(cidr_prefix),
         last_ip='{0}.254'.format(cidr_prefix))
     session.add(ippool)
     session.flush()
     iprange = models_v2.IPAvailabilityRange(
         allocation_pool_id=ippool['id'],
         first_ip='{0}.1'.format(cidr_prefix),
         last_ip='{0}.254'.format(cidr_prefix))
     session.add(iprange)
     session.flush()
     return subnet
Пример #2
0
 def save_allocation_pools(self, context, subnet, allocation_pools):
     for pool in allocation_pools:
         first_ip = str(netaddr.IPAddress(pool.first, pool.version))
         last_ip = str(netaddr.IPAddress(pool.last, pool.version))
         ip_pool = models_v2.IPAllocationPool(subnet=subnet,
                                              first_ip=first_ip,
                                              last_ip=last_ip)
         context.session.add(ip_pool)
Пример #3
0
 def _save_allocation_pools(self, context, subnet, allocation_pools):
     for pool in allocation_pools:
         ip_pool = models_v2.IPAllocationPool(subnet=subnet,
                                              first_ip=pool['start'],
                                              last_ip=pool['end'])
         context.session.add(ip_pool)
         ip_range = models_v2.IPAvailabilityRange(ipallocationpool=ip_pool,
                                                  first_ip=pool['start'],
                                                  last_ip=pool['end'])
         context.session.add(ip_range)
Пример #4
0
    def _update_subnet_allocation_pools(self, context, subnet_id, s):
        context.session.query(models_v2.IPAllocationPool).filter_by(
            subnet_id=subnet_id).delete()
        pools = [(netaddr.IPAddress(p.first, p.version).format(),
                  netaddr.IPAddress(p.last, p.version).format())
                 for p in s['allocation_pools']]
        new_pools = [models_v2.IPAllocationPool(first_ip=p[0],
                                                last_ip=p[1],
                                                subnet_id=subnet_id)
                     for p in pools]
        context.session.add_all(new_pools)

        # Gather new pools for result
        result_pools = [{'start': p[0], 'end': p[1]} for p in pools]
        del s['allocation_pools']
        return result_pools
Пример #5
0
 def _update_subnet_allocation_pools(self, context, subnet_id, s):
     context.session.query(models_v2.IPAllocationPool).filter_by(
         subnet_id=subnet_id).delete()
     new_pools = [models_v2.IPAllocationPool(first_ip=p['start'],
                                             last_ip=p['end'],
                                             subnet_id=subnet_id)
                  for p in s['allocation_pools']]
     context.session.add_all(new_pools)
     # Call static method with self to redefine in child
     # (non-pluggable backend)
     self._rebuild_availability_ranges(context, [s])
     # Gather new pools for result:
     result_pools = [{'start': pool['start'],
                      'end': pool['end']}
                     for pool in s['allocation_pools']]
     del s['allocation_pools']
     return result_pools
Пример #6
0
 def _update_subnet_allocation_pools(self, context, subnet_id, s):
     context.session.query(models_v2.IPAllocationPool).filter_by(
         subnet_id=subnet_id).delete()
     pools = ((netaddr.IPAddress(p.first, p.version).format(),
               netaddr.IPAddress(p.last, p.version).format())
              for p in s['allocation_pools'])
     new_pools = [models_v2.IPAllocationPool(first_ip=p[0],
                                             last_ip=p[1],
                                             subnet_id=subnet_id)
                  for p in pools]
     context.session.add_all(new_pools)
     # Call static method with self to redefine in child
     # (non-pluggable backend)
     self._rebuild_availability_ranges(context, [s])
     # Gather new pools for result
     result_pools = [{'start': p[0], 'end': p[1]} for p in pools]
     del s['allocation_pools']
     return result_pools