Tony Mack | cafd0b0 | 2013-04-17 10:45:12 -0400 | [diff] [blame] | 1 | import os |
| 2 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plstackapi.planetstack.settings") |
| 3 | import time |
| 4 | from plstackapi.core.models.sliver import Sliver |
| 5 | from plstackapi.openstack.client import OpenStackClient |
| 6 | |
| 7 | class 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 | |
| 27 | if __name__ == '__main__': |
| 28 | SliverAgent().run() |
| 29 | |