Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
| 3 | from planetstack.config import Config |
| 4 | |
| 5 | class SyncSliverIps(OpenStackSyncStep): |
| 6 | provides=[Sliver] |
Sapan Bhatia | 2ef36c8 | 2013-09-02 14:30:37 -0400 | [diff] [blame^] | 7 | requested_interval=0 |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 8 | def fetch_pending(self): |
| 9 | slivers = Sliver.objects.filter(ip=None) |
| 10 | return slivers |
| 11 | |
| 12 | def sync_record(self, sliver): |
| 13 | self.manager.init_admin(tenant=sliver.slice.name) |
| 14 | servers = self.manager.driver.shell.nova.servers.findall(id=sliver.instance_id) |
| 15 | if not servers: |
| 16 | continue |
| 17 | server = servers[0] |
| 18 | ips = server.addresses.get(sliver.slice.name, []) |
| 19 | if not ips: |
| 20 | continue |
| 21 | sliver.ip = ips[0]['addr'] |
| 22 | sliver.save() |
| 23 | logger.info("saved sliver ip: %s %s" % (sliver, ips[0])) |