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