blob: bd1d572149ea907bd333a7b3585013e8eb66e180 [file] [log] [blame]
Sapan Bhatia24836f12013-08-27 10:16:05 -04001import os
2import base64
Tony Mackae7f30c2013-09-25 12:46:50 -04003from django.db.models import F, Q
Sapan Bhatia24836f12013-08-27 10:16:05 -04004from planetstack.config import Config
Sapan Bhatia04c94ad2013-09-02 18:00:28 -04005from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.sliver import Sliver
Sapan Bhatia24836f12013-08-27 10:16:05 -04007
8class SyncSliverIps(OpenStackSyncStep):
Tony Mackce79de02013-09-24 10:12:33 -04009 provides=[Sliver]
10 requested_interval=0
Tony Mack66646d52013-09-24 21:47:12 -040011
Sapan Bhatiab83643c2014-07-23 09:59:32 -040012 def fetch_pending(self, deleted):
13 # Not supported yet
14 if (deleted):
15 return []
Tony Mackce79de02013-09-24 10:12:33 -040016 slivers = Sliver.objects.filter(ip=None)
17 return slivers
Sapan Bhatia24836f12013-08-27 10:16:05 -040018
Tony Mackce79de02013-09-24 10:12:33 -040019 def sync_record(self, sliver):
Tony Macke4be32f2014-03-11 20:45:25 -040020 driver = self.driver.client_driver(tenant=sliver.slice.name,
21 deployment=sliver.node.deployment.name)
Tony Mackce79de02013-09-24 10:12:33 -040022 servers = driver.shell.nova.servers.findall(id=sliver.instance_id)
23 if not servers:
24 return
25 server = servers[0]
26 ips = server.addresses.get(sliver.slice.name, [])
27 if not ips:
28 return
29 sliver.ip = ips[0]['addr']
Tony Mack261f8582014-04-21 17:08:31 -040030 if sliver.ip:
31 sliver.save()
32 logger.info("saved sliver ip: %s %s" % (sliver, ips[0]))