def get_output(self, op): """Return the specified Output value from the nested stack. If the output key does not exist, raise a NotFound exception. """ if (self._outputs is None or (op in self._outputs and rpc_api.OUTPUT_ERROR not in self._outputs[op] and self._outputs[op].get(rpc_api.OUTPUT_VALUE) is None)): stack_identity = self.nested_identifier() if stack_identity is None: return stack = self.rpc_client().show_stack(self.context, dict(stack_identity)) if not stack: return outputs = stack[0].get(rpc_api.STACK_OUTPUTS) or {} self._outputs = {o[rpc_api.OUTPUT_KEY]: o for o in outputs} if op not in self._outputs: raise exception.NotFound(_('Specified output key %s not ' 'found.') % op) output_data = self._outputs[op] if rpc_api.OUTPUT_ERROR in output_data: raise exception.TemplateOutputError( resource=self.name, attribute=op, message=output_data[rpc_api.OUTPUT_ERROR]) return output_data[rpc_api.OUTPUT_VALUE]
def get_output(self, op): """Return the specified Output value from the nested stack. If the output key does not exist, raise an InvalidTemplateAttribute exception. (Note that TemplateResource.get_attribute() relies on this particular exception, not KeyError, being raised if the key does not exist.) """ if (self._outputs is None or (op in self._outputs and rpc_api.OUTPUT_ERROR not in self._outputs[op] and self._outputs[op].get(rpc_api.OUTPUT_VALUE) is None)): stack_identity = self.nested_identifier() if stack_identity is None: return stack = self.rpc_client().show_stack(self.context, dict(stack_identity)) if not stack: return outputs = stack[0].get(rpc_api.STACK_OUTPUTS) or {} self._outputs = {o[rpc_api.OUTPUT_KEY]: o for o in outputs} if op not in self._outputs: raise exception.InvalidTemplateAttribute(resource=self.name, key=op) output_data = self._outputs[op] if rpc_api.OUTPUT_ERROR in output_data: raise exception.TemplateOutputError( resource=self.name, attribute=op, message=output_data[rpc_api.OUTPUT_ERROR]) return output_data[rpc_api.OUTPUT_VALUE]
def get_reference_id(self): if self.resource_id is None: return six.text_type(self.name) if STACK_ID_OUTPUT in self.attributes.cached_attrs: return self.attributes.cached_attrs[STACK_ID_OUTPUT] stack_identity = self.nested_identifier() reference_id = stack_identity.arn() try: if self._outputs is not None: reference_id = self.get_output(STACK_ID_OUTPUT) elif STACK_ID_OUTPUT in self.attributes: output = self.rpc_client().show_output(self.context, dict(stack_identity), STACK_ID_OUTPUT) if rpc_api.OUTPUT_ERROR in output: raise exception.TemplateOutputError( resource=self.name, attribute=STACK_ID_OUTPUT, message=output[rpc_api.OUTPUT_ERROR]) reference_id = output[rpc_api.OUTPUT_VALUE] except exception.TemplateOutputError as err: LOG.info('%s', err) except exception.NotFound: pass self.attributes.set_cached_attr(STACK_ID_OUTPUT, reference_id) return reference_id
def get_reference_id(self): if self.resource_id is None: return six.text_type(self.name) stack_identity = self.nested_identifier() try: if self._outputs is not None: return self.get_output(STACK_ID_OUTPUT) output = self.rpc_client().show_output(self.context, dict(stack_identity), STACK_ID_OUTPUT) if rpc_api.OUTPUT_ERROR in output: raise exception.TemplateOutputError( resource=self.name, attribute=STACK_ID_OUTPUT, message=output[rpc_api.OUTPUT_ERROR]) except (exception.InvalidTemplateAttribute, exception.NotFound): pass else: return output[rpc_api.OUTPUT_VALUE] return stack_identity.arn()