blob: adab39d8d63cbea8e20208489347918dda03b72d [file] [log] [blame]
Sapan Bhatia24836f12013-08-27 10:16:05 -04001import os
2import base64
3from planetstack.config import Config
Sapan Bhatia04c94ad2013-09-02 18:00:28 -04004from observer.openstacksyncstep import OpenStackSyncStep
5from core.models.sliver import Sliver
Sapan Bhatia24836f12013-08-27 10:16:05 -04006
7class SyncSlivers(OpenStackSyncStep):
8 provides=[Sliver]
Sapan Bhatia2ef36c82013-09-02 14:30:37 -04009 requested_interval=0
Sapan Bhatia24836f12013-08-27 10:16:05 -040010 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 Bhatia04c94ad2013-09-02 18:00:28 -040018 key_name = sliver.creator.keyname,
19 image_id = sliver.image.image_id,
20 hostname = sliver.node.name,
21 pubkeys = pubkeys,
22 nics = nics )
Sapan Bhatia24836f12013-08-27 10:16:05 -040023 sliver.instance_id = instance.id
24 sliver.instance_name = getattr(instance, 'OS-EXT-SRV-ATTR:instance_name')
25
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040026 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 Bhatia24836f12013-08-27 10:16:05 -040028
Sapan Bhatia04c94ad2013-09-02 18:00:28 -040029 sliver.save()