It should be possible to generate the code for def _state_merged method
Two additional pieces of information are required in order to accomplish the codegen
- singular entity name
- key name
Proposal:
Add RESOURCE_KEY_NAMEand RESOURCE_SINGULAR to template:
---
NETWORK_OS: myos
RESOURCE: interfaces
RESOURCE_SINGULAR: interface
RESOURCE_KEY_NAME: name
COPYRIGHT: Copyright 2019 Red Hat
LICENSE: gpl-3.0.txt
This would allow the template to be:
def _state_merged(self, want, have):
""" The command generator when state is merged
:rtype: A list
:returns: the xml necessary to migrate the current configuration
to the desired configuration
"""
{{ resource }}_xml = []
for child in want:
{{ resource }} = build_root_xml_node("{{ resource }}")
{{ resource_singular }}= build_child_xml_node({{ resource }}, "{{ resource_singular }}")
build_child_xml_node(
{{ resource_singular }}, "{{ resource_key_name }}", child["{{ resource_key_name }}"]
)
return {{ resource }}_xml
Additional codegen could be implemented based on the schema of the resource.
It should be possible to generate the code for
def _state_mergedmethodTwo additional pieces of information are required in order to accomplish the codegen
Proposal:
Add RESOURCE_KEY_NAMEand RESOURCE_SINGULAR to template:
This would allow the template to be:
def _state_merged(self, want, have): """ The command generator when state is merged :rtype: A list :returns: the xml necessary to migrate the current configuration to the desired configuration """ {{ resource }}_xml = [] for child in want: {{ resource }} = build_root_xml_node("{{ resource }}") {{ resource_singular }}= build_child_xml_node({{ resource }}, "{{ resource_singular }}") build_child_xml_node( {{ resource_singular }}, "{{ resource_key_name }}", child["{{ resource_key_name }}"] ) return {{ resource }}_xmlAdditional codegen could be implemented based on the schema of the resource.