blob: f07f6038946d995e8f9385fa5efa8647d3608f6d [file] [log] [blame]
Tony Mackcafd0b02013-04-17 10:45:12 -04001import os
Tony Mack951dab42013-05-02 19:51:45 -04002import sys
Tony Mackcafd0b02013-04-17 10:45:12 -04003os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plstackapi.planetstack.settings")
4import time
5from plstackapi.core.models.sliver import Sliver
Tony Mack951dab42013-05-02 19:51:45 -04006from plstackapi.openstack.manager import OpenStackManager
Tony Mackcafd0b02013-04-17 10:45:12 -04007
8class SliverAgent:
9
10 def run(self):
Tony Mack951dab42013-05-02 19:51:45 -040011 manager = OpenStackManager()
12 # exit if openstack is disable or unavailable
13 if not manager.enabled or not manager.has_openstack:
14 sys.exit()
15
16 while True :
Tony Mackcafd0b02013-04-17 10:45:12 -040017 # fill in null ip addresses
18 slivers = Sliver.objects.filter(ip=None)
19 for sliver in slivers:
Tony Mackffab0f22013-04-29 19:42:20 -040020 # update connection
Tony Mack951dab42013-05-02 19:51:45 -040021 manager.client.connect(username=manager.client.keystone.username,
22 password=manager.client.keystone.password,
Tony Mackffab0f22013-04-29 19:42:20 -040023 tenant=sliver.slice.name)
Tony Mack951dab42013-05-02 19:51:45 -040024 sliver.os_manager = manager
25 servers = manager.client.nova.servers.findall(id=sliver.instance_id)
Tony Mackcafd0b02013-04-17 10:45:12 -040026 if not servers:
27 continue
28 server = servers[0]
29 ips = server.addresses.get(sliver.slice.name, [])
30 if not ips:
31 continue
32 sliver.ip = ips[0]['addr']
33 sliver.save()
34 time.sleep(7)
35
36
37if __name__ == '__main__':
38 SliverAgent().run()
39