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