def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn):
        for attr in self.referenced_attrs():
            if isinstance(attr, str):
                key, path = attr, []
            else:
                key, path = attr[0], list(attr[1:])
            # Always use map types, as list order is not defined at
            # template generation time.
            if key == self.OUTPUTS_LIST:
                key = self.OUTPUTS
            if key.startswith("resource."):
                keycomponents = key.split('.', 2)
                path = keycomponents[2:] + path
                if path:
                    key = self.OUTPUTS
            output_name = self._attribute_output_name(key, *path)

            if key == self.OUTPUTS and path:
                value = {r: get_attr_fn([r] + path) for r in resource_names}
                yield output.OutputDefinition(output_name, value)

        # Always define an output for the member IDs, which also doubles as the
        # output used by the REFS and REFS_MAP attributes.
        member_ids_value = {r: get_res_fn(r) for r in resource_names}
        yield output.OutputDefinition(self.OUTPUT_MEMBER_IDS, member_ids_value)
Example #2
0
    def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn):
        for attr in self.referenced_attrs():
            if isinstance(attr, six.string_types):
                key, path = attr, []
            else:
                key, path = attr[0], list(attr[1:])
            output_name = self._attribute_output_name(key, *path)
            value = None

            if key.startswith("resource."):
                keycomponents = key.split('.', 2)
                res_name = keycomponents[1]
                attr_path = keycomponents[2:] + path
                if attr_path:
                    if res_name in resource_names:
                        value = get_attr_fn([res_name] + attr_path)
                else:
                    output_name = key = self.REFS_MAP
            elif key == self.ATTR_ATTRIBUTES and path:
                value = {r: get_attr_fn([r] + path) for r in resource_names}
            elif key not in self.ATTRIBUTES:
                value = [get_attr_fn([r, key] + path) for r in resource_names]

            if key == self.REFS:
                value = [get_res_fn(r) for r in resource_names]

            if value is not None:
                yield output.OutputDefinition(output_name, value)

        value = {r: get_res_fn(r) for r in resource_names}
        yield output.OutputDefinition(self.REFS_MAP, value)
Example #3
0
    def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn):
        for attr in self.referenced_attrs():
            if isinstance(attr, six.string_types):
                key = attr
            else:
                key = attr[0]

            if key == self.INSTANCE_LIST:
                value = {r: get_attr_fn([r, 'PublicIp'])
                         for r in resource_names}
                yield output.OutputDefinition(key, value)

        member_ids_value = {r: get_res_fn(r) for r in resource_names}
        yield output.OutputDefinition(self.OUTPUT_MEMBER_IDS,
                                      member_ids_value)
Example #4
0
    def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn):
        for attr in self.referenced_attrs():
            if isinstance(attr, six.string_types):
                key, path = attr, []
            else:
                key, path = attr[0], list(attr[1:])
            # Always use map types, as list order is not defined at
            # template generation time.
            if key == self.OUTPUTS_LIST:
                key = self.OUTPUTS
            if key == self.REFS:
                key = self.REFS_MAP
            if key.startswith("resource."):
                keycomponents = key.split('.', 2)
                path = keycomponents[2:] + path
                if path:
                    key = self.OUTPUTS
                else:
                    key = self.REFS_MAP
            output_name = self._attribute_output_name(key, *path)
            value = None

            if key == self.REFS_MAP:
                value = {r: get_res_fn(r) for r in resource_names}
            elif key == self.OUTPUTS and path:
                value = {r: get_attr_fn([r] + path) for r in resource_names}

            if value is not None:
                yield output.OutputDefinition(output_name, value)
Example #5
0
 def _nested_output_defns(self, resource_names, get_attr_fn):
     for attr in self.referenced_attrs():
         key = attr if isinstance(attr, six.string_types) else attr[0]
         n_attr = self._member_attribute_name(key)
         output_name = '%s, %s' % (self.ATTR_ATTRIBUTES, n_attr)
         value = {r: get_attr_fn([r, n_attr]) for r in resource_names}
         yield output.OutputDefinition(output_name, value)
        def get_outputs():
            for key, val in outputs.items():
                if not isinstance(val, collections.Mapping):
                    message = _('Output definitions must be a map. Found a '
                                '%s instead') % type(val).__name__
                    raise exception.StackValidationFailed(
                        error='Output validation error',
                        path=[self.OUTPUTS, key],
                        message=message)

                if self.OUTPUT_VALUE not in val:
                    message = _('Each output definition must contain '
                                'a %s key.') % self.OUTPUT_VALUE
                    raise exception.StackValidationFailed(
                        error='Output validation error',
                        path=[self.OUTPUTS, key],
                        message=message)

                description = val.get(self.OUTPUT_DESCRIPTION)

                if hasattr(self, 'OUTPUT_CONDITION'):
                    path = [self.OUTPUTS, key, self.OUTPUT_CONDITION]
                    cond = self.parse_condition(stack,
                                                val.get(self.OUTPUT_CONDITION),
                                                '.'.join(path))
                    try:
                        enabled = conds.is_enabled(function.resolve(cond))
                    except ValueError as exc:
                        path = [self.OUTPUTS, key, self.OUTPUT_CONDITION]
                        message = six.text_type(exc)
                        raise exception.StackValidationFailed(path=path,
                                                              message=message)

                    if not enabled:
                        yield key, output.OutputDefinition(
                            key, None, description)
                        continue

                value_def = self.parse(
                    stack,
                    val[self.OUTPUT_VALUE],
                    path='.'.join([self.OUTPUTS, key, self.OUTPUT_VALUE]))

                yield key, output.OutputDefinition(key, value_def, description)
Example #7
0
    def _nested_output_defns(self, resource_names, get_attr_fn):
        for attr in self.referenced_attrs():
            if isinstance(attr, six.string_types):
                key = attr
            else:
                key = attr[0]

            if key == self.INSTANCE_LIST:
                value = [get_attr_fn([r, 'PublicIp']) for r in resource_names]
                yield output.OutputDefinition(key, value)
Example #8
0
    def test_get_output_ok(self):
        nested = self.m.CreateMockAnything()
        self.m.StubOutWithMock(stack_resource.StackResource, 'nested')
        stack_resource.StackResource.nested().AndReturn(nested)
        nested.outputs = {"key": output.OutputDefinition("key", "value")}
        self.m.ReplayAll()

        self.assertEqual("value", self.parent_resource.get_output("key"))

        self.m.VerifyAll()
Example #9
0
    def test_resolve_attribute_list(self):
        nested = self.m.CreateMockAnything()
        self.m.StubOutWithMock(stack_resource.StackResource, 'nested')
        stack_resource.StackResource.nested().AndReturn(nested)
        nested.outputs = {'key': output.OutputDefinition('key', [1, 2, 3])}
        self.m.ReplayAll()

        self.assertEqual([1, 2, 3],
                         self.parent_resource._resolve_attribute("key"))

        self.m.VerifyAll()
Example #10
0
    def _nested_output_defns(self, resource_names, get_attr_fn):
        for attr in self.referenced_attrs():
            if isinstance(attr, six.string_types):
                key, path = attr, []
                output_name = attr
            else:
                key, path = attr[0], list(attr[1:])
                output_name = ', '.join(six.text_type(a) for a in attr)

            if key.startswith("resource."):
                keycomponents = key.split('.', 2)
                path = keycomponents[2:] + path
                if path:
                    key = self.OUTPUTS
                    output_name = ', '.join([self.OUTPUTS] + path)

            if key == self.OUTPUTS and path:
                value = {r: get_attr_fn([r] + path) for r in resource_names}
                yield output.OutputDefinition(output_name, value)

            elif key == self.OUTPUTS_LIST and path:
                value = [get_attr_fn([r] + path) for r in resource_names]
                yield output.OutputDefinition(output_name, value)
Example #11
0
    def _nested_output_defns(self, resource_names, get_attr_fn):
        for attr in self.referenced_attrs():
            if isinstance(attr, six.string_types):
                key, path = attr, []
                output_name = attr
            else:
                key, path = attr[0], list(attr[1:])
                output_name = ', '.join(six.text_type(a) for a in attr)

            if key.startswith("resource."):
                keycomponents = key.split('.', 2)
                res_name = keycomponents[1]
                attr_name = keycomponents[2:]
                if attr_name and (res_name in resource_names):
                    value = get_attr_fn([res_name] + attr_name + path)
                    yield output.OutputDefinition(output_name, value)

            elif key == self.ATTR_ATTRIBUTES and path:
                value = {r: get_attr_fn([r] + path) for r in resource_names}
                yield output.OutputDefinition(output_name, value)

            elif key not in self.ATTRIBUTES:
                value = [get_attr_fn([r, key] + path) for r in resource_names]
                yield output.OutputDefinition(output_name, value)
Example #12
0
        def get_outputs():
            for key, val in outputs.items():
                if not isinstance(val, collections.Mapping):
                    message = _('Outputs must contain Output. '
                                'Found a [%s] instead') % type(val)
                    raise exception.StackValidationFailed(
                        error='Output validation error',
                        path=[self.OUTPUTS, key],
                        message=message)

                if self.OUTPUT_VALUE not in val:
                    message = _('Each output must contain '
                                'a %s key.') % self.OUTPUT_VALUE
                    raise exception.StackValidationFailed(
                        error='Output validation error',
                        path=[self.OUTPUTS, key],
                        message=message)

                value_def = val[self.OUTPUT_VALUE]
                description = val.get(self.OUTPUT_DESCRIPTION)

                yield key, output.OutputDefinition(key, value_def, description)