Example #1
0
        def wrapper(cloudify_agent):

            attr = AGENT_ATTRIBUTES.get(name)
            if attr is None:
                raise RuntimeError('{0} is not an agent attribute'
                                   .format(name))

            context_attribute = attr.get('context_attribute', name)

            node_properties = ctx.node.properties['cloudify_agent']
            agent_context = ctx.bootstrap_context.cloudify_agent
            runtime_properties = ctx.instance.runtime_properties.get(
                'cloudify_agent', {})

            # if the property was given in the invocation, use it.
            if name in cloudify_agent:
                return

            # if the property is inside a runtime property, use it.
            if name in runtime_properties:
                cloudify_agent[name] = runtime_properties[
                    name]
                return

            # if the property is declared on the node, use it
            if name in node_properties:
                cloudify_agent[name] = node_properties[name]
                return

            # if the property is inside the bootstrap context,
            # and its value is not None, use it
            if hasattr(agent_context, context_attribute):
                value = getattr(agent_context, context_attribute)
                if value is not None:
                    cloudify_agent[name] = value
                return

            # apply the function itself
            ctx.logger.debug('Applying function:{0} on Attribute '
                             '<{1}>'.format(function.__name__, name))
            value = function(cloudify_agent)
            if value is not None:
                ctx.logger.debug('{0} set by function:{1}'
                                 .format(name, value))
                cloudify_agent[name] = value
                return

            # set default value
            default = AGENT_ATTRIBUTES[name].get('default')
            if default is not None:
                ctx.logger.debug('{0} set by default value'
                                 .format(name, value))
                cloudify_agent[name] = default
Example #2
0
        def wrapper(cloudify_agent, *args, **kwargs):

            # collect all attributes belonging to that group
            group_attributes = {}
            for attr_name, attr_value in AGENT_ATTRIBUTES.iteritems():
                if attr_value.get('group') == name:
                    group_attributes[attr_name] = attr_value

            for group_attr_name in group_attributes.iterkeys():
                # iterate and try to set all the attributes of the group as
                # defined in the heuristics of @attribute.
                @attribute(group_attr_name)
                def setter(_):
                    pass

                setter(cloudify_agent)

            # when we are done, invoke the group function to
            # apply group logic
            group_function(cloudify_agent, *args, **kwargs)
Example #3
0
        def wrapper(cloudify_agent, *args, **kwargs):

            # collect all attributes belonging to that group
            group_attributes = {}
            for attr_name, attr_value in AGENT_ATTRIBUTES.iteritems():
                if attr_value.get('group') == name:
                    group_attributes[attr_name] = attr_value

            for group_attr_name in group_attributes.iterkeys():
                # iterate and try to set all the attributes of the group as
                # defined in the heuristics of @attribute.
                @attribute(group_attr_name)
                def setter(_):
                    pass

                setter(cloudify_agent)

            # when we are done, invoke the group function to
            # apply group logic
            group_function(cloudify_agent, *args, **kwargs)
Example #4
0
        def wrapper(cloudify_agent):

            # if the property was given in the invocation, use it.
            # inputs are first in precedence order
            if _update_agent_property(name,
                                      props=cloudify_agent,
                                      final_props=cloudify_agent):
                return

            if ctx.type == context.NODE_INSTANCE:

                # if the property is inside a runtime property, use it.
                # runtime properties are second in precedence order
                runtime_properties = ctx.instance.runtime_properties.get(
                    'cloudify_agent', {})
                if _update_agent_property(name,
                                          props=runtime_properties,
                                          final_props=cloudify_agent):
                    return

                # if the property is declared on the node, use it
                # node properties are third in precedence order
                node_properties = ctx.node.properties.get(
                    'cloudify_agent', {})
                node_properties.update(ctx.node.properties.get(
                    'agent_config', {}))

                if _update_agent_property(name,
                                          props=node_properties,
                                          final_props=cloudify_agent):
                    return

            # if the property is inside the bootstrap context,
            # and its value is not None, use it
            # bootstrap_context is forth in precedence order
            attr = AGENT_ATTRIBUTES.get(name)
            if attr is None:
                raise RuntimeError('{0} is not an agent attribute'
                                   .format(name))
            agent_context = ctx.bootstrap_context.cloudify_agent.\
                _cloudify_agent or {}
            context_attribute = attr.get('context_attribute', name)
            if _update_agent_property(context_attribute,
                                      props=agent_context,
                                      final_props=cloudify_agent,
                                      final_key=name):
                return
            if _update_agent_property(name,
                                      props=agent_context,
                                      final_props=cloudify_agent):
                return

            # apply the function itself
            ctx.logger.debug('Applying function:{0} on Attribute '
                             '<{1}>'.format(function.__name__, name))
            value = function(cloudify_agent)
            if value is not None:
                ctx.logger.debug('{0} set by function:{1}'
                                 .format(name, value))
                cloudify_agent[name] = value
                return

            # set default value
            default = attr.get('default')
            if default is not None:
                ctx.logger.debug('{0} set by default value'
                                 .format(name, value))
                cloudify_agent[name] = default
                return
Example #5
0
        def wrapper(cloudify_agent):

            # if the property was given in the invocation, use it.
            # inputs are first in precedence order
            if _update_agent_property(name,
                                      props=cloudify_agent,
                                      final_props=cloudify_agent):
                return

            if ctx.type == context.NODE_INSTANCE:

                # if the property is inside a runtime property, use it.
                # runtime properties are second in precedence order
                runtime_properties = ctx.instance.runtime_properties.get(
                    'cloudify_agent', {})
                if _update_agent_property(name,
                                          props=runtime_properties,
                                          final_props=cloudify_agent):
                    return

                # if the property is declared on the node, use it
                # node properties are third in precedence order
                node_properties = ctx.node.properties.get('cloudify_agent', {})
                node_properties.update(
                    ctx.node.properties.get('agent_config', {}))

                if _update_agent_property(name,
                                          props=node_properties,
                                          final_props=cloudify_agent):
                    return

            # if the property is inside the bootstrap context,
            # and its value is not None, use it
            # bootstrap_context is forth in precedence order
            attr = AGENT_ATTRIBUTES.get(name)
            if attr is None:
                raise RuntimeError(
                    '{0} is not an agent attribute'.format(name))
            agent_context = ctx.bootstrap_context.cloudify_agent.\
                _cloudify_agent or {}
            context_attribute = attr.get('context_attribute', name)
            if _update_agent_property(context_attribute,
                                      props=agent_context,
                                      final_props=cloudify_agent,
                                      final_key=name):
                return
            if _update_agent_property(name,
                                      props=agent_context,
                                      final_props=cloudify_agent):
                return

            # apply the function itself
            ctx.logger.debug('Applying function:{0} on Attribute '
                             '<{1}>'.format(function.__name__, name))
            value = function(cloudify_agent)
            if value is not None:
                ctx.logger.debug('{0} set by function:{1}'.format(name, value))
                cloudify_agent[name] = value
                return

            # set default value
            default = attr.get('default')
            if default is not None:
                ctx.logger.debug('{0} set by default value'.format(
                    name, value))
                cloudify_agent[name] = default
                return