octodns.processor.templating¶
- class octodns.processor.templating.Templating(id, *args, trailing_dots=True, context={}, **kwargs)[source]¶
Bases:
BaseProcessorRecord templating using python format. For simple records like TXT and CAA that is the value itself. For multi-field records like MX or SRV it’s the text portions, exchange and target respectively.
Example Processor Config:
- templating:
class: octodns.processor.templating.Templating # When trailing_dots is disabled, trailing dots are removed from all # built-in variables values who represent a FQDN, like {zone_name} # or {record_fqdn}. Optional. Default to True. trailing_dots: False # Any k/v present in context will be passed into the .format method and # thus be available as additional variables in the template. This is all # optional. context:
key: value another: 42
Example Records:
- foo:
type: TXT value: The zone this record lives in is {zone_name}. There are {zone_num_records} record(s).
- bar:
type: MX values:
preference: 1 exchange: mx1.{zone_name}.mail.mx.
preference: 1 exchange: mx2.{zone_name}.mail.mx.
Note that validations for some types reject values with {}. When encountered the best option is to use record level lenient: true https://github.com/octodns/octodns/blob/main/docs/records.md#lenience
Note that if you need to add dynamic context you can create a custom processor that inherits from Templating and passes them into the call to super, e.g.
See https://docs.python.org/3/library/string.html#custom-string-formatting for details on formatting options. Anything possible in an f-string or .format should work here.
- process_source_and_target_zones(desired, existing, provider)[source]¶
Called just prior to computing changes for target between desired and existing. Provides an opportunity for the processor to modify either the desired or existing `Zone`s that will be used to compute the changes and create the initial plan.
Will see desired after any modifications done by Provider._process_desired_zone and all processors via Processor.process_source_zone
Will see existing after any modifications done by all processors via Processor.process_target_zone
Will see both desired and existing after any modifications done by any processors configured to run before this one via Processor.process_source_and_target_zones.
May modify desired directly.
Must return desired which will normally be the desired param.
May modify existing directly.
Must return existing which will normally be the existing param.
Must not modify records directly, record.copy should be called, the results of which can be modified, and then Zone.add_record may be used with replace=True.
May call Zone.remove_record to remove records from desired.
May call Zone.remove_record to remove records from existing.