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: |
Tony Mack | ffab0f2 | 2013-04-29 19:42:20 -0400 | [diff] [blame] | 15 | # update connection |
| 16 | client.connect(username=client.keystone.username, |
| 17 | password=client.keystone.password, |
| 18 | tenant=sliver.slice.name) |
Tony Mack | cafd0b0 | 2013-04-17 10:45:12 -0400 | [diff] [blame] | 19 | 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 | |
| 31 | if __name__ == '__main__': |
| 32 | SliverAgent().run() |
| 33 | |