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] |
| 7 | def fetch_pending(self): |
| 8 | slivers = Sliver.objects.filter(ip=None) |
| 9 | return slivers |
| 10 | |
| 11 | def sync_record(self, sliver): |
| 12 | self.manager.init_admin(tenant=sliver.slice.name) |
| 13 | servers = self.manager.driver.shell.nova.servers.findall(id=sliver.instance_id) |
| 14 | if not servers: |
| 15 | continue |
| 16 | server = servers[0] |
| 17 | ips = server.addresses.get(sliver.slice.name, []) |
| 18 | if not ips: |
| 19 | continue |
| 20 | sliver.ip = ips[0]['addr'] |
| 21 | sliver.save() |
| 22 | logger.info("saved sliver ip: %s %s" % (sliver, ips[0])) |