blob: 4aea44d91d365ab0abd02581e714b8defeade8ae [file] [log] [blame]
Tony Mackcafd0b02013-04-17 10:45:12 -04001import os
Tony Mack951dab42013-05-02 19:51:45 -04002import sys
Scott Baker76a840e2015-02-11 21:38:09 -08003#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.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