Sapan Bhatia | 26d40bc | 2014-05-12 15:28:02 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from django.db.models import F, Q |
| 4 | from planetstack.config import Config |
| 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.sliver import Sliver |
| 7 | |
| 8 | class 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])) |