Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
Tony Mack | ae7f30c | 2013-09-25 12:46:50 -0400 | [diff] [blame] | 3 | from django.db.models import F, Q |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 4 | from planetstack.config import Config |
Sapan Bhatia | 04c94ad | 2013-09-02 18:00:28 -0400 | [diff] [blame] | 5 | from observer.openstacksyncstep import OpenStackSyncStep |
| 6 | from core.models.sliver import Sliver |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 7 | |
| 8 | class SyncSliverIps(OpenStackSyncStep): |
Tony Mack | ce79de0 | 2013-09-24 10:12:33 -0400 | [diff] [blame] | 9 | provides=[Sliver] |
| 10 | requested_interval=0 |
Tony Mack | 66646d5 | 2013-09-24 21:47:12 -0400 | [diff] [blame] | 11 | |
Sapan Bhatia | b83643c | 2014-07-23 09:59:32 -0400 | [diff] [blame] | 12 | def fetch_pending(self, deleted): |
| 13 | # Not supported yet |
| 14 | if (deleted): |
| 15 | return [] |
Tony Mack | ce79de0 | 2013-09-24 10:12:33 -0400 | [diff] [blame] | 16 | slivers = Sliver.objects.filter(ip=None) |
| 17 | return slivers |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 18 | |
Tony Mack | ce79de0 | 2013-09-24 10:12:33 -0400 | [diff] [blame] | 19 | def sync_record(self, sliver): |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 20 | driver = self.driver.client_driver(tenant=sliver.slice.name, |
| 21 | deployment=sliver.node.deployment.name) |
Tony Mack | ce79de0 | 2013-09-24 10:12:33 -0400 | [diff] [blame] | 22 | servers = driver.shell.nova.servers.findall(id=sliver.instance_id) |
| 23 | if not servers: |
| 24 | return |
| 25 | server = servers[0] |
| 26 | ips = server.addresses.get(sliver.slice.name, []) |
| 27 | if not ips: |
| 28 | return |
| 29 | sliver.ip = ips[0]['addr'] |
Tony Mack | 261f858 | 2014-04-21 17:08:31 -0400 | [diff] [blame] | 30 | if sliver.ip: |
| 31 | sliver.save() |
| 32 | logger.info("saved sliver ip: %s %s" % (sliver, ips[0])) |