blob: d69fd5d375d5c4f6cd00cfc1f13520f9ac11813b [file] [log] [blame]
Sapan Bhatia24836f12013-08-27 10:16:05 -04001import os
2import base64
3from planetstack.config import Config
Sapan Bhatia04c94ad2013-09-02 18:00:28 -04004from observer.openstacksyncstep import OpenStackSyncStep
5from core.models.sliver import Sliver
Sapan Bhatia24836f12013-08-27 10:16:05 -04006
7class SyncSliverIps(OpenStackSyncStep):
8 provides=[Sliver]
Sapan Bhatia2ef36c82013-09-02 14:30:37 -04009 requested_interval=0
Sapan Bhatia24836f12013-08-27 10:16:05 -040010 def fetch_pending(self):
11 slivers = Sliver.objects.filter(ip=None)
12 return slivers
13
14 def sync_record(self, sliver):
15 self.manager.init_admin(tenant=sliver.slice.name)
16 servers = self.manager.driver.shell.nova.servers.findall(id=sliver.instance_id)
17 if not servers:
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040018 return
Sapan Bhatia24836f12013-08-27 10:16:05 -040019 server = servers[0]
20 ips = server.addresses.get(sliver.slice.name, [])
21 if not ips:
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040022 return
Sapan Bhatia24836f12013-08-27 10:16:05 -040023 sliver.ip = ips[0]['addr']
24 sliver.save()
25 logger.info("saved sliver ip: %s %s" % (sliver, ips[0]))