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 SyncSlivers(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 sync_record(self, slice): |
| 9 | if not sliver.instance_id: |
| 10 | nics = self.get_requested_networks(sliver.slice) |
| 11 | file("/tmp/scott-manager","a").write("slice: %s\nreq: %s\n" % (str(sliver.slice.name), str(nics))) |
| 12 | slice_memberships = SliceMembership.objects.filter(slice=sliver.slice) |
| 13 | pubkeys = [sm.user.public_key for sm in slice_memberships if sm.user.public_key] |
| 14 | pubkeys.append(sliver.creator.public_key) |
| 15 | instance = self.driver.spawn_instance(name=sliver.name, |
| 16 | key_name = sliver.creator.keyname, |
| 17 | image_id = sliver.image.image_id, |
| 18 | hostname = sliver.node.name, |
| 19 | pubkeys = pubkeys, |
| 20 | nics = nics ) |
| 21 | sliver.instance_id = instance.id |
| 22 | sliver.instance_name = getattr(instance, 'OS-EXT-SRV-ATTR:instance_name') |
| 23 | |
| 24 | if sliver.instance_id and ("numberCores" in sliver.changed_fields): |
| 25 | self.driver.update_instance_metadata(sliver.instance_id, {"cpu_cores": str(sliver.numberCores)}) |
| 26 | |
| 27 | sliver.save() |