blob: b2f29cfa3ea6e4d1e50bf44c8161d7988b7d8be3 [file] [log] [blame]
Tony Mackcafd0b02013-04-17 10:45:12 -04001import os
Tony Mack951dab42013-05-02 19:51:45 -04002import sys
Siobhan Tully30fd4292013-05-10 08:59:56 -04003#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
Tony Mackcafd0b02013-04-17 10:45:12 -04004import time
Siobhan Tully30fd4292013-05-10 08:59:56 -04005from core.models.sliver import Sliver
6from 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