def create(self): if self.state != None: return self.state_set(self.CREATE_IN_PROGRESS) Resource.create(self) self._get_handle_resource_id() # keep polling our Metadata to see if the cfn-signal has written # it yet. The execution here is limited by timeout. print "timeout %d" % self.timeout tmo = eventlet.Timeout(self.timeout) status = "WAITING" reason = "" try: while status == "WAITING": pt = None if self.stack.parsed_template_id: try: pt = db_api.parsed_template_get(None, self.stack.parsed_template_id) except Exception as ex: if "not found" in ex: # entry deleted return else: pass if pt: res = pt.template["Resources"][self.resource_id] metadata = res.get("Metadata", {}) status = metadata.get("Status", "WAITING") reason = metadata.get("Reason", "Reason not provided") logger.debug("got %s" % json.dumps(metadata)) if status == "WAITING": logger.debug("Waiting some more for the Metadata[Status]") eventlet.sleep(30) except eventlet.Timeout, t: if t is not tmo: # not my timeout raise else: status = "TIMEDOUT" reason = "Timed out waiting for instance"
def update_parsed_template(self): ''' Update the parsed template after each resource has been created, so commands like describe will work. ''' if self.parsed_template_id == 0: stack = db_api.stack_get(None, self.name) if stack: self.parsed_template_id = stack.raw_template.parsed_template.id else: return pt = db_api.parsed_template_get(None, self.parsed_template_id) if pt: pt.template = self.t pt.save() else: logger.warn('Cant find parsed template to update %d' % \ self.parsed_template_id)
def metadata_update(self, context, stack_name, resource_id, metadata): """ Update the metadata for the given resource. """ s = db_api.stack_get(None, stack_name) if not s: return ["stack", None] pt_id = s.raw_template.parsed_template.id pt = db_api.parsed_template_get(None, pt_id) if not resource_id in pt.template.get("Resources", {}): return ["resource", None] # TODO(shadower) deep copy of the template is required here. Without # it, we directly modify parsed_template.template by assigning the new # metadata. When we then call parsed_template.update_and_save, the # session will detect no changes and thus not update the database. # Just updating the values and calling save didn't seem to work either. # There's probably an idiomatic way I'm missing right now. t = deepcopy(pt.template) t["Resources"][resource_id]["Metadata"] = metadata pt.template = t pt.save() return [None, metadata]