blob: 2d7f1f89377927d7f6f0ab5c25af74ea416dc71e [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 Mack387a73f2013-09-18 07:59:14 -040017 driver = self.driver.client_driver(tenant=sliver.slice.name)
Tony Mackce79de02013-09-24 10:12:33 -040018 servers = driver.shell.nova.servers.findall(id=sliver.instance_id)
19 if not servers:
20 return
21 server = servers[0]
22 ips = server.addresses.get(sliver.slice.name, [])
23 if not ips:
24 return
25 sliver.ip = ips[0]['addr']
26 sliver.save()
27 logger.info("saved sliver ip: %s %s" % (sliver, ips[0]))