The heat.engine.resource
Module¶
-
exception
heat.engine.resource.
NoActionRequired
(res_name=’Unknown’, reason=”)[source]¶ Bases:
exceptions.Exception
Exception raised when a signal is ignored.
Resource subclasses should raise this exception from handle_signal() to suppress recording of an event corresponding to the signal.
-
exception
heat.engine.resource.
PollDelay
(period)[source]¶ Bases:
exceptions.Exception
Exception to delay polling of the resource.
This exception may be raised by a Resource subclass’s check_*_complete() methods to indicate that it need not be polled again immediately. If this exception is raised, the check_*_complete() method will not be called again until the nth time that the resource becomes eligible for polling. A PollDelay period of 1 is equivalent to returning False.
-
class
heat.engine.resource.
Resource
(name, definition, stack)[source]¶ Bases:
heat.engine.status.ResourceStatus
-
BASE_ATTRIBUTES
= (‘show’,)¶
-
FnGetAtt
(key, *path)[source]¶ For the intrinsic function Fn::GetAtt.
Parameters: - key – the attribute key.
- path – a list of path components to select from the attribute.
Returns: the attribute value.
-
FnGetAtts
()[source]¶ For the intrinsic function get_attr which returns all attributes.
Returns: dict of all resource’s attributes exclude “show” attribute.
-
LOCK_ACQUIRE
= 1¶
-
LOCK_ACTIONS
= (0, 1, -1)¶
-
LOCK_NONE
= 0¶
-
LOCK_RELEASE
= -1¶
-
SHOW
= ‘show’¶
-
action_handler_task
(action, args=None, action_prefix=None)[source]¶ A task to call the Resource subclass’s handler methods for action.
Calls the handle_<ACTION>() method for the given action and then calls the check_<ACTION>_complete() method with the result in a loop until it returns True. If the methods are not provided, the call is omitted.
Any args provided are passed to the handler.
If a prefix is supplied, the handler method handle_<PREFIX>_<ACTION>() is called instead.
-
add_dependencies
(deps)[source]¶ Add implicit dependencies specific to the resource type.
Some resource types may have implicit dependencies on other resources in the same stack that are not linked by a property value (that would be set using get_resource or get_attr for example, thus creating an explicit dependency). Such dependencies are opaque to the user and should be avoided wherever possible, however in some circumstances they are required due to magic in the underlying API.
The deps parameter is a Dependencies object to which dependency pairs may be added.
-
add_explicit_dependencies
(deps)[source]¶ Add all dependencies explicitly specified in the template.
The deps parameter is a Dependencies object to which dependency pairs are added.
-
adopt
(resource_data)[source]¶ Adopt the existing resource.
Resource subclasses can provide a handle_adopt() method to customise adopt.
-
attributes_schema
= {}¶
-
base_attributes_schema
= {‘show’: <heat.engine.attributes.Schema object>}¶
-
static
build_template_dict
(res_name, res_type, tmpl_type, params, props, outputs, description)[source]¶
-
check
()[source]¶ Checks that the physical resource is in its expected state.
Gets the current status of the physical resource and updates the database accordingly. If check is not supported by the resource, default action is to fail and revert the resource’s status to its original state with the added message that check was not performed.
-
create
(*args, **kwargs)[source]¶ Create the resource.
Subclasses should provide a handle_create() method to customise creation.
-
create_convergence
(template_id, resource_data, engine_id, timeout, progress_callback=None)[source]¶ Creates the resource by invoking the scheduler TaskRunner.
-
data
()[source]¶ Return the resource data for this resource.
Use methods data_set and data_delete to modify the resource data for this resource.
Returns: a dict representing the resource data for this resource.
-
data_delete
(key)[source]¶ Remove a key from the resource data.
Returns: True if the key existed to delete.
-
default_client_name
= None¶
-
delete
(*args, **kwargs)[source]¶ A task to delete the resource.
Subclasses should provide a handle_delete() method to customise deletion.
-
delete_convergence
(template_id, input_data, engine_id, timeout, progress_callback=None)[source]¶ Destroys the resource if it doesn’t belong to given template.
The given template is suppose to be the current template being provisioned.
Also, since this resource is visited as part of clean-up phase, the needed_by should be updated. If this resource was replaced by more recent resource, then delete this and update the replacement resource’s needed_by and replaces fields.
-
entity
= None¶
-
external_id
¶
-
get_attribute
(key, *path)[source]¶ Default implementation for function get_attr and Fn::GetAtt.
This may be overridden by resource plugins to add extra logic specific to the resource implementation.
-
get_live_resource_data
()[source]¶ Default implementation; can be overridden by resources.
Get resource data and handle it with exceptions.
-
get_live_state
(resource_properties)[source]¶ Default implementation; should be overridden by resources.
Parameters: resource_properties – resource’s object of Properties class. Returns: dict of resource’s real state of properties.
-
get_reference_id
()[source]¶ Default implementation for function get_resource.
This may be overridden by resource plugins to add extra logic specific to the resource implementation.
-
handle_metadata_reset
()[source]¶ Default implementation; should be overridden by resources.
Now we override this method to reset the metadata for scale-policy and scale-group resources, because their metadata might hang in a wrong state (‘scaling_in_progress’ is always True) if engine restarts while scaling.
-
has_interface
(resource_type)[source]¶ Check if resource is mapped to resource_type or is “resource_type”.
Check to see if this resource is either mapped to resource_type or is a “resource_type”.
-
has_nested
()[source]¶ Return True if the resource has an existing nested stack.
For most resource types, this will always return False. StackResource subclasses return True when appropriate. Resource subclasses that may return True must also provide a nested_identifier() method to return the identifier of the nested stack, and a nested() method to return a Stack object for the nested stack.
-
metadata_set
(*args, **kw)[source]¶ Write new metadata to the database.
The caller may optionally provide a merge_metadata() function, which takes two arguments - the metadata passed to metadata_set() and the current metadata of the resource - and returns the merged metadata to write. If merge_metadata is not provided, the metadata passed to metadata_set() is written verbatim, overwriting any existing metadata.
If a race condition is detected, the write will be retried with the new result of merge_metadata() (if it is supplied) or the verbatim data (if it is not).
-
metadata_update
(new_metadata=None)[source]¶ No-op for resources which don’t explicitly override this method.
-
needs_replace_with_prop_diff
(changed_properties_set, after_props, before_props)[source]¶ Needs replace based on prop_diff.
-
no_signal_actions
= (‘SUSPEND’, ‘DELETE’)¶
-
parse_live_resource_data
(resource_properties, resource_data)[source]¶ Default implementation; can be overridden by resources.
Parse resource data for using it in updating properties with live state. :param resource_properties: properties of stored resource plugin. :param resource_data: data from current live state of a resource.
-
physical_resource_name_limit
= 255¶
-
prepare_for_replace
()[source]¶ Prepare resource for replacing.
Some resources requires additional actions before replace them. If resource need to be changed before replacing, this method should be implemented in resource class.
-
preview
()[source]¶ Default implementation of Resource.preview.
This method should be overridden by child classes for specific behavior.
-
preview_update
(after, before, after_props, before_props, prev_resource, check_init_complete=False)[source]¶ Simulates update without actually updating the resource.
Raises UpdateReplace, if replacement is required or returns True, if in-place update is required.
-
static
reduce_physical_resource_name
(name, limit)[source]¶ Reduce length of physical resource name to a limit.
The reduced name will consist of the following:
- the first 2 characters of the name
- a hyphen
- the end of the name, truncated on the left to bring the name length within the limit
Parameters: - name – The name to reduce the length of
- limit – The max length limit
Returns: A name whose length is less than or equal to the limit
-
referenced_attrs
(in_resources=True, in_outputs=True)[source]¶ Return the set of all attributes referenced in the template.
This enables the resource to calculate which of its attributes will be used. By default, attributes referenced in either other resources or outputs will be included. Either can be excluded by setting the in_resources or in_outputs parameters to False.
-
regenerate_info_schema
(definition)[source]¶ Default implementation; should be overridden by resources.
Should be overridden by resources that would require schema refresh during update, ex. TemplateResource.
Definition: Resource Definition
-
reparse
(client_resolve=True)[source]¶ Reparse the resource properties.
Optional translate flag for property translation and client_resolve flag for resolving properties by doing client lookup.
-
required_by
()[source]¶ List of resources that require this one as a dependency.
Returns a list of names of resources that depend on this resource directly.
-
required_service_extension
= None¶
-
requires_deferred_auth
= False¶
-
classmethod
resource_to_template
(resource_type, template_type=’cfn’)[source]¶ Generate a provider template that mirrors the resource.
Parameters: - resource_type – The resource type to be displayed in the template
- template_type – the template type to generate, cfn or hot.
Returns: A template where the resource’s properties_schema is mapped as parameters, and the resource’s attributes_schema is mapped as outputs
-
restore_prev_rsrc
(convergence=False)[source]¶ Restore resource after rollback.
Some resources requires additional actions after rollback. If resource need to be changed during rollback, this method should be implemented in resource class.
-
resume
()[source]¶ Return a task to resume the resource.
Subclasses should provide a handle_resume() method to implement resume.
-
signal
(details=None, need_check=True)[source]¶ Signal the resource.
Returns True if the metadata for all resources in the stack needs to be regenerated as a result of the signal, False if it should not be.
Subclasses should provide a handle_signal() method to implement the signal. The base-class raise an exception if no handler is implemented.
-
signal_needs_metadata_updates
= True¶
-
stack
¶
-
state
¶ Returns state, tuple of action, status.
-
store
(set_metadata=False, lock=0)[source]¶ Create the resource in the database.
If self.id is set, we update the existing stack.
-
strict_dependency
= True¶
-
support_status
= <heat.engine.support.SupportStatus object>¶
-
suspend
()[source]¶ Return a task to suspend the resource.
Subclasses should provide a handle_suspend() method to implement suspend.
-
translate_properties
(properties, client_resolve=True)[source]¶ Set resource specific rules for properties translation.
The properties parameter is a properties object and the optional client_resolve flag is to specify whether to do ‘RESOLVE’ translation with client lookup.
-
update
(*args, **kwargs)[source]¶ Return a task to update the resource.
Subclasses should provide a handle_update() method to customise update, the base-class handle_update will fail by default.
-
update_allowed_properties
= ()¶
-
update_convergence
(template_id, resource_data, engine_id, timeout, new_stack, progress_callback=None)[source]¶ Update the resource synchronously.
Persist the resource’s current_template_id to template_id and resource’s requires to list of the required resource ids from the given resource_data and existing resource’s requires, then updates the resource by invoking the scheduler TaskRunner.
-
update_policy_schema
= {}¶
-
update_template_diff
(after, before)[source]¶ Returns the difference between the before and after json snippets.
If something has been removed in after which exists in before we set it to None.
-
update_template_diff_properties
(after_props, before_props)[source]¶ Return changed Properties between the before and after properties.
If any property having immutable as True is updated, raises NotSupported error. If any properties have changed which are not in update_allowed_properties, raises UpdateReplace.
-