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