blob: e2212d17863dd717631c31add6ce210e03fb278a [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
Tony Mackce79de02013-09-24 10:12:33 -040012 def fetch_pending(self):
13 slivers = Sliver.objects.filter(ip=None)
14 return slivers
Sapan Bhatia24836f12013-08-27 10:16:05 -040015
Tony Mackce79de02013-09-24 10:12:33 -040016 def sync_record(self, sliver):
Tony Macke4be32f2014-03-11 20:45:25 -040017 driver = self.driver.client_driver(tenant=sliver.slice.name,
18 deployment=sliver.node.deployment.name)
Tony Mackce79de02013-09-24 10:12:33 -040019 servers = driver.shell.nova.servers.findall(id=sliver.instance_id)
20 if not servers:
21 return
22 server = servers[0]
23 ips = server.addresses.get(sliver.slice.name, [])
24 if not ips:
25 return
26 sliver.ip = ips[0]['addr']
Tony Mack261f8582014-04-21 17:08:31 -040027 if sliver.ip:
28 sliver.save()
29 logger.info("saved sliver ip: %s %s" % (sliver, ips[0]))