blob: 322cdfdeb7632c4ed3f38e08852ca6d4838c5c2a [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:
15 servers = client.nova.servers.findall(id=sliver.instance_id)
16 if not servers:
17 continue
18 server = servers[0]
19 ips = server.addresses.get(sliver.slice.name, [])
20 if not ips:
21 continue
22 sliver.ip = ips[0]['addr']
23 sliver.save()
24 time.sleep(7)
25
26
27if __name__ == '__main__':
28 SliverAgent().run()
29