blob: 82d2b1558b913080f2cdbe1de307a6f32a1514b4 [file] [log] [blame]
Sapan Bhatia0a56fdc2017-04-21 15:12:57 +02001def ip_to_mac(self, ip):
2 (a, b, c, d) = ip.split('.')
3 return "02:42:%02x:%02x:%02x:%02x" % (int(a), int(b), int(c), int(d))
4
5def get_gateways(self):
6 gateways = []
7
8 aps = self.addresspools.all()
9 for ap in aps:
10 gateways.append({"gateway_ip": ap.gateway_ip, "gateway_mac": ap.gateway_mac})
11
12 return gateways
13
14def get_address_pool(self, name):
15 ap = AddressPool.objects.filter(name=name, service=self)
16 if not ap:
17 raise Exception("vRouter unable to find addresspool %s" % name)
18 return ap[0]
19
20def get_tenant(self, **kwargs):
21 address_pool_name = kwargs.pop("address_pool_name")
22
23 ap = self.get_address_pool(address_pool_name)
24
25 ip = ap.get_address()
26 if not ip:
27 raise Exception("AddressPool '%s' has run out of addresses." % ap.name)
28
29 t = VRouterTenant(provider_service=self, **kwargs)
30 t.public_ip = ip
31 t.public_mac = self.ip_to_mac(ip)
32 t.address_pool_id = ap.id
33 t.save()
34
35 return t
36