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