3 from planetstack.config import Config
4 from observer.openstacksyncstep import OpenStackSyncStep
5 from core.models.slice import Slice
7 class SyncSlices(OpenStackSyncStep):
11 def fetch_pending(self):
12 return Slice.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
14 def sync_record(self, slice):
15 if not slice.tenant_id:
16 nova_fields = {'tenant_name': slice.name,
17 'description': slice.description,
18 'enabled': slice.enabled}
19 tenant = self.driver.create_tenant(**nova_fields)
20 slice.tenant_id = tenant.id
22 # XXX give caller an admin role at the tenant they've created
23 self.driver.add_user_role(self.caller.kuser_id, tenant.id, 'admin')
25 # refresh credentials using this tenant
26 self.driver.shell.connect(username=self.driver.shell.keystone.username,
27 password=self.driver.shell.keystone.password,
31 network = self.driver.create_network(slice.name)
32 slice.network_id = network['id']
35 router = self.driver.create_router(slice.name)
36 slice.router_id = router['id']
39 next_subnet = self.get_next_subnet()
40 cidr = str(next_subnet.cidr)
41 ip_version = next_subnet.version
42 start = str(next_subnet[2])
43 end = str(next_subnet[-2])
44 subnet = self.driver.create_subnet(name=slice.name,
45 network_id = network['id'],
47 ip_version = ip_version,
50 slice.subnet_id = subnet['id']
51 # add subnet as interface to slice's router
52 self.driver.add_router_interface(router['id'], subnet['id'])
54 self.driver.add_external_route(subnet)
57 if slice.id and slice.tenant_id:
58 self.driver.update_tenant(slice.tenant_id,
59 description=slice.description,
60 enabled=slice.enabled)