@@ -13,6 +13,11 @@ created
1313from ansible.module_utils.network.common.cfg.base import ConfigBase
1414from ansible.module_utils.network.common.utils import to_list
1515from {{ import_path }}.{{ network_os }}.facts.facts import Facts
16+ {% if transport .netconf %}
17+ from ansible.module_utils.network.netconf.netconf import locked_config
18+ from ansible.module_utils.network.common.netconf import (build_root_xml_node,
19+ build_child_xml_node)
20+ {% endif %}
1621
1722
1823class {{ resource|capitalize }}(ConfigBase):
@@ -51,8 +56,29 @@ class {{ resource|capitalize }}(ConfigBase):
5156 :returns: The result from module execution
5257 """
5358 result = {'changed': False}
54- commands = list()
59+ {% if transport .netconf %}
60+ existing_{{ resource }}_facts = self.get_{{ resource }}_facts()
61+ config_xmls = self.set_config(existing_{{ resource }}_facts)
62+
63+ with locked_config(self._module):
64+ for config_xml in to_list(config_xmls):
65+ diff = self._module._connectionload_config(self._module, config_xml, [])
66+
67+ commit = not self._module.check_mode
68+ if diff:
69+ if commit:
70+ self._module._connection.commit_configuration(self._module)
71+ else:
72+ self._module._connection.discard_changes(self._module)
73+ result['changed'] = True
74+
75+ if self._module._diff:
76+ result['diff'] = {'prepared': diff}
77+
78+ result['xml'] = config_xmls
79+ {% else %}
5580 warnings = list()
81+ commands = list()
5682
5783 existing_{{ resource }}_facts = self.get_{{ resource }}_facts()
5884 commands.extend(self.set_config(existing_{{ resource }}_facts))
@@ -62,6 +88,7 @@ class {{ resource|capitalize }}(ConfigBase):
6288 result['changed'] = True
6389 result['commands'] = commands
6490
91+ {% endif %}
6592 changed_{{ resource }}_facts = self.get_{{ resource }}_facts()
6693
6794 result['before'] = existing_{{ resource }}_facts
@@ -93,6 +120,23 @@ class {{ resource|capitalize }}(ConfigBase):
93120 :returns: the commands necessary to migrate the current configuration
94121 to the desired configuration
95122 """
123+ {% if transport .netconf %}
124+ root = build_root_xml_node('{{ resource }}')
125+ state = self._module.params['state']
126+ if state == 'overridden':
127+ config_xmls = self._state_overridden(want, have)
128+ elif state == 'deleted':
129+ config_xmls = self._state_deleted(want, have)
130+ elif state == 'merged':
131+ config_xmls = self._state_merged(want, have)
132+ elif state == 'replaced':
133+ config_xmls = self._state_replaced(want, have)
134+
135+ for xml in config_xmls:
136+ root.append(xml)
137+
138+ return self._module._connection.tostring(root)
139+ {% else %}
96140 state = self._module.params['state']
97141 if state == 'overridden':
98142 kwargs = {}
@@ -107,7 +151,47 @@ class {{ resource|capitalize }}(ConfigBase):
107151 kwargs = {}
108152 commands = self._state_replaced(**kwargs)
109153 return commands
154+ {% endif %}
155+ {% if transport .netconf %}
156+ def _state_replaced(self, want, have):
157+ """ The command generator when state is replaced
110158
159+ :rtype: A list
160+ :returns: the xml necessary to migrate the current configuration
161+ to the desired configuration
162+ """
163+ intf_xml = []
164+ return intf_xml
165+
166+ def _state_overridden(self, want, have):
167+ """ The command generator when state is overridden
168+
169+ :rtype: A list
170+ :returns: the xml necessary to migrate the current configuration
171+ to the desired configuration
172+ """
173+ intf_xml = []
174+ return intf_xml
175+ def _state_deleted(self, want, have):
176+ """ The command generator when state is deleted
177+
178+ :rtype: A list
179+ :returns: the xml necessary to migrate the current configuration
180+ to the desired configuration
181+ """
182+ intf_xml = []
183+ return intf_xml
184+
185+ def _state_merged(self, want, have):
186+ """ The command generator when state is merged
187+
188+ :rtype: A list
189+ :returns: the xml necessary to migrate the current configuration
190+ to the desired configuration
191+ """
192+ intf_xml = []
193+ return intf_xml
194+ {% else %}
111195 @staticmethod
112196 def _state_replaced(**kwargs):
113197 """ The command generator when state is replaced
@@ -151,3 +235,4 @@ class {{ resource|capitalize }}(ConfigBase):
151235 """
152236 commands = []
153237 return commands
238+ {% endif %}
0 commit comments