blob: 46f78fdf635038e612de12d09df51a55fe6680fa [file] [log] [blame]
Sapan Bhatia24836f12013-08-27 10:16:05 -04001import os
2import base64
3from planetstack.config import Config
4
5class SyncSlivers(OpenStackSyncStep):
6 provides=[Sliver]
Sapan Bhatia2ef36c82013-09-02 14:30:37 -04007 requested_interval=0
Sapan Bhatia24836f12013-08-27 10:16:05 -04008 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()