checking in latest sync_slices code. move get_next_subnet to sync_slices
diff --git a/planetstack/observer/steps/sync_slices.py b/planetstack/observer/steps/sync_slices.py
index 9ba5ab7..53dc06b 100644
--- a/planetstack/observer/steps/sync_slices.py
+++ b/planetstack/observer/steps/sync_slices.py
@@ -1,5 +1,6 @@
import os
import base64
+from netaddr import IPAddress, IPNetwork
from django.db.models import F, Q
from planetstack.config import Config
from observer.openstacksyncstep import OpenStackSyncStep
@@ -12,6 +13,17 @@
def fetch_pending(self):
return Slice.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
+ def get_next_subnet(self):
+ # limit ourself to 10.0.x.x for now
+ valid_subnet = lambda net: net.startswith('10.0')
+ subnets = self.driver.shell.quantum.list_subnets()['subnets']
+ ints = [int(IPNetwork(subnet['cidr']).ip) for subnet in subnets \
+ if valid_subnet(subnet['cidr'])]
+ ints.sort()
+ last_ip = IPAddress(ints[-1])
+ last_network = IPNetwork(str(last_ip) + "/24")
+ next_network = IPNetwork(str(IPAddress(last_network) + last_network.size) + "/24")
+
def sync_record(self, slice):
if not slice.tenant_id:
nova_fields = {'tenant_name': slice.name,
@@ -21,19 +33,17 @@
slice.tenant_id = tenant.id
# XXX give caller an admin role at the tenant they've created
- self.driver.add_user_role(self.caller.kuser_id, tenant.id, 'admin')
+ self.driver.add_user_role(slice.creator.kuser_id, tenant.id, 'admin')
# refresh credentials using this tenant
- self.driver.shell.connect(username=self.driver.shell.keystone.username,
- password=self.driver.shell.keystone.password,
- tenant=tenant.name)
+ client_driver = self.driver.client_driver(tenant=tenant.name)
# create network
- network = self.driver.create_network(slice.name)
+ network = client_driver.create_network(slice.name)
slice.network_id = network['id']
# create router
- router = self.driver.create_router(slice.name)
+ router = client_driver.create_router(slice.name)
slice.router_id = router['id']
# create subnet
@@ -42,7 +52,7 @@
ip_version = next_subnet.version
start = str(next_subnet[2])
end = str(next_subnet[-2])
- subnet = self.driver.create_subnet(name=slice.name,
+ subnet = client_driver.create_subnet(name=slice.name,
network_id = network['id'],
cidr_ip = cidr,
ip_version = ip_version,
@@ -50,13 +60,13 @@
end = end)
slice.subnet_id = subnet['id']
# add subnet as interface to slice's router
- self.driver.add_router_interface(router['id'], subnet['id'])
+ client_driver.add_router_interface(router['id'], subnet['id'])
# add external route
- self.driver.add_external_route(subnet)
+ client_driver.add_external_route(subnet)
if slice.id and slice.tenant_id:
- self.driver.update_tenant(slice.tenant_id,
+ client_driver.update_tenant(slice.tenant_id,
description=slice.description,
enabled=slice.enabled)
diff --git a/planetstack/openstack/driver.py b/planetstack/openstack/driver.py
index febac32..8224c17 100644
--- a/planetstack/openstack/driver.py
+++ b/planetstack/openstack/driver.py
@@ -1,4 +1,5 @@
import commands
+import hashlib
from planetstack.config import Config
try: