3 from planetstack.config import Config
5 class SyncSlices(OpenStackSyncStep):
8 def sync_record(self, slice):
9 if not slice.tenant_id:
10 nova_fields = {'tenant_name': slice.name,
11 'description': slice.description,
12 'enabled': slice.enabled}
13 tenant = self.driver.create_tenant(**nova_fields)
14 slice.tenant_id = tenant.id
16 # XXX give caller an admin role at the tenant they've created
17 self.driver.add_user_role(self.caller.kuser_id, tenant.id, 'admin')
19 # refresh credentials using this tenant
20 self.driver.shell.connect(username=self.driver.shell.keystone.username,
21 password=self.driver.shell.keystone.password,
25 network = self.driver.create_network(slice.name)
26 slice.network_id = network['id']
29 router = self.driver.create_router(slice.name)
30 slice.router_id = router['id']
33 next_subnet = self.get_next_subnet()
34 cidr = str(next_subnet.cidr)
35 ip_version = next_subnet.version
36 start = str(next_subnet[2])
37 end = str(next_subnet[-2])
38 subnet = self.driver.create_subnet(name=slice.name,
39 network_id = network['id'],
41 ip_version = ip_version,
44 slice.subnet_id = subnet['id']
45 # add subnet as interface to slice's router
46 self.driver.add_router_interface(router['id'], subnet['id'])
48 self.driver.add_external_route(subnet)
51 if slice.id and slice.tenant_id:
52 self.driver.update_tenant(slice.tenant_id,
53 description=slice.description,
54 enabled=slice.enabled)