blob: 736fde6946fe15c0f651147912a86f0901c3583b [file] [log] [blame]
Sapan Bhatia24836f12013-08-27 10:16:05 -04001import os
2import base64
3from planetstack.config import Config
4
5class SyncSlices(OpenStackSyncStep):
6 provides=[Slice]
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
14
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')
17
18 # refresh credentials using this tenant
19 self.driver.shell.connect(username=self.driver.shell.keystone.username,
20 password=self.driver.shell.keystone.password,
21 tenant=tenant.name)
22
23 # create network
24 network = self.driver.create_network(slice.name)
25 slice.network_id = network['id']
26
27 # create router
28 router = self.driver.create_router(slice.name)
29 slice.router_id = router['id']
30
31 # create subnet
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'],
39 cidr_ip = cidr,
40 ip_version = ip_version,
41 start = start,
42 end = end)
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'])
46 # add external route
47 self.driver.add_external_route(subnet)
48
49
50 if slice.id and slice.tenant_id:
51 self.driver.update_tenant(slice.tenant_id,
52 description=slice.description,
53 enabled=slice.enabled)
54
55 slice.save()