blob: e2212d17863dd717631c31add6ce210e03fb278a [file] [log] [blame]
Sapan Bhatia26d40bc2014-05-12 15:28:02 -04001import os
2import base64
3from django.db.models import F, Q
4from planetstack.config import Config
5from observer.openstacksyncstep import OpenStackSyncStep
6from core.models.sliver import Sliver
7
8class SyncSliverIps(OpenStackSyncStep):
9 provides=[Sliver]
10 requested_interval=0
11
12 def fetch_pending(self):
13 slivers = Sliver.objects.filter(ip=None)
14 return slivers
15
16 def sync_record(self, sliver):
17 driver = self.driver.client_driver(tenant=sliver.slice.name,
18 deployment=sliver.node.deployment.name)
19 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']
27 if sliver.ip:
28 sliver.save()
29 logger.info("saved sliver ip: %s %s" % (sliver, ips[0]))