blob: fb787dbbec6d2fbf42bb2d59703cac5e9ca0b189 [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]
Sapan Bhatia2ef36c82013-09-02 14:30:37 -04007 requested_interval=0
Sapan Bhatia24836f12013-08-27 10:16:05 -04008 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
15
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')
18
19 # refresh credentials using this tenant
20 self.driver.shell.connect(username=self.driver.shell.keystone.username,
21 password=self.driver.shell.keystone.password,
22 tenant=tenant.name)
23
24 # create network
25 network = self.driver.create_network(slice.name)
26 slice.network_id = network['id']
27
28 # create router
29 router = self.driver.create_router(slice.name)
30 slice.router_id = router['id']
31
32 # create subnet
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'],
40 cidr_ip = cidr,
41 ip_version = ip_version,
42 start = start,
43 end = end)
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'])
47 # add external route
48 self.driver.add_external_route(subnet)
49
50
51 if slice.id and slice.tenant_id:
52 self.driver.update_tenant(slice.tenant_id,
53 description=slice.description,
54 enabled=slice.enabled)
55
56 slice.save()