blob: 732a5f17fc04363bc0ffa46062c769e4b6086258 [file] [log] [blame]
Tony Mackcafd0b02013-04-17 10:45:12 -04001import os
2os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plstackapi.planetstack.settings")
3import time
4from plstackapi.core.models.sliver import Sliver
5from plstackapi.openstack.client import OpenStackClient
6
7class SliverAgent:
8
9 def run(self):
10 client = OpenStackClient()
11 while True:
12 # fill in null ip addresses
13 slivers = Sliver.objects.filter(ip=None)
14 for sliver in slivers:
Tony Mackffab0f22013-04-29 19:42:20 -040015 # update connection
16 client.connect(username=client.keystone.username,
17 password=client.keystone.password,
18 tenant=sliver.slice.name)
Tony Mackcafd0b02013-04-17 10:45:12 -040019 servers = client.nova.servers.findall(id=sliver.instance_id)
20 if not servers:
21 continue
22 server = servers[0]
23 ips = server.addresses.get(sliver.slice.name, [])
24 if not ips:
25 continue
26 sliver.ip = ips[0]['addr']
27 sliver.save()
28 time.sleep(7)
29
30
31if __name__ == '__main__':
32 SliverAgent().run()
33